Rev 2779: (mbp, r=aaron) Add per-inventory-implementation tests in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Sep 3 06:17:38 BST 2007


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

------------------------------------------------------------
revno: 2779
revision-id: pqm at pqm.ubuntu.com-20070903051736-tnjjdk1ii0258an0
parent: pqm at pqm.ubuntu.com-20070903031921-8msn0bmzubicv5b1
parent: mbp at sourcefrog.net-20070903044538-4iglni6xv5nkk737
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2007-09-03 06:17:36 +0100
message:
  (mbp,r=aaron) Add per-inventory-implementation tests
added:
  bzrlib/tests/inventory_implementations/ bzrlibtestsinventory-20070820060653-4mjbbmwhp74dsf3x-1
  bzrlib/tests/inventory_implementations/__init__.py __init__.py-20070821044532-olbadbokgv3qv1yd-1
  bzrlib/tests/inventory_implementations/basics.py basics.py-20070903044446-kdjwbiu1p1zi9phs-1
modified:
  bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_inv.py       testinv.py-20050722220913-1dc326138d1a5892
  bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
    ------------------------------------------------------------
    revno: 2729.1.2.1.9
    merged: mbp at sourcefrog.net-20070903044538-4iglni6xv5nkk737
    parent: mbp at sourcefrog.net-20070903044151-1i0i66weatycmhf1
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: inv-tests
    timestamp: Mon 2007-09-03 14:45:38 +1000
    message:
      Move actual tests from inventory_implementations __init__ into basics.py (Aaron)
    ------------------------------------------------------------
    revno: 2729.1.2.1.8
    merged: mbp at sourcefrog.net-20070903044151-1i0i66weatycmhf1
    parent: mbp at sourcefrog.net-20070903043549-0cfyrgx7z2h8ppks
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: inv-tests
    timestamp: Mon 2007-09-03 14:41:51 +1000
    message:
      Fix mis-merged NEWS entry
    ------------------------------------------------------------
    revno: 2729.1.2.1.7
    merged: mbp at sourcefrog.net-20070903043549-0cfyrgx7z2h8ppks
    parent: mbp at sourcefrog.net-20070824061553-6bou4l4e322qeufy
    parent: pqm at pqm.ubuntu.com-20070903031921-8msn0bmzubicv5b1
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: inv-tests
    timestamp: Mon 2007-09-03 14:35:49 +1000
    message:
      merge trunk
    ------------------------------------------------------------
    revno: 2729.1.2.1.6
    merged: mbp at sourcefrog.net-20070824061553-6bou4l4e322qeufy
    parent: mbp at sourcefrog.net-20070821052959-5odvyjziwyuaeo3d
    parent: pqm at pqm.ubuntu.com-20070822052832-nxby1d1plok4syek
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: inv-tests
    timestamp: Fri 2007-08-24 16:15:53 +1000
    message:
      merge trunk
    ------------------------------------------------------------
    revno: 2729.1.2.1.5
    merged: mbp at sourcefrog.net-20070821052959-5odvyjziwyuaeo3d
    parent: mbp at sourcefrog.net-20070821050831-p5igoti17fstdxds
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: inv-refactor
    timestamp: Tue 2007-08-21 15:29:59 +1000
    message:
      Move per-inventory tests from test_inv to tests.inventory_implementations
    ------------------------------------------------------------
    revno: 2729.1.2.1.4
    merged: mbp at sourcefrog.net-20070821050831-p5igoti17fstdxds
    parent: mbp at sourcefrog.net-20070821050429-4dn2xziq91kgwkir
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: inv-refactor
    timestamp: Tue 2007-08-21 15:08:31 +1000
    message:
      move some osutils-related tests from test_inv to test_osutils
    ------------------------------------------------------------
    revno: 2729.1.2.1.3
    merged: mbp at sourcefrog.net-20070821050429-4dn2xziq91kgwkir
    parent: mbp at sourcefrog.net-20070821050207-ys2rrhoo0pud4isl
    parent: mbp at sourcefrog.net-20070821050305-64tehj3dk3d4y1px
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: inv-refactor
    timestamp: Tue 2007-08-21 15:04:29 +1000
    message:
      TestScenarioAdapter fix merge
    ------------------------------------------------------------
    revno: 2729.1.2.1.2
    merged: mbp at sourcefrog.net-20070821050207-ys2rrhoo0pud4isl
    parent: mbp at sourcefrog.net-20070821044932-92qvnrn8u62f8cl2
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: inv-refactor
    timestamp: Tue 2007-08-21 15:02:07 +1000
    message:
      Start moving inventory tests into per-inventory module
    ------------------------------------------------------------
    revno: 2729.1.2.1.1
    merged: mbp at sourcefrog.net-20070821044932-92qvnrn8u62f8cl2
    parent: mbp at sourcefrog.net-20070821030216-2bfghdwpyk2se1of
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: inv-refactor
    timestamp: Tue 2007-08-21 14:49:32 +1000
    message:
      Start adding per-inventory tests
