From e3430cec7ce072322b16c2ca97c5ea506f14df31 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Sun, 31 Aug 2014 17:40:54 -0700 Subject: [PATCH] Overhaul test suite to allow testing in place. --- Makefile | 5 +++++ dns/dnssec.py | 2 ++ tests/Makefile | 5 +---- tests/{bugs.py => test_bugs.py} | 0 tests/{dnssec.py => test_dnssec.py} | 14 ++++++++++++++ tests/{flags.py => test_flags.py} | 0 tests/{generate.py => test_generate.py} | 0 tests/{message.py => test_message.py} | 0 tests/{name.py => test_name.py} | 0 tests/{namedict.py => test_namedict.py} | 0 tests/{ntoaaton.py => test_ntoaaton.py} | 0 .../{rdtypeandclass.py => test_rdtypeandclass.py} | 0 tests/{resolver.py => test_resolver.py} | 0 tests/{rrset.py => test_rrset.py} | 0 tests/{set.py => test_set.py} | 0 tests/{tokenizer.py => test_tokenizer.py} | 0 tests/{update.py => test_update.py} | 0 tests/{zone.py => test_zone.py} | 0 tests/utest.py | 8 ++++++++ 19 files changed, 30 insertions(+), 4 deletions(-) rename tests/{bugs.py => test_bugs.py} (100%) rename tests/{dnssec.py => test_dnssec.py} (93%) rename tests/{flags.py => test_flags.py} (100%) rename tests/{generate.py => test_generate.py} (100%) rename tests/{message.py => test_message.py} (100%) rename tests/{name.py => test_name.py} (100%) rename tests/{namedict.py => test_namedict.py} (100%) rename tests/{ntoaaton.py => test_ntoaaton.py} (100%) rename tests/{rdtypeandclass.py => test_rdtypeandclass.py} (100%) rename tests/{resolver.py => test_resolver.py} (100%) rename tests/{rrset.py => test_rrset.py} (100%) rename tests/{set.py => test_set.py} (100%) rename tests/{tokenizer.py => test_tokenizer.py} (100%) rename tests/{update.py => test_update.py} (100%) rename tests/{zone.py => test_zone.py} (100%) create mode 100644 tests/utest.py diff --git a/Makefile b/Makefile index 74469a32..882f6e65 100644 --- a/Makefile +++ b/Makefile @@ -54,3 +54,8 @@ kits: tags: find . -name '*.py' -print | etags - + +check: test + +test: + cd tests; make test diff --git a/dns/dnssec.py b/dns/dnssec.py index c1cd1cb7..2dd4a677 100644 --- a/dns/dnssec.py +++ b/dns/dnssec.py @@ -370,6 +370,8 @@ try: import Crypto.Util.number validate = _validate validate_rrsig = _validate_rrsig + _have_pycrypto = True except ImportError: validate = _need_pycrypto validate_rrsig = _need_pycrypto + _have_pycrypto = False diff --git a/tests/Makefile b/tests/Makefile index cd6e4fa1..8c465dff 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -20,7 +20,4 @@ PYTHON=python3 check: test test: - @for i in *.py; do \ - echo "Running $$i:"; \ - ${PYTHON} $$i || exit 1; \ - done + ${PYTHON} ./utest.py diff --git a/tests/bugs.py b/tests/test_bugs.py similarity index 100% rename from tests/bugs.py rename to tests/test_bugs.py diff --git a/tests/dnssec.py b/tests/test_dnssec.py similarity index 93% rename from tests/dnssec.py rename to tests/test_dnssec.py index f5fd54a2..98c47888 100644 --- a/tests/dnssec.py +++ b/tests/test_dnssec.py @@ -99,22 +99,32 @@ example_ds_sha256 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.DS, class DNSSECValidatorTestCase(unittest.TestCase): + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") def testAbsoluteRSAGood(self): dns.dnssec.validate(abs_soa, abs_soa_rrsig, abs_keys, None, when) + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") def testDuplicateKeytag(self): dns.dnssec.validate(abs_soa, abs_soa_rrsig, abs_keys_duplicate_keytag, None, when) + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") def testAbsoluteRSABad(self): def bad(): dns.dnssec.validate(abs_other_soa, abs_soa_rrsig, abs_keys, None, when) self.assertRaises(dns.dnssec.ValidationFailure, bad) + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") def testRelativeRSAGood(self): dns.dnssec.validate(rel_soa, rel_soa_rrsig, rel_keys, abs_dnspython_org, when) + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") def testRelativeRSABad(self): def bad(): dns.dnssec.validate(rel_other_soa, rel_soa_rrsig, rel_keys, @@ -125,10 +135,14 @@ class DNSSECValidatorTestCase(unittest.TestCase): ds = dns.dnssec.make_ds(abs_dnspython_org, sep_key, 'SHA256') self.assertTrue(ds == good_ds) + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") def testAbsoluteDSAGood(self): dns.dnssec.validate(abs_dsa_soa, abs_dsa_soa_rrsig, abs_dsa_keys, None, when2) + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") def testAbsoluteDSABad(self): def bad(): dns.dnssec.validate(abs_other_dsa_soa, abs_dsa_soa_rrsig, diff --git a/tests/flags.py b/tests/test_flags.py similarity index 100% rename from tests/flags.py rename to tests/test_flags.py diff --git a/tests/generate.py b/tests/test_generate.py similarity index 100% rename from tests/generate.py rename to tests/test_generate.py diff --git a/tests/message.py b/tests/test_message.py similarity index 100% rename from tests/message.py rename to tests/test_message.py diff --git a/tests/name.py b/tests/test_name.py similarity index 100% rename from tests/name.py rename to tests/test_name.py diff --git a/tests/namedict.py b/tests/test_namedict.py similarity index 100% rename from tests/namedict.py rename to tests/test_namedict.py diff --git a/tests/ntoaaton.py b/tests/test_ntoaaton.py similarity index 100% rename from tests/ntoaaton.py rename to tests/test_ntoaaton.py diff --git a/tests/rdtypeandclass.py b/tests/test_rdtypeandclass.py similarity index 100% rename from tests/rdtypeandclass.py rename to tests/test_rdtypeandclass.py diff --git a/tests/resolver.py b/tests/test_resolver.py similarity index 100% rename from tests/resolver.py rename to tests/test_resolver.py diff --git a/tests/rrset.py b/tests/test_rrset.py similarity index 100% rename from tests/rrset.py rename to tests/test_rrset.py diff --git a/tests/set.py b/tests/test_set.py similarity index 100% rename from tests/set.py rename to tests/test_set.py diff --git a/tests/tokenizer.py b/tests/test_tokenizer.py similarity index 100% rename from tests/tokenizer.py rename to tests/test_tokenizer.py diff --git a/tests/update.py b/tests/test_update.py similarity index 100% rename from tests/update.py rename to tests/test_update.py diff --git a/tests/zone.py b/tests/test_zone.py similarity index 100% rename from tests/zone.py rename to tests/test_zone.py diff --git a/tests/utest.py b/tests/utest.py new file mode 100644 index 00000000..32c1d753 --- /dev/null +++ b/tests/utest.py @@ -0,0 +1,8 @@ +import os.path +import sys +import unittest + +if __name__ == '__main__': + sys.path.insert(0, os.path.realpath('..')) + suites = unittest.defaultTestLoader.discover('.') + unittest.TextTestRunner(verbosity=2).run(suites) -- 2.47.3