Rev 3307: Help identify duplicates IDs in test suite in file:///v/home/vila/src/bzr/experimental/faster-selftest/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Mar 24 19:12:13 GMT 2008
At file:///v/home/vila/src/bzr/experimental/faster-selftest/
------------------------------------------------------------
revno: 3307
revision-id: v.ladeuil+lp at free.fr-20080324191209-23lppe6oqc0ef4kh
parent: v.ladeuil+lp at free.fr-20080324154444-38ox0sd3t1er995r
parent: v.ladeuil+lp at free.fr-20080324191104-uq1uc3tscb1det4x
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: test-suite-fixes
timestamp: Mon 2008-03-24 20:12:09 +0100
message:
Help identify duplicates IDs in test suite
modified:
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
------------------------------------------------------------
revno: 3302.1.1
revision-id: v.ladeuil+lp at free.fr-20080324191104-uq1uc3tscb1det4x
parent: pqm at pqm.ubuntu.com-20080323231145-nh7pyfd19alqp471
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: check-id-filtering
timestamp: Mon 2008-03-24 20:11:04 +0100
message:
Help identify duplicates IDs in test suite and missing tests in id
lists.
* bzrlib/tests/test_selftest.py:
(TestTestIdList): Add tests for suite_matches_id_list.
* bzrlib/tests/__init__.py:
(suite_matches_id_list): Test id list
filtering sanity checks.
(test_suite): When id list filtering is used do some sanity
checks.
modified:
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2008-03-16 10:45:53 +0000
+++ b/bzrlib/tests/__init__.py 2008-03-24 19:11:04 +0000
@@ -2573,6 +2573,40 @@
ftest.close()
return test_list
+def suite_matches_id_list(test_suite, id_list):
+ """Warns about tests not appearing or appearing more than once.
+
+ :param test_suite: A TestSuite object.
+ :param test_id_list: The list of test ids that should be found in
+ test_suite.
+
+ :return: (absents, duplicates) absents is a list containing the test found
+ in id_list but not in test_suite, duplicates is a list containing the
+ test found multiple times in test_suite.
+
+ When using a prefined test id list, it may occurs that some tests do not
+ exist anymore or that some tests use the same id. This function warns the
+ tester about potential problems in his workflow (test lists are volatile)
+ or in the test suite itself (using the same id for several tests does not
+ help to localize defects).
+ """
+ # Build a dict counting id occurrences
+ tests = dict()
+ for test in iter_suite_tests(test_suite):
+ id = test.id()
+ tests[id] = tests.get(id, 0) + 1
+
+ not_found = []
+ duplicates = []
+ for id in id_list:
+ occurs = tests.get(id, 0)
+ if not occurs:
+ not_found.append(id)
+ elif occurs > 1:
+ duplicates.append(id)
+
+ return not_found, duplicates
+
class TestIdList(object):
"""Test id list to filter a test suite.
@@ -2838,6 +2872,15 @@
sys.getdefaultencoding())
reload(sys)
sys.setdefaultencoding(default_encoding)
+
+ if keep_only is not None:
+ # Do some sanity checks on the id_list filtering
+ not_found, duplicates = suite_matches_id_list(suite, keep_only)
+ for id in not_found:
+ bzrlib.trace.warning('"%s" not found in the test suite', id)
+ for id in duplicates:
+ bzrlib.trace.warning('"%s" is used as an id by several tests', id)
+
return suite
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2008-03-24 15:44:44 +0000
+++ b/bzrlib/tests/test_selftest.py 2008-03-24 19:12:09 +0000
@@ -1991,6 +1991,32 @@
suite = tests.test_suite(test_list)
self.assertEquals(test_list, self._test_ids(suite))
+ def test_test_suite_matches_id_list_with_unknown(self):
+ loader = TestUtil.TestLoader()
+ import bzrlib.tests.test_sampler
+ suite = loader.loadTestsFromModule(bzrlib.tests.test_sampler)
+ test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing',
+ 'bogus']
+ not_found, duplicates = tests.suite_matches_id_list(suite, test_list)
+ self.assertEquals(['bogus'], not_found)
+ self.assertEquals([], duplicates)
+
+ def test_suite_matches_id_list_with_duplicates(self):
+ loader = TestUtil.TestLoader()
+ import bzrlib.tests.test_sampler
+ suite = loader.loadTestsFromModule(bzrlib.tests.test_sampler)
+ dupes = loader.suiteClass()
+ for test in iter_suite_tests(suite):
+ dupes.addTest(test)
+ dupes.addTest(test) # Add it again
+
+ test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing',]
+ not_found, duplicates = tests.suite_matches_id_list(
+ dupes, test_list)
+ self.assertEquals([], not_found)
+ self.assertEquals(['bzrlib.tests.test_sampler.DemoTest.test_nothing'],
+ duplicates)
+
class TestLoadTestIdList(tests.TestCaseInTempDir):
More information about the bazaar-commits
mailing list