=== added directory 'bzrlib/tests/inventory_implementations'
=== added file 'bzrlib/tests/inventory_implementations/__init__.py'
--- a/bzrlib/tests/inventory_implementations/__init__.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/inventory_implementations/__init__.py	2007-09-03 04:45:38 +0000
@@ -0,0 +1,59 @@
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Tests for different inventory implementations"""
+
+# NOTE: Don't import Inventory here, to make sure that we don't accidentally
+# hardcode that when we should be using self.make_inventory
+
+from bzrlib import (
+        errors,
+        )
+
+from bzrlib.inventory import (
+        InventoryDirectory,
+        InventoryEntry,
+        InventoryFile,
+        InventoryLink,
+        ROOT_ID,
+        TreeReference,
+        )
+
+from bzrlib.tests import (
+        TestCase,
+        multiply_tests_from_modules,
+        )
+
+
+def _inventory_test_scenarios():
+    """Return a sequence of test scenarios.
+
+    Each scenario is (scenario_name_suffix, params).  The params are each 
+    set as attributes on the test case.
+    """
+    from bzrlib.inventory import (
+        Inventory,
+        )
+    yield ('Inventory', dict(inventory_class=Inventory))
+
+
+def test_suite():
+    """Generate suite containing all parameterized tests"""
+    modules_to_test = [
+            'bzrlib.tests.inventory_implementations.basics',
+            ]
+    return multiply_tests_from_modules(modules_to_test,
+            _inventory_test_scenarios())

=== added file 'bzrlib/tests/inventory_implementations/basics.py'
--- a/bzrlib/tests/inventory_implementations/basics.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/inventory_implementations/basics.py	2007-09-03 04:45:38 +0000
@@ -0,0 +1,211 @@
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Tests for different inventory implementations"""
+
+# NOTE: Don't import Inventory here, to make sure that we don't accidentally
+# hardcode that when we should be using self.make_inventory
+
+from bzrlib import (
+        errors,
+        )
+
+from bzrlib.inventory import (
+        InventoryDirectory,
+        InventoryEntry,
+        InventoryFile,
+        InventoryLink,
+        ROOT_ID,
+        TreeReference,
+        )
+
+from bzrlib.tests import (
+        TestCase,
+        multiply_tests_from_modules,
+        )
+
+
+class TestInventoryBasics(TestCase):
+    # Most of these were moved the rather old bzrlib.tests.test_inv module
+    
+    def make_inventory(self, root_id):
+        return self.inventory_class(root_id=root_id)
+
+    def test_creation_from_root_id(self):
+        # iff a root id is passed to the constructor, a root directory is made
+        inv = self.make_inventory(root_id='tree-root')
+        self.assertNotEqual(None, inv.root)
+        self.assertEqual('tree-root', inv.root.file_id)
+
+    def test_add_path_of_root(self):
+        # if no root id is given at creation time, there is no root directory
+        inv = self.make_inventory(root_id=None)
+        self.assertIs(None, inv.root)
+        # add a root entry by adding its path
+        ie = inv.add_path("", "directory", "my-root")
+        self.assertEqual("my-root", ie.file_id)
+        self.assertIs(ie, inv.root)
+
+    def test_add_path(self):
+        inv = self.make_inventory(root_id='tree_root')
+        ie = inv.add_path('hello', 'file', 'hello-id')
+        self.assertEqual('hello-id', ie.file_id)
+        self.assertEqual('file', ie.kind)
+
+    def test_is_root(self):
+        """Ensure our root-checking code is accurate."""
+        inv = self.make_inventory('TREE_ROOT')
+        self.assertTrue(inv.is_root('TREE_ROOT'))
+        self.assertFalse(inv.is_root('booga'))
+        inv.root.file_id = 'booga'
+        self.assertFalse(inv.is_root('TREE_ROOT'))
+        self.assertTrue(inv.is_root('booga'))
+        # works properly even if no root is set
+        inv.root = None
+        self.assertFalse(inv.is_root('TREE_ROOT'))
+        self.assertFalse(inv.is_root('booga'))
+
+    def test_create_tree_reference(self):
+        inv = self.make_inventory('tree-root-123')
+        inv.add(TreeReference('nested-id', 'nested', parent_id='tree-root-123',
+                              revision='rev', reference_revision='rev2'))
+
+    def test_error_encoding(self):
+        inv = self.make_inventory('tree-root')
+        inv.add(InventoryFile('a-id', u'\u1234', 'tree-root'))
+        try:
+            inv.add(InventoryFile('b-id', u'\u1234', 'tree-root'))
+        except errors.BzrError, e:
+            self.assertContainsRe(str(e), u'\u1234'.encode('utf-8'))
+        else:
+            self.fail('BzrError not raised')
+
+    def test_ids(self):
+        """Test detection of files within selected directories."""
+        inv = self.make_inventory(ROOT_ID)
+        for args in [('src', 'directory', 'src-id'),
+                     ('doc', 'directory', 'doc-id'),
+                     ('src/hello.c', 'file'),
+                     ('src/bye.c', 'file', 'bye-id'),
+                     ('Makefile', 'file')]:
+            inv.add_path(*args)
+        self.assertEqual(inv.path2id('src'), 'src-id')
+        self.assertEqual(inv.path2id('src/bye.c'), 'bye-id')
+        self.assert_('src-id' in inv)
+
+    def test_non_directory_children(self):
+        """Test path2id when a parent directory has no children"""
+        inv = self.make_inventory('tree_root')
+        inv.add(InventoryFile('file-id','file',
+                                        parent_id='tree_root'))
+        inv.add(InventoryLink('link-id','link',
+                                        parent_id='tree_root'))
+        self.assertIs(None, inv.path2id('file/subfile'))
+        self.assertIs(None, inv.path2id('link/subfile'))
+
+    def test_iter_entries(self):
+        inv = self.make_inventory('tree-root')
+        for args in [('src', 'directory', 'src-id'),
+                     ('doc', 'directory', 'doc-id'),
+                     ('src/hello.c', 'file', 'hello-id'),
+                     ('src/bye.c', 'file', 'bye-id'),
+                     ('Makefile', 'file', 'makefile-id')]:
+            inv.add_path(*args)
+        self.assertEqual([
+            ('', 'tree-root'),
+            ('Makefile', 'makefile-id'),
+            ('doc', 'doc-id'),
+            ('src', 'src-id'),
+            ('src/bye.c', 'bye-id'),
+            ('src/hello.c', 'hello-id'),
+            ], [(path, ie.file_id) for path, ie in inv.iter_entries()])
+
+    def test_iter_entries_by_dir(self):
+        inv = self.make_inventory('tree-root')
+        for args in [('src', 'directory', 'src-id'),
+                     ('doc', 'directory', 'doc-id'),
+                     ('src/hello.c', 'file', 'hello-id'),
+                     ('src/bye.c', 'file', 'bye-id'),
+                     ('zz', 'file', 'zz-id'),
+                     ('src/sub/', 'directory', 'sub-id'),
+                     ('src/zz.c', 'file', 'zzc-id'),
+                     ('src/sub/a', 'file', 'a-id'),
+                     ('Makefile', 'file', 'makefile-id')]:
+            inv.add_path(*args)
+        self.assertEqual([
+            ('', 'tree-root'),
+            ('Makefile', 'makefile-id'),
+            ('doc', 'doc-id'),
+            ('src', 'src-id'),
+            ('zz', 'zz-id'),
+            ('src/bye.c', 'bye-id'),
+            ('src/hello.c', 'hello-id'),
+            ('src/sub', 'sub-id'),
+            ('src/zz.c', 'zzc-id'),
+            ('src/sub/a', 'a-id'),
+            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir()])
+        self.assertEqual([
+            ('', 'tree-root'),
+            ('Makefile', 'makefile-id'),
+            ('doc', 'doc-id'),
+            ('src', 'src-id'),
+            ('zz', 'zz-id'),
+            ('src/bye.c', 'bye-id'),
+            ('src/hello.c', 'hello-id'),
+            ('src/sub', 'sub-id'),
+            ('src/zz.c', 'zzc-id'),
+            ('src/sub/a', 'a-id'),
+            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
+                specific_file_ids=('a-id', 'zzc-id', 'doc-id', 'tree-root',
+                'hello-id', 'bye-id', 'zz-id', 'src-id', 'makefile-id',
+                'sub-id'))])
+
+        self.assertEqual([
+            ('Makefile', 'makefile-id'),
+            ('doc', 'doc-id'),
+            ('zz', 'zz-id'),
+            ('src/bye.c', 'bye-id'),
+            ('src/hello.c', 'hello-id'),
+            ('src/zz.c', 'zzc-id'),
+            ('src/sub/a', 'a-id'),
+            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
+                specific_file_ids=('a-id', 'zzc-id', 'doc-id',
+                'hello-id', 'bye-id', 'zz-id', 'makefile-id'))])
+
+        self.assertEqual([
+            ('Makefile', 'makefile-id'),
+            ('src/bye.c', 'bye-id'),
+            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
+                specific_file_ids=('bye-id', 'makefile-id'))])
+
+        self.assertEqual([
+            ('Makefile', 'makefile-id'),
+            ('src/bye.c', 'bye-id'),
+            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
+                specific_file_ids=('bye-id', 'makefile-id'))])
+
+        self.assertEqual([
+            ('src/bye.c', 'bye-id'),
+            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
+                specific_file_ids=('bye-id',))])
+
+    def test_add_recursive(self):
+        parent = InventoryDirectory('src-id', 'src', 'tree-root')
+        child = InventoryFile('hello-id', 'hello.c', 'src-id')
+        parent.children[child.file_id] = child
+        inv = self.make_inventory('tree-root')
+        inv.add(parent)
+        self.assertEqual('src/hello.c', inv.id2path('hello-id'))

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2007-09-01 16:04:44 +0000
+++ b/bzrlib/errors.py	2007-09-03 04:35:49 +0000
@@ -1334,7 +1334,6 @@
         self.badline = badline
         self.filename = filename
 
