Rev 3216: Prepare test id list sanity checks. in file:///v/home/vila/src/bzr/experimental/selftest/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Feb 15 13:25:10 GMT 2008


At file:///v/home/vila/src/bzr/experimental/selftest/

------------------------------------------------------------
revno: 3216
revision-id:v.ladeuil+lp at free.fr-20080215132504-m43kszd99ufmwxr3
parent: v.ladeuil+lp at free.fr-20080215105702-52sb8hijq9cfy0i7
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: selftest
timestamp: Fri 2008-02-15 14:25:04 +0100
message:
  Prepare test id list sanity checks.
  
  * bzrlib/tests/test_selftest.py:
  (TestTestIdList): Add tests for suite_matches_id_list.
  
  * bzrlib/tests/__init__.py:
  (suite_matches_id_list): Test list filtering 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-02-14 16:09:05 +0000
+++ b/bzrlib/tests/__init__.py	2008-02-15 13:25:04 +0000
@@ -2542,6 +2542,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.

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2008-02-15 10:57:02 +0000
+++ b/bzrlib/tests/test_selftest.py	2008-02-15 13:25:04 +0000
@@ -1995,6 +1995,31 @@
         suite = tests.test_suite(test_list)
         self.assertEquals(test_list, _test_ids(suite))
 
+    def test_test_suite_matches_id_list_with_unknown(self):
+        loader = TestUtil.TestLoader()
+        suite = loader.loadTestsFromModuleName('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()
+        suite = loader.loadTestsFromModuleName('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):
 
@@ -2049,3 +2074,4 @@
 
         suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
         self.assertEquals([], _test_ids(suite))
+



More information about the bazaar-commits mailing list