Skip to content

Commit bf3107e

Browse files
authored
Merge pull request #27 from pycompression/coverage2
Add some coverage improvements
2 parents e3bb928 + ba89105 commit bf3107e

File tree

6 files changed

+44
-23
lines changed

6 files changed

+44
-23
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[build-system]
22
requires = ["setuptools>=51", "cython>=0.29", "wheel"]
33
build-backend = "setuptools.build_meta"
4+
5+
# [tool.coverage.run]
6+
# plugins = ["Cython.Coverage"]

setup.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ def build_extension(self, ext):
6262
ext.extra_objects = [
6363
os.path.join(isa_l_prefix_dir, "lib", "libisal.a")]
6464

65+
if os.getenv("CYTHON_COVERAGE") is not None:
66+
# Import cython here so python setup.py can be used without
67+
# installing cython.
68+
from Cython.Build import cythonize
69+
# Add cython directives and macros for coverage support.
70+
cythonized_exts = cythonize(ext, compiler_directives=dict(
71+
linetrace=True
72+
))
73+
for cython_ext in cythonized_exts:
74+
cython_ext.define_macros = [("CYTHON_TRACE_NOGIL", "1")]
75+
cython_ext._needs_stub = False
76+
super().build_extension(cython_ext)
77+
return
78+
6579
super().build_extension(ext)
6680

6781

src/isal/igzip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,5 @@ def main():
313313
out_file.close()
314314

315315

316-
if __name__ == "__main__":
316+
if __name__ == "__main__": # pragma: no cover
317317
main()

tests/test_gzip_compliance.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import tempfile
2727
import unittest
2828
from subprocess import PIPE, Popen
29-
from test import support
3029
from test.support import _4G, bigmemtest
3130
from test.support.script_helper import assert_python_failure, assert_python_ok
3231

@@ -408,8 +407,12 @@ def test_compresslevel_metadata(self):
408407

409408
for (name, level, expectedXflByte) in cases:
410409
major, minor, _, _, _ = sys.version_info
411-
if major == 3 and minor < 7 or major < 3:
412-
# Specific xfl bytes introduced in 3.7
410+
if not ("compresslevel" in
411+
gzip.GzipFile._write_gzip_header.__code__.co_varnames
412+
and hasattr(gzip, "_COMPRESS_LEVEL_FAST")
413+
and hasattr(gzip, "_COMPRESS_LEVEL_TRADEOFF")):
414+
# Specific xfl bytes introduced in 3.9 and backported to
415+
# earlier versions
413416
expectedXflByte = b'\x02'
414417
with self.subTest(name):
415418
fWrite = igzip.IGzipFile(self.filename, 'w',
@@ -804,15 +807,13 @@ def test_decompress_infile_outfile(self):
804807

805808
with igzip.open(igzipname, mode='wb') as fp:
806809
fp.write(self.data)
807-
rc, out, err = assert_python_ok('-m', 'isal.igzip', '-d', igzipname)
810+
sys.argv = ['', '-d', igzipname]
811+
igzip.main()
808812

809813
with open(os.path.join(TEMPDIR, "testigzip"), "rb") as gunziped:
810814
self.assertEqual(gunziped.read(), self.data)
811815

812816
self.assertTrue(os.path.exists(igzipname))
813-
self.assertEqual(rc, 0)
814-
self.assertEqual(out, b'')
815-
self.assertEqual(err, b'')
816817

817818
def test_decompress_infile_outfile_error(self):
818819
rc, out, err = assert_python_ok('-m', 'isal.igzip', '-d',
@@ -882,11 +883,3 @@ def test_decompress_cannot_have_flags_compression(self):
882883
b'-0/--fast',
883884
err)
884885
self.assertEqual(out, b'')
885-
886-
887-
def test_main(verbose=None):
888-
support.run_unittest(TestGzip, TestOpen, TestCommandLine)
889-
890-
891-
if __name__ == "__main__":
892-
test_main(verbose=True)

tests/test_zlib_compliance.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,3 @@ def choose_lines(source, number, seed=None, generator=random):
945945
class CustomInt:
946946
def __index__(self):
947947
return 100
948-
949-
950-
if __name__ == "__main__":
951-
unittest.main()

tox.ini

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,28 @@
33
# python3 interpreter of the user.
44
envlist=py3
55
[testenv]
6-
deps=coverage
6+
deps=pytest
7+
coverage
8+
passenv=
9+
PYTHON_ISAL_LINK_DYNAMIC
10+
commands =
11+
# Create HTML coverage report for humans and xml coverage report for external services.
12+
coverage run --source={envsitepackagesdir}/isal -m py.test tests
13+
coverage html
14+
coverage xml
15+
16+
[testenv:coverage]
17+
# Separate test environment for cython coverage.
18+
deps=coverage[toml]
19+
cython
720
pytest
821
passenv=
922
PYTHON_ISAL_LINK_DYNAMIC
23+
setenv=
24+
CYTHON_COVERAGE=true
1025
commands =
1126
# Create HTML coverage report for humans and xml coverage report for external services.
12-
coverage run --source={envsitepackagesdir}/isal -m py.test -v tests
27+
coverage run --source={envsitepackagesdir}/isal -m py.test tests
1328
coverage html
1429
coverage xml
1530

@@ -21,7 +36,7 @@ commands=
2136
[testenv:compatibility]
2237
deps=pytest
2338
commands=
24-
pytest -v tests/test_isal.py
39+
pytest tests/test_isal.py
2540

2641
[testenv:lint]
2742
deps=flake8

0 commit comments

Comments
 (0)