Rev 447: Add some more tests. in file:///data/jelmer/bzr-svn/nestedtrees/

Jelmer Vernooij jelmer at samba.org
Sat Jul 21 13:38:55 BST 2007


At file:///data/jelmer/bzr-svn/nestedtrees/

------------------------------------------------------------
revno: 447
revision-id: jelmer at samba.org-20070721123854-3h53w2qyfm6u3vqj
parent: jelmer at samba.org-20070721114455-tmlzl4xkxuiqp4ve
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: nestedtrees
timestamp: Sat 2007-07-21 14:38:54 +0200
message:
  Add some more tests.
modified:
  TODO                           todo-20060729211917-2kpobww0zyvvo0j2-1
  tests/test_fetch.py            test_fetch.py-20070624210302-luvgwjmlfysk5qeq-1
  tests/test_tree.py             test_tree.py-20070103204350-pr8nupes7e5sd2wr-1
  tree.py                        tree.py-20060624222557-dudlwqcmkf22lt2s-1
=== modified file 'TODO'
--- a/TODO	2007-07-21 01:24:13 +0000
+++ b/TODO	2007-07-21 12:38:54 +0000
@@ -3,7 +3,6 @@
 - integrate bzr:merge into bzr:revision-info or rename to bzr:merge-vXXYY
 - fix setting of bzr:file-ids property
 - splittree support
-- nestedtree support
 
 todo:
 - BzrDir.create_branch() should set the revision id to NULL_REVISION

=== modified file 'tests/test_fetch.py'
--- a/tests/test_fetch.py	2007-07-21 11:44:55 +0000
+++ b/tests/test_fetch.py	2007-07-21 12:38:54 +0000
@@ -55,27 +55,6 @@
         newrepos = dir.create_repository()
         oldrepos.copy_content_into(newrepos)
 
-    def test_fetch_externals(self):
-        repos_url1 = self.make_client('d1', 'dc1')
-        self.build_tree({'dc1/proj1/trunk/file': "data"})
-        self.client_add("dc1/proj1")
-        self.client_commit("dc1", "My Message")
-
-        repos_url2 = self.make_client('d2', 'dc2')
-        self.build_tree({'dc2/somedir': None})
-        self.client_add("dc2/somedir")
-        self.client_set_prop("dc2/somedir", "svn:externals", 
-                str("bla\t%s/proj1/trunk\n" % repos_url1))
-        self.client_commit("dc2", "My Message")
-
-        oldrepos = Repository.open(repos_url2)
-        from bzrlib.repofmt.knitrepo import RepositoryFormatKnit3
-        newrepos = RepositoryFormatKnit3().initialize(BzrDir.create("f"))
-        oldrepos.copy_content_into(newrepos)
-        inv = oldrepos.get_inventory(oldrepos.generate_revision_id(1, "", "none"))
-        self.assertTrue(inv.has_filename("somedir/bla"))
-        self.assertEqual(inv.path2id("somedir/bla"), Branch.open("%s/proj1/trunk" % repos_url1).get_root_id())
-
     def test_fetch_special_char(self):
         repos_url = self.make_client('d', 'dc')
         self.build_tree({u'dc/trunk/f\x2cle': "data"})
@@ -1416,3 +1395,34 @@
                          inventory[inventory.path2id("bdir/stationary")].revision)
 
 
