Skip to content

Commit 29e0c43

Browse files
committed
tests: Add test_cmake/test_wheel
* Waiting a new release of pytest-plugins (including man-group/pytest-plugins#36) is done, we add a dependency to jcfr/pytest-plugins@pytest-shutil-2016-11-08-c50ac56 generated using [1] [1] https://gist.github.com/jcfr/19a360f541b5caae5f31ac31c83e4f65/bae647ba9a0182ff9126a863805a14077f81bd2a
1 parent ec8b07a commit 29e0c43

9 files changed

+102
-1
lines changed

Diff for: .coveragerc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[run]
2+
branch = True
3+
include = cmake/*.py
4+
omit = cmake/_version.py
5+
6+
[xml]
7+
output = tests/coverage.xml

Diff for: cmake/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
if platform.system().lower() == "darwin":
1414
CMAKE_DATA = os.path.join(CMAKE_DATA, 'CMake.app', 'Contents')
1515

16+
# Support running tests from the source tree
17+
if not os.path.exists(CMAKE_DATA):
18+
_cmake_data = os.path.abspath(os.path.join(
19+
os.path.dirname(__file__), '../_skbuild/cmake-install/cmake/data'))
20+
if os.path.exists(_cmake_data):
21+
CMAKE_DATA = _cmake_data
22+
1623
CMAKE_BIN_DIR = os.path.join(CMAKE_DATA, 'bin')
1724
CMAKE_DOC_DIR = os.path.join(CMAKE_DATA, 'doc')
1825
CMAKE_SHARE_DIR = os.path.join(CMAKE_DATA, 'share')

Diff for: requirements-dev.txt

+7
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
codecov==2.0.5
2+
coverage==4.2
13
flake8==3.0.4
4+
pytest==3.0.3
5+
pytest-cov==2.4.0
6+
pytest-runner==2.9
7+
git+https://github.com/jcfr/pytest-plugins@pytest-shutil-2016-11-08-c50ac56#egg=pytest-shutil
8+
pytest-virtualenv==1.2.2
29
scikit-build==0.4.0

Diff for: scikit-ci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ build:
3939
- python setup.py --hide-listing sdist
4040
- $<RUN_ENV> python setup.py --hide-listing bdist_wheel
4141

42+
test:
43+
commands:
44+
- python setup.py test
45+
4246
after_test:
4347
commands:
48+
- codecov -X gcov --required --file ./tests/coverage.xml
4449
- pip install girder-client==2.0.0
4550
- python: |
4651
import girder_client, os, subprocess

Diff for: setup.cfg

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[aliases]
2+
test = pytest
3+
14
[flake8]
25
max-line-length: 80
36
# Whether to display the pep8 instructions on failure (can be quite verbose)
@@ -9,6 +12,10 @@ max-complexity: 14
912
format: pylint
1013
exclude: .git,.idea,.eggs,__pycache__,.tox,_skbuild,src,versioneer.py
1114

15+
[tool:pytest]
16+
testpaths = tests
17+
addopts = -v --cov --cov-report xml
18+
1219
[versioneer]
1320
VCS = git
1421
versionfile_source = cmake/_version.py

Diff for: setup.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22

3+
import sys
34
import versioneer
45

56
from pip.req import parse_requirements
@@ -9,8 +10,16 @@
910
def _parse_requirements(filename):
1011
return [str(ir.req) for ir in parse_requirements(filename, session=False)]
1112

13+
requirements = []
1214
dev_requirements = _parse_requirements('requirements-dev.txt')
1315

16+
# Require pytest-runner only when running tests
17+
pytest_runner = (['pytest-runner>=2.0,<3dev']
18+
if any(arg in sys.argv for arg in ('pytest', 'test'))
19+
else [])
20+
21+
setup_requires = pytest_runner
22+
1423
setup(
1524
name='cmake',
1625

@@ -61,6 +70,7 @@ def _parse_requirements(filename):
6170

6271
keywords='CMake build c++ fortran cross-platform cross-compilation',
6372

64-
install_requires=[],
73+
install_requires=requirements,
6574
tests_require=dev_requirements,
75+
setup_requires=setup_requires
6676
)

Diff for: tests/__init__.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import sys
3+
4+
from contextlib import contextmanager
5+
6+
7+
@contextmanager
8+
def push_argv(argv):
9+
old_argv = sys.argv
10+
sys.argv = argv
11+
yield
12+
sys.argv = old_argv

Diff for: tests/test_cmake.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
import pytest
3+
4+
import cmake
5+
6+
from . import push_argv
7+
8+
9+
def test_cmake_module():
10+
with push_argv(["cmake.py", "--version"]), pytest.raises(SystemExit):
11+
cmake.cmake()
12+
13+
with push_argv(["cpack.py", "--version"]), pytest.raises(SystemExit):
14+
cmake.cpack()
15+
16+
with push_argv(["ctest.py", "--version"]), pytest.raises(SystemExit):
17+
cmake.ctest()

Diff for: tests/test_wheel.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
import os
3+
import textwrap
4+
5+
from path import Path
6+
7+
DIST_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../dist'))
8+
9+
10+
def test_command_line(virtualenv, tmpdir):
11+
assert len(Path(DIST_DIR).files(pattern="*.whl")) == 1
12+
13+
virtualenv.install_package("coverage==4.2")
14+
virtualenv.run("pip install %s/*" % DIST_DIR)
15+
16+
expected_version = "3.6.2"
17+
18+
for executable_name in ["cmake", "cpack", "ctest"]:
19+
output = virtualenv.run(
20+
"%s --version" % executable_name, capture=True).splitlines()[0]
21+
assert output == "%s version %s" % (executable_name, expected_version)
22+
23+
test_script = tmpdir.join("test_cmake.cmake")
24+
test_script.write(textwrap.dedent(r"""
25+
message("${CMAKE_COMMAND}")
26+
"""))
27+
28+
output = virtualenv.run("cmake -P %s" % str(test_script), capture=True)
29+
assert output.startswith(virtualenv.virtualenv)

0 commit comments

Comments
 (0)