Skip to content

Commit 6f327ba

Browse files
committed
BLD: Add coverage for Cython Code
Add line coverage for Cython code
1 parent b262e3c commit 6f327ba

File tree

5 files changed

+56
-23
lines changed

5 files changed

+56
-23
lines changed

.coveragerc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# .coveragerc to control coverage.py
2+
[run]
3+
source = randomstate
4+
branch = True
5+
include = */randomstate/*
6+
omit =
7+
*/_version.py
8+
plugins = Cython.Coverage
9+
10+
[report]
11+
# Regexes for lines to exclude from consideration
12+
exclude_lines =
13+
# Have to re-enable the standard pragma
14+
pragma: no cover
15+
16+
# Don't complain if tests don't hit defensive assertion code:
17+
raise NotImplementedError
18+
except NotImplementedError
19+
except AssertionError
20+
# Ignore pass
21+
pass
22+
include = */randomstate/*
23+
omit =
24+
*/_version.py
25+
ignore_errors = True

.travis.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ matrix:
1717
- env:
1818
- PYTHON=2.7
1919
- NUMPY=1.9
20-
- CYTHON=0.22
20+
- CYTHON=0.25
2121
- env:
2222
- PYTHON=3.4
2323
- NUMPY=1.10
24-
- CYTHON=0.24
24+
- CYTHON=0.25
2525
- env:
2626
- PYTHON=3.5
27+
- CYTHON=0.26
2728
- env:
2829
- PYTHON=3.6
2930

@@ -43,14 +44,15 @@ before_install:
4344
- export BUILD_DIR=$PWD
4445
- conda create -n randomstate-test ${PKGS} pytest pip setuptools matplotlib pyyaml nose --quiet
4546
- source activate randomstate-test
46-
- pip install tempita sphinx guzzle_sphinx_theme ipython -q
47+
- pip install tempita sphinx guzzle_sphinx_theme ipython coverage coveralls pytest-cov codecov -q
48+
- export CYTHON_COVERAGE=1
4749

4850
install:
4951
- python setup.py develop
5052

5153
script:
5254
- set -e
53-
- pytest randomstate
55+
- pytest --cov-config .coveragerc --cov=randomstate randomstate --cov-report xml --cov-report term
5456
- |
5557
if [ ${PYTHON} = 3.5 ]; then
5658
conda install -c conda-forge doctr
@@ -67,3 +69,6 @@ script:
6769
cd ${BUILD_DIR}/randomstate
6870
python performance.py;
6971
fi
72+
73+
after_success:
74+
codecov

randomstate/.coveragerc

Lines changed: 0 additions & 2 deletions
This file was deleted.

randomstate/tests/test_numpy_mt19937.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,22 +1712,22 @@ def test_two_arg_funcs(self):
17121712
out = func(self.argOne, argTwo[0])
17131713
assert_equal(out.shape, self.tgtShape)
17141714

1715-
def test_randint(self):
1716-
itype = [np.bool, np.int8, np.uint8, np.int16, np.uint16,
1717-
np.int32, np.uint32, np.int64, np.uint64]
1718-
func = mt19937.randint
1719-
high = np.array([1])
1720-
low = np.array([0])
1721-
1722-
for dt in itype:
1723-
out = func(low, high, dtype=dt)
1724-
assert_equal(out.shape, self.tgtShape)
1725-
1726-
out = func(low[0], high, dtype=dt)
1727-
assert_equal(out.shape, self.tgtShape)
1728-
1729-
out = func(low, high[0], dtype=dt)
1730-
assert_equal(out.shape, self.tgtShape)
1715+
def test_randint(self):
1716+
itype = [np.bool, np.int8, np.uint8, np.int16, np.uint16,
1717+
np.int32, np.uint32, np.int64, np.uint64]
1718+
func = mt19937.randint
1719+
high = np.array([1])
1720+
low = np.array([0])
1721+
1722+
for dt in itype:
1723+
out = func(low, high, dtype=dt)
1724+
assert_equal(out.shape, self.tgtShape)
1725+
1726+
out = func(low[0], high, dtype=dt)
1727+
assert_equal(out.shape, self.tgtShape)
1728+
1729+
out = func(low, high[0], dtype=dt)
1730+
assert_equal(out.shape, self.tgtShape)
17311731

17321732
def test_three_arg_funcs(self):
17331733
funcs = [mt19937.noncentral_f, mt19937.triangular,

setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import versioneer
1515

1616
DEVELOP = False
17+
CYTHON_COVERAGE = bool(os.environ.get('CYTHON_COVERAGE', False))
1718

1819
try:
1920
import Cython.Tempita as tempita
@@ -37,6 +38,8 @@
3738
compile_rngs = rngs[:]
3839

3940
extra_defs = [('_CRT_SECURE_NO_WARNINGS', '1')] if os.name == 'nt' else []
41+
extra_defs += [('CYTHON_TRACE_NOGIL','1')] if CYTHON_COVERAGE else []
42+
4043
extra_link_args = ['/LTCG', '/OPT:REF', 'Advapi32.lib', 'Kernel32.lib'] if os.name == 'nt' else []
4144
# TODO: The unddefine is to handle a problem when building
4245
# TODO: manylinux1 on CentOS 5/GCC 4.8.2
@@ -242,7 +245,9 @@ def cythonize(e, *args, **kwargs):
242245
with open(output_file_name, 'w') as output_file:
243246
output_file.write(template.substitute())
244247

245-
ext_modules = cythonize(extensions, force=not DEVELOP, annotate=True)
248+
directives = {'linetrace': CYTHON_COVERAGE}
249+
ext_modules = cythonize(extensions, force=not DEVELOP, annotate=True,
250+
compiler_directives=directives)
246251

247252
classifiers = ['Development Status :: 5 - Production/Stable',
248253
'Environment :: Console',

0 commit comments

Comments
 (0)