+class TestNestedTrees(TestCaseWithSubversionRepository):
+    def setUp(self):
+        super(TestNestedTrees, self).setUp()
+        self.repos_url1 = self.make_client('d1', 'dc1')
+        self.build_tree({'dc1/proj1/trunk/file': "data"})
+        self.client_add("dc1/proj1")
+        self.client_commit("dc1", "My Message")
+
+        self.repos_url2 = self.make_client('d2', 'dc2')
+
+    def test_simple_externals(self):
+        self.build_tree({'dc2/somedir': None})
+        self.client_add("dc2/somedir")
+        self.client_set_prop("dc2/somedir", "svn:externals", 
+                str("bla\t%s/proj1/trunk\n" % self.repos_url1))
+        self.client_commit("dc2", "My Message")
+
+        oldrepos = Repository.open(self.repos_url2)
+        newdir = BzrDir.create("f", format=format.get_rich_root_format())
+        newrepos = newdir.create_repository()
+        oldrepos.copy_content_into(newrepos)
+        inv = oldrepos.get_inventory(
+                oldrepos.generate_revision_id(1, "", "none"))
+        self.assertTrue(inv.has_filename("somedir/bla"))
+        self.assertEqual(inv.path2id("somedir/bla"), 
+            Branch.open("%s/proj1/trunk" % self.repos_url1).get_root_id())
+        self.assertEqual(None, 
+                inv[inv.path2id("somedir/bla")].reference_revision)
+        self.assertEqual(oldrepos.generate_revision_id(1, "", "none"), 
+                inv[inv.path2id("somedir/bla")].revision)
+

=== modified file 'tests/test_tree.py'
--- a/tests/test_tree.py	2007-07-21 11:43:32 +0000
+++ b/tests/test_tree.py	2007-07-21 12:38:54 +0000
@@ -20,7 +20,9 @@
 from bzrlib.tests import TestCase
 from bzrlib.workingtree import WorkingTree
 
+import errors
 from fileids import generate_svn_file_id
+import os
 from revids import generate_svn_revision_id
 from tree import (SvnBasisTree, parse_externals_description, 
                   inventory_add_external)
@@ -48,7 +50,6 @@
 
     def test_symlink(self):
         self.make_client("d", "dc")
-        import os
         os.symlink("target", "dc/file")
         self.build_tree({"dc/file": "x"})
         self.client_add("dc/file")
@@ -76,7 +77,6 @@
 
     def test_symlink_next(self):
         self.make_client("d", "dc")
-        import os
         os.symlink("target", "dc/file")
         self.build_tree({"dc/file": "x", "dc/bla": "p"})
         self.client_add("dc/file")
@@ -93,7 +93,6 @@
 
     def test_executable_link(self):
         self.make_client("d", "dc")
-        import os
         os.symlink("target", "dc/file")
         self.build_tree({"dc/file": "x"})
         self.client_add("dc/file")
@@ -108,9 +107,9 @@
 class TestExternalsParser(TestCase):
     def test_parse_externals(self):
         self.assertEqual({
-                'third-party/sounds': (None, "http://sounds.red-bean.com/repos"),
-                'third-party/skins': (None, "http://skins.red-bean.com/repositories/skinproj"),
-                'third-party/skins/toolkit': (21, "http://svn.red-bean.com/repos/skin-maker")},
+            'third-party/sounds': (None, "http://sounds.red-bean.com/repos"),
+            'third-party/skins': (None, "http://skins.red-bean.com/repositories/skinproj"),
+            'third-party/skins/toolkit': (21, "http://svn.red-bean.com/repos/skin-maker")},
             parse_externals_description(
 """third-party/sounds             http://sounds.red-bean.com/repos
 third-party/skins              http://skins.red-bean.com/repositories/skinproj
@@ -127,34 +126,60 @@
 #third-party/skins              http://skins.red-bean.com/repositories/skinproj
 #third-party/skins/toolkit -r21 http://svn.red-bean.com/repos/skin-maker"""))
 
+    def test_parse_invalid_missing_url(self):
+        """No URL specified."""
+        self.assertRaises(errors.InvalidExternalsDescription, 
+                lambda: parse_externals_description("bla"))
+            
+    def test_parse_invalid_too_much_data(self):
+        """No URL specified."""
+        self.assertRaises(errors.InvalidExternalsDescription, 
+                lambda: parse_externals_description("bla -R40 http://bla/"))
+ 
+
 class TestInventoryExternals(TestCaseWithSubversionRepository):
     def test_add_nested_norev(self):
