Skip to content

Commit faea9dc

Browse files
authored
Merge pull request #67 from pycompression/fixasan
Fix test environment
2 parents a8e91fb + 402d8c9 commit faea9dc

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ version develop
1717
are flushed using Z_SYNC_FLUSH.
1818
+ Switched to setuptools-scm for building the package rather than versioningit.
1919
+ Test files are added to the source distribution.
20+
+ Fix an issue where some tests failed because they ignored PYTHONPATH.
2021

2122
version 0.5.1
2223
-----------------

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ classifiers = [
3030
"Operating System :: Microsoft :: Windows",
3131
]
3232
urls.homepage = "https://github.com/pycompression/python-zlib-ng"
33-
urls.documentation = "python-zlib-ng.readthedocs.io"
33+
urls.documentation = "https://python-zlib-ng.readthedocs.io"
3434

3535
[tool.setuptools_scm]
3636
version_file = "src/zlib_ng/_version.py"

tests/test_gzip_compliance.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,19 @@ def test_decompress_stdin_stdout(self):
804804
self.assertEqual(err, b'')
805805
self.assertEqual(out, self.data)
806806

807+
# The following tests use assert_python_failure or assert_python_ok.
808+
#
809+
# If the env_vars argument to assert_python_failure or assert_python_ok
810+
# is empty the test will run in isolated mode (-I) which means that the
811+
# PYTHONPATH environment variable will be ignored and the test fails
812+
# because the isal module can not be found, or the test is run usung the
813+
# system installed version of the module instead of the newly built
814+
# module that should be tested.
815+
#
816+
# By adding a dummy entry to the env_vars argument the isolated mode is
817+
# not used and the PYTHONPATH environment variable is not ignored and
818+
# the test works as expected.
819+
807820
@create_and_remove_directory(TEMPDIR)
808821
def test_decompress_infile_outfile(self):
809822
gzipname = os.path.join(TEMPDIR, 'testgzip.gz')
@@ -812,7 +825,7 @@ def test_decompress_infile_outfile(self):
812825
with gzip.open(gzipname, mode='wb') as fp:
813826
fp.write(self.data)
814827
rc, out, err = assert_python_ok('-m', 'zlib_ng.gzip_ng', '-d',
815-
gzipname)
828+
gzipname, **{'_dummy': '1'})
816829

817830
with open(os.path.join(TEMPDIR, "testgzip"), "rb") as gunziped:
818831
self.assertEqual(gunziped.read(), self.data)
@@ -824,7 +837,7 @@ def test_decompress_infile_outfile(self):
824837

825838
def test_decompress_infile_outfile_error(self):
826839
rc, out, err = assert_python_failure('-m', 'zlib_ng.gzip_ng', '-d',
827-
'thisisatest.out')
840+
'thisisatest.out', **{'_dummy': '1'})
828841
self.assertIn(b"filename doesn't end in .gz: 'thisisatest.out'",
829842
err.strip())
830843
self.assertEqual(rc, 1)
@@ -849,7 +862,7 @@ def test_compress_infile_outfile_default(self):
849862
fp.write(self.data)
850863

851864
rc, out, err = assert_python_ok('-m', 'zlib_ng.gzip_ng',
852-
local_testgzip)
865+
local_testgzip, **{'_dummy': '1'})
853866

854867
self.assertTrue(os.path.exists(gzipname))
855868
self.assertEqual(out, b'')
@@ -867,7 +880,8 @@ def test_compress_infile_outfile(self):
867880
fp.write(self.data)
868881

869882
rc, out, err = assert_python_ok('-m', 'zlib_ng.gzip_ng',
870-
compress_level, local_testgzip)
883+
compress_level, local_testgzip,
884+
**{'_dummy': '1'})
871885

872886
self.assertTrue(os.path.exists(gzipname))
873887
self.assertEqual(out, b'')
@@ -877,15 +891,15 @@ def test_compress_infile_outfile(self):
877891

878892
def test_compress_fast_best_are_exclusive(self):
879893
rc, out, err = assert_python_failure('-m', 'zlib_ng.gzip_ng', '--fast',
880-
'--best')
894+
'--best', **{'_dummy': '1'})
881895
self.assertIn(
882896
b"error: argument -9/--best: not allowed with argument -1/--fast",
883897
err)
884898
self.assertEqual(out, b'')
885899

886900
def test_decompress_cannot_have_flags_compression(self):
887901
rc, out, err = assert_python_failure('-m', 'zlib_ng.gzip_ng', '--fast',
888-
'-d')
902+
'-d', **{'_dummy': '1'})
889903
self.assertIn(
890904
b'error: argument -d/--decompress: not allowed with argument -1/--fast',
891905
err)

tox.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ commands =
2323
[testenv:asan]
2424
setenv=
2525
PYTHONDEVMODE=1
26+
PYTHONUNBUFFERED=1
2627
PYTHONMALLOC=malloc
27-
CFLAGS=-lasan -fsanitize=address -fno-omit-frame-pointer
28+
CFLAGS=-lasan -fsanitize=address -fno-omit-frame-pointer -Og -g
29+
ASAN_OPTIONS=log_path=asan_errors
2830
allowlist_externals=bash
2931
commands=
3032
bash -c 'export LD_PRELOAD=$(gcc -print-file-name=libasan.so) && printenv LD_PRELOAD && python -c "from zlib_ng import zlib_ng" && pytest tests'

0 commit comments

Comments
 (0)