-
 class KnitIndexUnknownMethod(KnitError):
     """Raised when we don't understand the storage method.
 

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2007-08-29 01:16:53 +0000
+++ b/bzrlib/tests/__init__.py	2007-09-03 04:35:49 +0000
@@ -135,6 +135,7 @@
     import bzrlib.tests.interrepository_implementations
     import bzrlib.tests.interversionedfile_implementations
     import bzrlib.tests.intertree_implementations
+    import bzrlib.tests.inventory_implementations
     import bzrlib.tests.per_lock
     import bzrlib.tests.repository_implementations
     import bzrlib.tests.revisionstore_implementations
@@ -149,6 +150,7 @@
             bzrlib.tests.interrepository_implementations,
             bzrlib.tests.interversionedfile_implementations,
             bzrlib.tests.intertree_implementations,
+            bzrlib.tests.inventory_implementations,
             bzrlib.tests.per_lock,
             bzrlib.tests.repository_implementations,
             bzrlib.tests.revisionstore_implementations,
@@ -374,7 +376,6 @@
     def wasStrictlySuccessful(self):
         if self.unsupported or self.known_failure_count:
             return False
-
         return self.wasSuccessful()
 
 

=== modified file 'bzrlib/tests/test_inv.py'
--- a/bzrlib/tests/test_inv.py	2007-04-04 02:38:10 +0000
+++ b/bzrlib/tests/test_inv.py	2007-08-21 05:29:59 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -14,177 +14,13 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+
 from bzrlib import errors, inventory, osutils
 from bzrlib.inventory import (Inventory, ROOT_ID, InventoryFile,
     InventoryDirectory, InventoryEntry, TreeReference)
-from bzrlib.osutils import (pathjoin, is_inside_any, 
-    is_inside_or_parent_of_any)
 from bzrlib.tests import TestCase
 
 
-class TestInventory(TestCase):
-
-    def test_add_path(self):
-
-        inv = Inventory(root_id=None)
-        self.assertIs(None, inv.root)
-        ie = inv.add_path("", "directory", "my-root")
-        self.assertEqual("my-root", ie.file_id)
-        self.assertIs(ie, inv.root)
-
-    def test_is_within(self):
-
-        SRC_FOO_C = pathjoin('src', 'foo.c')
-        for dirs, fn in [(['src', 'doc'], SRC_FOO_C),
-                         (['src'], SRC_FOO_C),
-                         (['src'], 'src'),
-                         ]:
-            self.assert_(is_inside_any(dirs, fn))
-            
-        for dirs, fn in [(['src'], 'srccontrol'),
-                         (['src'], 'srccontrol/foo')]:
-            self.assertFalse(is_inside_any(dirs, fn))
-
-    def test_is_within_or_parent(self):
-        for dirs, fn in [(['src', 'doc'], 'src/foo.c'),
-                         (['src'], 'src/foo.c'),
-                         (['src/bar.c'], 'src'),
-                         (['src/bar.c', 'bla/foo.c'], 'src'),
-                         (['src'], 'src'),
-                         ]:
-            self.assert_(is_inside_or_parent_of_any(dirs, fn))
-            
-        for dirs, fn in [(['src'], 'srccontrol'),
-                         (['srccontrol/foo.c'], 'src'),
-                         (['src'], 'srccontrol/foo')]:
-            self.assertFalse(is_inside_or_parent_of_any(dirs, fn))
-
-    def test_ids(self):
-        """Test detection of files within selected directories."""
-        inv = Inventory()
-        
-        for args in [('src', 'directory', 'src-id'), 
-                     ('doc', 'directory', 'doc-id'), 
-                     ('src/hello.c', 'file'),
-                     ('src/bye.c', 'file', 'bye-id'),
-                     ('Makefile', 'file')]:
-            inv.add_path(*args)
-            
-        self.assertEqual(inv.path2id('src'), 'src-id')
-        self.assertEqual(inv.path2id('src/bye.c'), 'bye-id')
-        
-        self.assert_('src-id' in inv)
-
-    def test_non_directory_children(self):
-        """Test path2id when a parent directory has no children"""
-        inv = inventory.Inventory('tree_root')
-        inv.add(inventory.InventoryFile('file-id','file', 
-                                        parent_id='tree_root'))
-        inv.add(inventory.InventoryLink('link-id','link', 
-                                        parent_id='tree_root'))
-        self.assertIs(None, inv.path2id('file/subfile'))
-        self.assertIs(None, inv.path2id('link/subfile'))
-
-    def test_iter_entries(self):
-        inv = Inventory()
-        
-        for args in [('src', 'directory', 'src-id'), 
-                     ('doc', 'directory', 'doc-id'), 
-                     ('src/hello.c', 'file', 'hello-id'),
-                     ('src/bye.c', 'file', 'bye-id'),
-                     ('Makefile', 'file', 'makefile-id')]:
-            inv.add_path(*args)
-
-        self.assertEqual([
-            ('', ROOT_ID),
-            ('Makefile', 'makefile-id'),
-            ('doc', 'doc-id'),
-            ('src', 'src-id'),
-            ('src/bye.c', 'bye-id'),
-            ('src/hello.c', 'hello-id'),
-            ], [(path, ie.file_id) for path, ie in inv.iter_entries()])
-            
-    def test_iter_entries_by_dir(self):
-        inv = Inventory()
-        
-        for args in [('src', 'directory', 'src-id'), 
-                     ('doc', 'directory', 'doc-id'), 
-                     ('src/hello.c', 'file', 'hello-id'),
-                     ('src/bye.c', 'file', 'bye-id'),
-                     ('zz', 'file', 'zz-id'),
-                     ('src/sub/', 'directory', 'sub-id'),
-                     ('src/zz.c', 'file', 'zzc-id'),
-                     ('src/sub/a', 'file', 'a-id'),
-                     ('Makefile', 'file', 'makefile-id')]:
-            inv.add_path(*args)
-
-        self.assertEqual([
-            ('', ROOT_ID),
-            ('Makefile', 'makefile-id'),
-            ('doc', 'doc-id'),
-            ('src', 'src-id'),
-            ('zz', 'zz-id'),
-            ('src/bye.c', 'bye-id'),
-            ('src/hello.c', 'hello-id'),
-            ('src/sub', 'sub-id'),
-            ('src/zz.c', 'zzc-id'),
-            ('src/sub/a', 'a-id'),
-            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir()])
-            
-        self.assertEqual([
-            ('', ROOT_ID),
-            ('Makefile', 'makefile-id'),
-            ('doc', 'doc-id'),
-            ('src', 'src-id'),
-            ('zz', 'zz-id'),
-            ('src/bye.c', 'bye-id'),
-            ('src/hello.c', 'hello-id'),
-            ('src/sub', 'sub-id'),
-            ('src/zz.c', 'zzc-id'),
-            ('src/sub/a', 'a-id'),
-            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
-                specific_file_ids=('a-id', 'zzc-id', 'doc-id', ROOT_ID,
-                'hello-id', 'bye-id', 'zz-id', 'src-id', 'makefile-id', 
-                'sub-id'))])
-
-        self.assertEqual([
-            ('Makefile', 'makefile-id'),
-            ('doc', 'doc-id'),
-            ('zz', 'zz-id'),
-            ('src/bye.c', 'bye-id'),
-            ('src/hello.c', 'hello-id'),
-            ('src/zz.c', 'zzc-id'),
-            ('src/sub/a', 'a-id'),
-            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
-                specific_file_ids=('a-id', 'zzc-id', 'doc-id',
-                'hello-id', 'bye-id', 'zz-id', 'makefile-id'))])
-
-        self.assertEqual([
-            ('Makefile', 'makefile-id'),
-            ('src/bye.c', 'bye-id'),
-            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
-                specific_file_ids=('bye-id', 'makefile-id'))])
-
-        self.assertEqual([
-            ('Makefile', 'makefile-id'),
-            ('src/bye.c', 'bye-id'),
-            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
-                specific_file_ids=('bye-id', 'makefile-id'))])
-
-        self.assertEqual([
-            ('src/bye.c', 'bye-id'),
-            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
-                specific_file_ids=('bye-id',))])
-
-    def test_add_recursive(self):
-        parent = InventoryDirectory('src-id', 'src', ROOT_ID)
-        child = InventoryFile('hello-id', 'hello.c', 'src-id')
-        parent.children[child.file_id] = child
-        inv = Inventory()
-        inv.add(parent)
-        self.assertEqual('src/hello.c', inv.id2path('hello-id'))
-
-
 class TestInventoryEntry(TestCase):
 
     def test_file_kind_character(self):
@@ -330,40 +166,3 @@
     def assertChangeDescription(self, expected_change, old_ie, new_ie):
         change = InventoryEntry.describe_change(old_ie, new_ie)
         self.assertEqual(expected_change, change)
-
-
-class TestIsRoot(TestCase):
-    """Ensure our root-checking code is accurate."""
-
-    def test_is_root(self):
-        inv = Inventory('TREE_ROOT')
-        self.assertTrue(inv.is_root('TREE_ROOT'))
-        self.assertFalse(inv.is_root('booga'))
-        inv.root.file_id = 'booga'
-        self.assertFalse(inv.is_root('TREE_ROOT'))
-        self.assertTrue(inv.is_root('booga'))
-        # works properly even if no root is set
-        inv.root = None
-        self.assertFalse(inv.is_root('TREE_ROOT'))
-        self.assertFalse(inv.is_root('booga'))
-
-
-class TestTreeReference(TestCase):
-    
-    def test_create(self):
-        inv = Inventory('tree-root-123')
-        inv.add(TreeReference('nested-id', 'nested', parent_id='tree-root-123',
-                              revision='rev', reference_revision='rev2'))
-
-
-class TestEncoding(TestCase):
-
-    def test_error_encoding(self):
-        inv = Inventory('tree-root')
-        inv.add(InventoryFile('a-id', u'\u1234', 'tree-root'))
-        try:
-            inv.add(InventoryFile('b-id', u'\u1234', 'tree-root'))
-        except errors.BzrError, e:
-            self.assertContainsRe(str(e), u'\u1234'.encode('utf-8'))
-        else:
-            self.fail('BzrError not raised')

=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py	2007-07-02 14:24:27 +0000
+++ b/bzrlib/tests/test_osutils.py	2007-08-21 05:08:31 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -29,10 +29,15 @@
     win32utils,
     )
 from bzrlib.errors import BzrBadParameterNotUnicode, InvalidURL
+from bzrlib.osutils import (
+        is_inside_any,
+        is_inside_or_parent_of_any,
+        pathjoin,
+        )
 from bzrlib.tests import (
         StringIOWrapper,
-        TestCase, 
-        TestCaseInTempDir, 
+        TestCase,
+        TestCaseInTempDir,
         TestSkipped,
         )
 
@@ -105,6 +110,31 @@
         self.assertFalse(is_inside('foo.c', ''))
         self.assertTrue(is_inside('', 'foo.c'))
 
+    def test_is_inside_any(self):
+        SRC_FOO_C = pathjoin('src', 'foo.c')
+        for dirs, fn in [(['src', 'doc'], SRC_FOO_C),
+                         (['src'], SRC_FOO_C),
+                         (['src'], 'src'),
+                         ]:
+            self.assert_(is_inside_any(dirs, fn))
+        for dirs, fn in [(['src'], 'srccontrol'),
+                         (['src'], 'srccontrol/foo')]:
+            self.assertFalse(is_inside_any(dirs, fn))
+
+    def test_is_inside_or_parent_of_any(self):
+        for dirs, fn in [(['src', 'doc'], 'src/foo.c'),
+                         (['src'], 'src/foo.c'),
+                         (['src/bar.c'], 'src'),
+                         (['src/bar.c', 'bla/foo.c'], 'src'),
+                         (['src'], 'src'),
+                         ]:
+            self.assert_(is_inside_or_parent_of_any(dirs, fn))
+            
+        for dirs, fn in [(['src'], 'srccontrol'),
+                         (['srccontrol/foo.c'], 'src'),
+                         (['src'], 'srccontrol/foo')]:
+            self.assertFalse(is_inside_or_parent_of_any(dirs, fn))
+
     def test_rmtree(self):
         # Check to remove tree with read-only files/dirs
         os.mkdir('dir')




More information about the bazaar-commits mailing list