+        """Add a nested tree with no specific revision referenced."""
         repos_url = self.make_client('d', 'dc')
         repos = Repository.open(repos_url)
         inv = Inventory(root_id='blabloe')
-        inventory_add_external(inv, 'blabloe', 'blie/bla', generate_svn_revision_id(repos.uuid, 1, "", "none"), 
-                               None, repos_url)
-        self.assertEqual(TreeReference(generate_svn_file_id(repos.uuid, 0, "", ""),
-             'bla', inv.path2id('blie'), revision=generate_svn_revision_id(repos.uuid, 1, "", "none")), 
+        inventory_add_external(inv, 'blabloe', 'blie/bla', 
+                generate_svn_revision_id(repos.uuid, 1, "", "none"), 
+                None, repos_url)
+        self.assertEqual(TreeReference(
+            generate_svn_file_id(repos.uuid, 0, "", ""),
+             'bla', inv.path2id('blie'), 
+             revision=generate_svn_revision_id(repos.uuid, 1, "", "none")), 
              inv[inv.path2id('blie/bla')])
 
     def test_add_simple_norev(self):
         repos_url = self.make_client('d', 'dc')
         repos = Repository.open(repos_url)
         inv = Inventory(root_id='blabloe')
-        inventory_add_external(inv, 'blabloe', 'bla', generate_svn_revision_id(repos.uuid, 1, "", "none"), None, repos_url)
-        self.assertEqual(TreeReference(generate_svn_file_id(repos.uuid, 0, "", ""),
-             'bla', 'blabloe', revision=generate_svn_revision_id(repos.uuid, 1, "", "none")), inv[inv.path2id('bla')])
+        inventory_add_external(inv, 'blabloe', 'bla', 
+            generate_svn_revision_id(repos.uuid, 1, "", "none"), None, 
+            repos_url)
+
+        self.assertEqual(TreeReference(
+            generate_svn_file_id(repos.uuid, 0, "", ""),
+             'bla', 'blabloe', 
+             revision=generate_svn_revision_id(repos.uuid, 1, "", "none")), 
+             inv[inv.path2id('bla')])
 
     def test_add_simple_rev(self):
         repos_url = self.make_client('d', 'dc')
         repos = Repository.open(repos_url)
         inv = Inventory(root_id='blabloe')
-        inventory_add_external(inv, 'blabloe', 'bla', generate_svn_revision_id(repos.uuid, 1, "", "none"), 0, repos_url)
-        self.assertEqual(TreeReference(generate_svn_file_id(repos.uuid, 0, "", ""),
-             'bla', 'blabloe', revision=generate_svn_revision_id(repos.uuid, 1, "", "none"),
-             reference_revision=generate_svn_revision_id(repos.uuid, 0, "", "none")
+        inventory_add_external(inv, 'blabloe', 'bla', 
+            generate_svn_revision_id(repos.uuid, 1, "", "none"), 0, repos_url)
+        self.assertEqual(
+            TreeReference(generate_svn_file_id(repos.uuid, 0, "", ""),
+            'bla', 'blabloe', 
+            revision=generate_svn_revision_id(repos.uuid, 1, "", "none"),
+            reference_revision=generate_svn_revision_id(repos.uuid, 0, "", "none")
              ), inv[inv.path2id('bla')])
         ie = inv[inv.path2id('bla')]
-        self.assertEqual(generate_svn_revision_id(repos.uuid, 0, "", "none"), ie.reference_revision)
-        self.assertEqual(generate_svn_revision_id(repos.uuid, 1, "", "none"), ie.revision)
+        self.assertEqual(generate_svn_revision_id(repos.uuid, 0, "", "none"), 
+                         ie.reference_revision)
+        self.assertEqual(generate_svn_revision_id(repos.uuid, 1, "", "none"), 
+                         ie.revision)

=== modified file 'tree.py'
--- a/tree.py	2007-07-21 11:44:55 +0000
+++ b/tree.py	2007-07-21 12:38:54 +0000
@@ -30,7 +30,7 @@
 import svn.core, svn.wc, svn.delta
 from svn.core import Pool
 
-from errors import InvalidExternalsDescription
+import errors
 
 def parse_externals_description(val):
     """Parse an svn:externals property value.
@@ -45,12 +45,13 @@
             continue
         pts = l.rsplit(None, 2) 
         if len(pts) == 3:
-            assert pts[1].startswith("-r")
+            if not pts[1].startswith("-r"):
+                raise errors.InvalidExternalsDescription()
             ret[pts[0]] = (int(pts[1][2:]), pts[2])
         elif len(pts) == 2:
             ret[pts[0]] = (None, pts[1])
         else:
-            raise InvalidExternalsDescription
+            raise errors.InvalidExternalsDescription()
     return ret
 
 
@@ -61,8 +62,8 @@
     :param parent_id: File id of directory the entry was set on.
     :param path: Path of the entry, relative to entry with parent_id.
     :param revid: Revision to store in newly created inventory entries.
-    :param ref_revnum: Referenced revision of tree that's being referenced, or None if no 
-                specific revision is being referenced.
+    :param ref_revnum: Referenced revision of tree that's being referenced, or 
+        None if no specific revision is being referenced.
     :param url: URL of referenced tree.
     """
     assert ref_revnum is None or isinstance(ref_revnum, int)
@@ -84,7 +85,8 @@
     file_id = reference_branch.get_root_id()
     ie = TreeReference(file_id, name, parent.file_id, revision=revid)
     if ref_revnum is not None:
-        ie.reference_revision = reference_branch.generate_revision_id(ref_revnum)
+        ie.reference_revision = reference_branch.generate_revision_id(
+            ref_revnum)
     inv.add(ie)
 
 
@@ -120,7 +122,8 @@
         self._repository = repository
         self._revision_id = revision_id
         pool = Pool()
-        (self.branch_path, self.revnum, scheme) = repository.lookup_revision_id(revision_id)
+        (self.branch_path, self.revnum, 
+            scheme) = repository.lookup_revision_id(revision_id)
         self._inventory = Inventory()
         self.id_map = repository.get_fileid_map(self.revnum, self.branch_path, 
                                                 scheme)
@@ -211,7 +214,7 @@
         elif name == svn.core.SVN_PROP_SPECIAL:
             self.is_symlink = (value != None)
         elif name == svn.core.SVN_PROP_EXTERNALS:
-            mutter('svn:externals property on file!')
+            mutter('%r property on file!' % name)
         elif name == svn.core.SVN_PROP_ENTRY_COMMITTED_REV:
             self.last_file_rev = int(value)
         elif name in (svn.core.SVN_PROP_ENTRY_COMMITTED_DATE,
@@ -240,7 +243,8 @@
             # Add externals. This happens after all children have been added
             # as they can be grandchildren.
             for (name, (rev, url)) in self.externals[id].items():
-                inventory_add_external(self.tree._inventory, id, name, None, rev, url)
+                inventory_add_external(self.tree._inventory, id, name, None, 
+                                       rev, url)
 
     def close_file(self, path, checksum):
         file_id, revision_id = self.tree.id_map[path]
@@ -365,8 +369,9 @@
             props = {}
             if props.has_key(svn.core.SVN_PROP_EXTERNALS):
                 for (name, (rev, url)) in \
-                        parse_externals_description(props[svn.core.SVN_PROP_EXTERNALS]).items():
-                    inventory_add_external(self._inventory, id, name, None, rev, url)
+                    parse_externals_description(props[svn.core.SVN_PROP_EXTERNALS]).items():
+                    inventory_add_external(self._inventory, id, name, None, 
+                                           rev, url)
 
         wc = workingtree._get_wc() 
         try:




More information about the bazaar-commits mailing list