From ae3a039d95bce8aa78d9568a8924c9b08519ff70 Mon Sep 17 00:00:00 2001 From: Kelsey Hawley Date: Fri, 17 Jan 2014 12:13:39 -0800 Subject: [PATCH 1/3] updated setup.py to use pytest (for compatilibity with dump-anydbm tests) --- setup.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index dabce13..c657ec9 100755 --- a/setup.py +++ b/setup.py @@ -1,8 +1,23 @@ #!/usr/bin/env python # vim: set sw=4 et: +from setuptools.command.test import test as TestCommand +import sys import setuptools +# special class needs to be added to support the pytest written dump-anydbm tests +class PyTest(TestCommand): + def finalize_options(self): + TestCommand.finalize_options(self) + self.test_args = [] + self.test_suite = True + def run_tests(self): + #import here, cause outside the eggs aren't loaded + import pytest + errno = pytest.main(self.test_args) + sys.exit(errno) + + setuptools.setup(name='warcprox', version='1.1', description='WARC writing MITM HTTP/S proxy', @@ -14,7 +29,8 @@ setuptools.setup(name='warcprox', packages=['warcprox'], install_requires=['pyopenssl', 'warctools>=4.8.3'], # gdbm not in pip :( dependency_links=['git+https://github.com/internetarchive/warctools.git#egg=warctools-4.8.3'], - tests_require=['requests>=2.0.1'], # >=2.0.1 for https://github.com/kennethreitz/requests/pull/1636 + tests_require=['requests>=2.0.1', 'pytest'], # >=2.0.1 for https://github.com/kennethreitz/requests/pull/1636 + cmdclass = {'test': PyTest}, test_suite='warcprox.tests', scripts=['bin/dump-anydbm', 'bin/warcprox'], zip_safe=False, From a87a5dd972fc50e23c5e76d1a05082d7e13c1cae Mon Sep 17 00:00:00 2001 From: Kelsey Hawley Date: Fri, 17 Jan 2014 15:35:25 -0800 Subject: [PATCH 2/3] updated test to directly use the specified py version & access the file path to dump-anydbm directly. Also added some more helpful print error statements --- warcprox/tests/test_dump-anydbm.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/warcprox/tests/test_dump-anydbm.py b/warcprox/tests/test_dump-anydbm.py index 1fddefc..43ef6cb 100644 --- a/warcprox/tests/test_dump-anydbm.py +++ b/warcprox/tests/test_dump-anydbm.py @@ -4,6 +4,7 @@ import pytest import os import tempfile import subprocess # to access the script from shell +import sys # will try as python 3 then default to python 2 modules try: @@ -34,8 +35,9 @@ key1 = 'very first key' key2 = 'second key' val1 = 'very first value' val2 = 'second value' -dump_anydbm = "dump-anydbm" +py_version = "python"+str(sys.version_info.major)+"."+str(sys.version_info.minor) +dump_anydbm_loc = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "bin/dump-anydbm") @pytest.fixture(scope="function") def gdbm_test_db(request): @@ -94,8 +96,11 @@ def dumbdbm_test_db(request): def test_dumpanydbm_identify_gdbm(gdbm_test_db): print("running test_dumpanydbm_identify_gdbm") - output = subprocess.check_output([dump_anydbm, gdbm_test_db]) - print(b"script printout: \n" + output) + output = subprocess.check_output([py_version, dump_anydbm_loc, gdbm_test_db]) + print(b"script printout: ") + print(output) + print(b"check_one: ") + print(gdbm_test_db.encode(encoding='UTF-8') + b' is a ' + gdbm_type + b' db\nvery first key:very first value\nsecond key:second value\n') assert (output == gdbm_test_db.encode(encoding='UTF-8') + b' is a ' + gdbm_type + b' db\nvery first key:very first value\nsecond key:second value\n' or output == gdbm_test_db.encode(encoding='UTF-8') + b' is a ' + gdbm_type + b' db\nsecond key:second value\nvery first key:very first value\n') @@ -103,8 +108,11 @@ def test_dumpanydbm_identify_gdbm(gdbm_test_db): def test_dumpanydbm_identify_ndbm(ndbm_test_db): print("running test_dumpanydbm_identify_ndbm") - output = subprocess.check_output([dump_anydbm, ndbm_test_db]) - print(b"script printout: \n" + output) + output = subprocess.check_output([py_version, dump_anydbm_loc, ndbm_test_db]) + print(b"script printout: ") + print(output) + print(b"check_one: ") + print(ndbm_test_db.encode(encoding='UTF-8') + b' is a ' + ndbm_type + b' db\nvery first key:very first value\nsecond key:second value\n') assert (output == ndbm_test_db.encode(encoding='UTF-8') + b' is a ' + ndbm_type + b' db\nvery first key:very first value\nsecond key:second value\n' or output == ndbm_test_db.encode(encoding='UTF-8') + b' is a ' + ndbm_type + b' db\nsecond key:second value\nvery first key:very first value\n') @@ -112,8 +120,12 @@ def test_dumpanydbm_identify_ndbm(ndbm_test_db): def test_dumpanydbm_identify_dumbdbm(dumbdbm_test_db): print("running test_dumpanydbm_identify_dumbdbm") - output = subprocess.check_output([dump_anydbm, dumbdbm_test_db]) - print(b"script printout: \n" + output) + + output = subprocess.check_output([py_version, dump_anydbm_loc, dumbdbm_test_db]) + print(b"script printout: ") + print(output) + print(b"check_one: ") + print(dumbdbm_test_db.encode(encoding='UTF-8') + b' is a ' + dumb_type + b' db\nvery first key:very first value\nsecond key:second value\n') assert (output == dumbdbm_test_db.encode(encoding='UTF-8') + b' is a ' + dumb_type + b' db\nvery first key:very first value\nsecond key:second value\n' or output == dumbdbm_test_db.encode(encoding='UTF-8') + b' is a ' + dumb_type + b' db\nsecond key:second value\nvery first key:very first value\n') From c0fbd61507346a1bde0ba4412d37f1d417bb4768 Mon Sep 17 00:00:00 2001 From: Kelsey Hawley Date: Fri, 17 Jan 2014 16:20:16 -0800 Subject: [PATCH 3/3] changed the way I was retrieving the python version --- warcprox/tests/test_dump-anydbm.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/warcprox/tests/test_dump-anydbm.py b/warcprox/tests/test_dump-anydbm.py index 43ef6cb..7c973a6 100644 --- a/warcprox/tests/test_dump-anydbm.py +++ b/warcprox/tests/test_dump-anydbm.py @@ -36,7 +36,7 @@ key2 = 'second key' val1 = 'very first value' val2 = 'second value' -py_version = "python"+str(sys.version_info.major)+"."+str(sys.version_info.minor) +py = sys.executable dump_anydbm_loc = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "bin/dump-anydbm") @pytest.fixture(scope="function") @@ -96,7 +96,7 @@ def dumbdbm_test_db(request): def test_dumpanydbm_identify_gdbm(gdbm_test_db): print("running test_dumpanydbm_identify_gdbm") - output = subprocess.check_output([py_version, dump_anydbm_loc, gdbm_test_db]) + output = subprocess.check_output([py, dump_anydbm_loc, gdbm_test_db]) print(b"script printout: ") print(output) print(b"check_one: ") @@ -108,7 +108,7 @@ def test_dumpanydbm_identify_gdbm(gdbm_test_db): def test_dumpanydbm_identify_ndbm(ndbm_test_db): print("running test_dumpanydbm_identify_ndbm") - output = subprocess.check_output([py_version, dump_anydbm_loc, ndbm_test_db]) + output = subprocess.check_output([py, dump_anydbm_loc, ndbm_test_db]) print(b"script printout: ") print(output) print(b"check_one: ") @@ -121,7 +121,7 @@ def test_dumpanydbm_identify_ndbm(ndbm_test_db): def test_dumpanydbm_identify_dumbdbm(dumbdbm_test_db): print("running test_dumpanydbm_identify_dumbdbm") - output = subprocess.check_output([py_version, dump_anydbm_loc, dumbdbm_test_db]) + output = subprocess.check_output([py, dump_anydbm_loc, dumbdbm_test_db]) print(b"script printout: ") print(output) print(b"check_one: ")