Rev 3668: (vila) Add test prefix aliases for selftest --starting-with in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Sat Aug 30 10:10:08 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3668
revision-id: pqm at pqm.ubuntu.com-20080830091000-3oibqwlrxvdpgo5l
parent: pqm at pqm.ubuntu.com-20080829214033-n9tclw44g7b42hsc
parent: v.ladeuil+lp at free.fr-20080830083910-alwqc56xt3grsnj7
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2008-08-30 10:10:00 +0100
message:
  (vila) Add test prefix aliases for selftest --starting-with
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
    ------------------------------------------------------------
    revno: 3667.1.1
    revision-id: v.ladeuil+lp at free.fr-20080830083910-alwqc56xt3grsnj7
    parent: pqm at pqm.ubuntu.com-20080829214033-n9tclw44g7b42hsc
    parent: v.ladeuil+lp at free.fr-20080830083535-8qdpr48ehdxp7cjh
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: trunk
    timestamp: Sat 2008-08-30 10:39:10 +0200
    message:
      (vila) Add test prefix aliases for selftest --starting-with
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
    ------------------------------------------------------------
    revno: 3649.6.3
    revision-id: v.ladeuil+lp at free.fr-20080830083535-8qdpr48ehdxp7cjh
    parent: v.ladeuil+lp at free.fr-20080829160936-0pufyzshfrotcrrf
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: selftest-prefixes
    timestamp: Sat 2008-08-30 10:35:35 +0200
    message:
      Fixed typos as per John's review.
    modified:
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
    ------------------------------------------------------------
    revno: 3649.6.2
    revision-id: v.ladeuil+lp at free.fr-20080829160936-0pufyzshfrotcrrf
    parent: v.ladeuil+lp at free.fr-20080828141840-9s90i6j64s6958dq
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: selftest-prefixes
    timestamp: Fri 2008-08-29 18:09:36 +0200
    message:
      Replace aliases in selftest --starting-with option.
      
      * bzrlib/tests/__init__.py:
      (TestPrefixAliasRegistry): A registry class for test prefix
      aliases.
      (test_prefix_alias_registry): The registry itself with the
      predefined aliases. A first conservative set have been defined
      leaving devs define additional ones in their own dedicated plugin
      or plugin authors define semi-official ones in their plugins.
      
      * bzrlib/tests/test_selftest.py:
      (TestTestPrefixRegistry): Tests for test prefixes.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
    ------------------------------------------------------------
    revno: 3649.6.1
    revision-id: v.ladeuil+lp at free.fr-20080828141840-9s90i6j64s6958dq
    parent: pqm at pqm.ubuntu.com-20080825182248-dydy5bn4n5akbfjq
    parent: pqm at pqm.ubuntu.com-20080828092217-98wmtek2p8cie8sc
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: selftest-prefixes
    timestamp: Thu 2008-08-28 16:18:40 +0200
    message:
      merge bzr.dev at 3655
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/_patiencediff_c.c       _patiencediff_c.c-20070721205602-q3imkipwlgagp3cy-1
      bzrlib/btree_index.py          index.py-20080624222253-p0x5f92uyh5hw734-7
      bzrlib/chunk_writer.py         chunk_writer.py-20080630234519-6ggn4id17nipovny-1
      bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
      bzrlib/plugin.py               plugin.py-20050622060424-829b654519533d69
      bzrlib/tests/test_btree_index.py test_index.py-20080624222253-p0x5f92uyh5hw734-13
      bzrlib/tests/test_chunk_writer.py test_chunk_writer.py-20080630234519-6ggn4id17nipovny-2
      bzrlib/tests/test_diff.py      testdiff.py-20050727164403-d1a3496ebb12e339
      bzrlib/tests/test_log.py       testlog.py-20050728115707-1a514809d7d49309
      bzrlib/transport/http/_pycurl.py pycurlhttp.py-20060110060940-4e2a705911af77a6
      bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
=== modified file 'NEWS'
--- a/NEWS	2008-08-29 19:32:00 +0000
+++ b/NEWS	2008-08-30 08:39:10 +0000
@@ -86,6 +86,10 @@
       addition, addCleanup no longer requires that the callables passed to
       it be unique. (Jonathan Lange)
 
+    * ``selftest``'s ``--starting-with`` option can now use predefined
+      prefixes so that one can say ``bzr selftest -s bp.loom`` instead of
+      ``bzr selftest -s bzrlib.plugins.loom``. (Vincent Ladeuil)
+
   INTERNALS:
 
     * A new plugin interface, ``bzrlib.log.log_adapters``, has been added.

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2008-08-19 23:12:01 +0000
+++ b/bzrlib/tests/__init__.py	2008-08-30 08:35:35 +0000
@@ -58,6 +58,7 @@
     progress,
     ui,
     urlutils,
+    registry,
     workingtree,
     )
 import bzrlib.branch
@@ -2671,6 +2672,59 @@
         return self.tests.has_key(test_id)
 
 
