Rev 1893: Add more mapping tests. in file:///data/jelmer/bzr-svn/trunk/

Jelmer Vernooij jelmer at samba.org
Tue Sep 9 17:41:43 BST 2008


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

------------------------------------------------------------
revno: 1893
revision-id: jelmer at samba.org-20080909164141-o9mbxtrh5k88dff7
parent: jelmer at samba.org-20080909162126-x0y1g097i0yrn8wf
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Tue 2008-09-09 18:41:41 +0200
message:
  Add more mapping tests.
modified:
  mapping.py                     mapping.py-20080128201303-6cp01phc0dmc0kiv-1
  tests/test_mapping.py          test_mapping.py-20080201131338-0zd86eznn4bojtee-1
=== modified file 'mapping.py'
--- a/mapping.py	2008-09-09 13:36:52 +0000
+++ b/mapping.py	2008-09-09 16:41:41 +0000
@@ -725,7 +725,14 @@
                                'Fourth format (bzr-svn 0.5.x)')
 mapping_registry.set_default('v3')
 
+
 def find_mapping(revprops, fileprops):
+    """Find a mapping instance based on the revprops and fileprops set on a revision.
+
+    :param revprops: Revision properties.
+    :param fileprops: File properties set on branch root.
+    :return: BzrSvnMapping instance or None if no mapping found.
+    """
     if SVN_REVPROP_BZR_MAPPING_VERSION in revprops:
         try:
             cls = mapping_registry.get(revprops[SVN_REVPROP_BZR_MAPPING_VERSION])
@@ -759,6 +766,9 @@
 
 
 def estimate_bzr_ancestors(fileprops):
+    """Estimate the number of bzr ancestors that a revision has based on file properties.
+
+    """
     found = []
     for k, v in fileprops.items():
         if k.startswith(SVN_PROP_BZR_REVISION_ID):

=== modified file 'tests/test_mapping.py'
--- a/tests/test_mapping.py	2008-09-09 13:36:52 +0000
+++ b/tests/test_mapping.py	2008-09-09 16:41:41 +0000
@@ -21,11 +21,13 @@
 from bzrlib.tests import TestCase, TestNotApplicable
 from bzrlib.revision import Revision
 
+from bzrlib.plugins.svn import mapping
 from bzrlib.plugins.svn.errors import InvalidPropertyValue
 from bzrlib.plugins.svn.mapping import (generate_revision_metadata, parse_revision_metadata, 
                      parse_revid_property, parse_merge_property, parse_text_parents_property,
-                     generate_text_parents_property, 
-                     escape_svn_path, unescape_svn_path)
+                     generate_text_parents_property, estimate_bzr_ancestors,
+                     escape_svn_path, unescape_svn_path, is_bzr_revision_fileprops,
+                     get_roundtrip_ancestor_revids)
 from bzrlib.plugins.svn.mapping2 import BzrSvnMappingv1, BzrSvnMappingv2
 from bzrlib.plugins.svn.mapping3 import BzrSvnMappingv3FileProps
 from bzrlib.plugins.svn.mapping4 import BzrSvnMappingv4
@@ -206,3 +208,52 @@
 
     def test_escape_svn_path_nordic(self):
         self.assertEqual("foobar%C3%A6", escape_svn_path(u"foobar\xe6".encode("utf-8")))
+
+
+class EstimateBzrAncestorsTests(TestCase):
+
+    def test_no_fileprops(self):
+        self.assertEquals(0, estimate_bzr_ancestors({}))
+
+    def test_one(self):
+        self.assertEquals(2, estimate_bzr_ancestors({"bzr:revision-id:v42": "bla\nblie\n"}))
+
+    def test_multiple(self):
+        self.assertEquals(2, estimate_bzr_ancestors({"bzr:revision-id:v42": "bla\n", 
+            "bzr:revision-id:v50": "blie\nblie\n"}))
+
+
+class IsBzrRevisionTests(TestCase):
+
+    def test_no_fileprops(self):
+        self.assertEquals(None, is_bzr_revision_fileprops({}))
+
+    def test_fileprops(self):
+        self.assertEquals(True, is_bzr_revision_fileprops({"bzr:bla": "bloe"}))
+
+    def test_revprops(self):
+        self.assertEquals(True, is_bzr_revision_revprops({mapping.SVN_REVPROP_BZR_MAPPING_VERSION: "42"}))
+
+    def test_revprops_no(self):
+        self.assertEquals(False, is_bzr_revision_revprops({mapping.SVN_REVPROP_BZR_SKIP: ""}))
+
+    def test_revprops_unknown(self):
+        self.assertEquals(None, is_bzr_revision_revprops({}))
+
+
+class RoundTripAncestorRevids(TestCase):
+    
+    def test_none(self):
+        self.assertEquals([], list(get_roundtrip_ancestor_revids({})))
+
+    def test_simple(self):
+        self.assertEquals([("arevid", 42, "v42-scheme")], 
+                list(get_roundtrip_ancestor_revids({mapping.SVN_PROP_BZR_REVISION_ID+"v42-scheme": "42 arevid\n"})))
+
+    def test_multiple(self):
+        self.assertEquals(set([("arevid", 42, "v42-scheme"), ("brevid", 50, "v90-ll")]), 
+                set(get_roundtrip_ancestor_revids({
+                    mapping.SVN_PROP_BZR_REVISION_ID+"v42-scheme": "42 arevid\n",
+                    mapping.SVN_PROP_BZR_REVISION_ID+"v90-ll": "50 brevid\n",
+                    "otherrevprop": "fsldds",
+                    })))




More information about the bazaar-commits mailing list