Rev 3311: Add sanity checks to selftest --load-list in http://code.launchpad.net/%7Ev-ladeuil/bzr/bzr.integration

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Mar 27 15:06:29 GMT 2008


At http://code.launchpad.net/%7Ev-ladeuil/bzr/bzr.integration

------------------------------------------------------------
revno: 3311
revision-id: v.ladeuil+lp at free.fr-20080327150604-gsasqldpbdivo1d9
parent: pqm at pqm.ubuntu.com-20080327064129-8egj1nnju8z9v91b
parent: v.ladeuil+lp at free.fr-20080327145707-0brs5r07cfuk3fhj
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: trunk
timestamp: Thu 2008-03-27 16:06:04 +0100
message:
  Add sanity checks to selftest --load-list
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
    ------------------------------------------------------------
    revno: 3302.3.3
    revision-id: v.ladeuil+lp at free.fr-20080327145707-0brs5r07cfuk3fhj
    parent: v.ladeuil+lp at free.fr-20080326214255-02rhczp1uixzhvsm
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: check-id-filtering
    timestamp: Thu 2008-03-27 15:57:07 +0100
    message:
      Fix PEP8 catched by Aaron. Update NEWS.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
    ------------------------------------------------------------
    revno: 3302.3.2
    revision-id: v.ladeuil+lp at free.fr-20080326214255-02rhczp1uixzhvsm
    parent: v.ladeuil+lp at free.fr-20080324191104-uq1uc3tscb1det4x
    parent: v.ladeuil+lp at free.fr-20080326214222-5gspw57afbmyff7e
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: check-id-filtering
    timestamp: Wed 2008-03-26 22:42:55 +0100
    message:
      merge bzr.dev
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/_knit_load_data_c.pyx   knit_c.pyx-20070509143944-u42gy8w387a10m0j-1
      bzrlib/_knit_load_data_py.py   _knit_load_data_py.p-20070629000948-9a0nh4s118bi5y8n-1
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/bundle/__init__.py      changeset.py-20050513021216-b02ab57fb9738913
      bzrlib/bundle/serializer/v4.py v10.py-20070611062757-5ggj7k18s9dej0fr-1
      bzrlib/debug.py                debug.py-20061102062349-vdhrw9qdpck8cl35-1
      bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
      bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
      bzrlib/merge.py                merge.py-20050513021216-953b65a438527106
      bzrlib/multiparent.py          __init__.py-20070410133617-n1jdhcc1n1mibarp-1
      bzrlib/reconcile.py            reweave_inventory.py-20051108164726-1e5e0934febac06e
      bzrlib/repofmt/knitrepo.py     knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
      bzrlib/repofmt/weaverepo.py    presplitout.py-20070125045333-wfav3tsh73oxu3zk-1
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
      bzrlib/symbol_versioning.py    symbol_versioning.py-20060105104851-9ecf8af605d15a80
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/test_pull.py test_pull.py-20051201144907-64959364f629947f
      bzrlib/tests/interversionedfile_implementations/test_join.py test_join.py-20060302012326-9b5e9b0f0a03fedc
      bzrlib/tests/repository_implementations/test_check_reconcile.py test_broken.py-20070928125406-62236394w0jpbpd6-2
      bzrlib/tests/repository_implementations/test_iter_reverse_revision_history.py test_iter_reverse_re-20070217015036-spu7j5ggch7pbpyd-1
      bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
      bzrlib/tests/test_bundle.py    test.py-20050630184834-092aa401ab9f039c
      bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
      bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
      bzrlib/tests/test_read_bundle.py test_read_bundle.py-20060615211421-ud8cwr1ulgd914zf-1
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
      bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
      bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
      bzrlib/weave.py                knit.py-20050627021749-759c29984154256b
        ------------------------------------------------------------
        revno: 3302.4.1
        revision-id: v.ladeuil+lp at free.fr-20080326214222-5gspw57afbmyff7e
        parent: pqm at pqm.ubuntu.com-20080323231145-nh7pyfd19alqp471
        parent: pqm at pqm.ubuntu.com-20080326124829-ggl5f8711x321ahw
        committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
        branch nick: bzr-dev
        timestamp: Wed 2008-03-26 22:42:22 +0100
        message:
          merge bzr.dev
        modified:
          NEWS                           NEWS-20050323055033-4e00b5db738777ff
          bzrlib/_knit_load_data_c.pyx   knit_c.pyx-20070509143944-u42gy8w387a10m0j-1
          bzrlib/_knit_load_data_py.py   _knit_load_data_py.p-20070629000948-9a0nh4s118bi5y8n-1
          bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
          bzrlib/bundle/__init__.py      changeset.py-20050513021216-b02ab57fb9738913
          bzrlib/bundle/serializer/v4.py v10.py-20070611062757-5ggj7k18s9dej0fr-1
          bzrlib/debug.py                debug.py-20061102062349-vdhrw9qdpck8cl35-1
          bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
          bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
          bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
          bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
          bzrlib/merge.py                merge.py-20050513021216-953b65a438527106
          bzrlib/multiparent.py          __init__.py-20070410133617-n1jdhcc1n1mibarp-1
          bzrlib/reconcile.py            reweave_inventory.py-20051108164726-1e5e0934febac06e
          bzrlib/repofmt/knitrepo.py     knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
          bzrlib/repofmt/weaverepo.py    presplitout.py-20070125045333-wfav3tsh73oxu3zk-1
          bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
          bzrlib/symbol_versioning.py    symbol_versioning.py-20060105104851-9ecf8af605d15a80
          bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
          bzrlib/tests/blackbox/test_pull.py test_pull.py-20051201144907-64959364f629947f
          bzrlib/tests/interversionedfile_implementations/test_join.py test_join.py-20060302012326-9b5e9b0f0a03fedc
          bzrlib/tests/repository_implementations/test_check_reconcile.py test_broken.py-20070928125406-62236394w0jpbpd6-2
          bzrlib/tests/repository_implementations/test_iter_reverse_revision_history.py test_iter_reverse_re-20070217015036-spu7j5ggch7pbpyd-1
          bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
          bzrlib/tests/test_bundle.py    test.py-20050630184834-092aa401ab9f039c
          bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
          bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
          bzrlib/tests/test_read_bundle.py test_read_bundle.py-20060615211421-ud8cwr1ulgd914zf-1
          bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
          bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
          bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
          bzrlib/weave.py                knit.py-20050627021749-759c29984154256b
    ------------------------------------------------------------
    revno: 3302.3.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 'NEWS'
--- a/NEWS	2008-03-27 06:41:29 +0000
+++ b/NEWS	2008-03-27 15:06:04 +0000
@@ -82,6 +82,10 @@
       failing test.  Be aware that using this feature is likely to cause
       spurious test failures if used with the full suite. (Andrew Bennetts)
 
+    * selftest --load-list now does some sanity checks regarding duplicate test
+      IDs and tests present in the list but not found in the actual test suite.
+      (Vincent Ladeuil)
+
     * The test suite takes much less memory to run, and is a bit faster.  This
       is done by clearing most attributes of TestCases after running them, if
       they succeeded.  (Andrew Bennetts)

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2008-03-26 11:15:18 +0000
+++ b/bzrlib/tests/__init__.py	2008-03-27 14:57:07 +0000
@@ -2589,6 +2589,41 @@
     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.
 
@@ -2853,6 +2888,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-02-19 01:23:02 +0000
+++ b/bzrlib/tests/test_selftest.py	2008-03-26 21:42:55 +0000
@@ -1993,6 +1993,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