+class TestPrefixAliasRegistry(registry.Registry):
+    """A registry for test prefix aliases.
+
+    This helps implement shorcuts for the --starting-with selftest
+    option. Overriding existing prefixes is not allowed but not fatal (a
+    warning will be emitted).
+    """
+
+    def register(self, key, obj, help=None, info=None,
+                 override_existing=False):
+        """See Registry.register.
+
+        Trying to override an existing alias causes a warning to be emitted,
+        not a fatal execption.
+        """
+        try:
+            super(TestPrefixAliasRegistry, self).register(
+                key, obj, help=help, info=info, override_existing=False)
+        except KeyError:
+            actual = self.get(key)
+            note('Test prefix alias %s is already used for %s, ignoring %s'
+                 % (key, actual, obj))
+
+    def resolve_alias(self, id_start):
+        """Replace the alias by the prefix in the given string.
+
+        Using an unknown prefix is an error to help catching typos.
+        """
+        parts = id_start.split('.')
+        try:
+            parts[0] = self.get(parts[0])
+        except KeyError:
+            raise errors.BzrCommandError(
+                '%s is not a known test prefix alias' % parts[0])
+        return '.'.join(parts)
+
+
+test_prefix_alias_registry = TestPrefixAliasRegistry()
+"""Registry of test prefix aliases."""
+
+
+# This alias allows to detect typos ('bzrlin.') by making all valid test ids
+# appear prefixed ('bzrlib.' is "replaced" by 'bzrlib.').
+test_prefix_alias_registry.register('bzrlib', 'bzrlib')
+
+# Obvious higest levels prefixes, feel free to add your own via a plugin
+test_prefix_alias_registry.register('bd', 'bzrlib.doc')
+test_prefix_alias_registry.register('bu', 'bzrlib.utils')
+test_prefix_alias_registry.register('bt', 'bzrlib.tests')
+test_prefix_alias_registry.register('bb', 'bzrlib.tests.blackbox')
+test_prefix_alias_registry.register('bp', 'bzrlib.plugins')
+
+
 def test_suite(keep_only=None, starting_with=None):
     """Build and return TestSuite for the whole of bzrlib.
 
@@ -2838,6 +2892,7 @@
     loader = TestUtil.TestLoader()
 
     if starting_with is not None:
+        starting_with = test_prefix_alias_registry.resolve_alias(starting_with)
         # We take precedence over keep_only because *at loading time* using
         # both options means we will load less tests for the same final result.
         def interesting_module(name):

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2008-08-29 00:35:57 +0000
+++ b/bzrlib/tests/test_selftest.py	2008-08-30 08:39:10 +0000
@@ -2170,3 +2170,46 @@
 
         suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
         self.assertEquals([], _test_ids(suite))
+
+
+class TestTestPrefixRegistry(tests.TestCase):
+
+    def _get_registry(self):
+        tp_registry = tests.TestPrefixAliasRegistry()
+        return tp_registry
+
+    def test_register_new_prefix(self):
+        tpr = self._get_registry()
+        tpr.register('foo', 'fff.ooo.ooo')
+        self.assertEquals('fff.ooo.ooo', tpr.get('foo'))
+
+    def test_register_existing_prefix(self):
+        tpr = self._get_registry()
+        tpr.register('bar', 'bbb.aaa.rrr')
+        tpr.register('bar', 'bBB.aAA.rRR')
+        self.assertEquals('bbb.aaa.rrr', tpr.get('bar'))
+        self.assertContainsRe(self._get_log(keep_log_file=True),
+                              r'.*bar.*bbb.aaa.rrr.*bBB.aAA.rRR')
+
+    def test_get_unknown_prefix(self):
+        tpr = self._get_registry()
+        self.assertRaises(KeyError, tpr.get, 'I am not a prefix')
+
+    def test_resolve_prefix(self):
+        tpr = self._get_registry()
+        tpr.register('bar', 'bb.aa.rr')
+        self.assertEquals('bb.aa.rr', tpr.resolve_alias('bar'))
+
+    def test_resolve_unknown_alias(self):
+        tpr = self._get_registry()
+        self.assertRaises(errors.BzrCommandError,
+                          tpr.resolve_alias, 'I am not a prefix')
+
+    def test_predefined_prefixes(self):
+        tpr = tests.test_prefix_alias_registry
+        self.assertEquals('bzrlib', tpr.resolve_alias('bzrlib'))
+        self.assertEquals('bzrlib.doc', tpr.resolve_alias('bd'))
+        self.assertEquals('bzrlib.utils', tpr.resolve_alias('bu'))
+        self.assertEquals('bzrlib.tests', tpr.resolve_alias('bt'))
+        self.assertEquals('bzrlib.tests.blackbox', tpr.resolve_alias('bb'))
+        self.assertEquals('bzrlib.plugins', tpr.resolve_alias('bp'))




More information about the bazaar-commits mailing list