Rev 1385: Implement get_record_stream in FakeVersionedFiles. in file:///data/jelmer/bzr-svn/stackable/

Jelmer Vernooij jelmer at samba.org
Fri Jun 27 22:54:53 BST 2008


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

------------------------------------------------------------
revno: 1385
revision-id: jelmer at samba.org-20080627215452-m3wc33d8hrytynab
parent: jelmer at samba.org-20080627211327-60tdygznt0nz17cz
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: stackable
timestamp: Fri 2008-06-27 23:54:52 +0200
message:
  Implement get_record_stream in FakeVersionedFiles.
modified:
  tests/test_versionedfiles.py   test_versionedfiles.-20080626153242-v0c6uolklpux67a1-1
  versionedfiles.py              versionedfiles.py-20080626134117-j8g0ntz1pj228iox-1
=== modified file 'tests/test_versionedfiles.py'
--- a/tests/test_versionedfiles.py	2008-06-27 21:13:27 +0000
+++ b/tests/test_versionedfiles.py	2008-06-27 21:54:52 +0000
@@ -13,11 +13,13 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from bzrlib import osutils
 from bzrlib.graph import DictParentsProvider
 from bzrlib.tests import TestCase
 
 from bzrlib.plugins.svn.versionedfiles import (SvnTexts, FakeRevisionTexts, 
-                                               FakeInventoryTexts, FakeSignatureTexts)
+                                               FakeInventoryTexts, FakeSignatureTexts,
+                                               FakeVersionedFiles)
 
 
 class BasicSvnTextsTests:
@@ -42,26 +44,61 @@
         self.texts = SvnTexts()
 
 
-class FakeTextsTests(BasicSvnTextsTests):
+class FakeTextsTests(TestCase,BasicSvnTextsTests):
     def get_parent_map(self, keys):
         return DictParentsProvider(self.parent_map).get_parent_map(keys)
 
+    def get_lines(self, key):
+        (k,) = key
+        if not k in self.lines:
+            return None
+        return self.lines[k]
+
     def test_get_parent_map(self):
         self.parent_map = {"G": ("A", "B")}
         self.assertEquals({("G",): (("A",),("B",))}, self.texts.get_parent_map([("G",)]))
 
-
-class FakeRevisionTextsTests(TestCase,FakeTextsTests):
-    def setUp(self):
-        self.texts = FakeRevisionTexts(self.get_parent_map)
-
-
-class FakeInventoryTextsTests(TestCase,FakeTextsTests):
-    def setUp(self):
-        self.texts = FakeInventoryTexts(self.get_parent_map)
-
-
-class FakeSignatureTextsTests(TestCase,FakeTextsTests):
-    def setUp(self):
-        self.texts = FakeSignatureTexts(self.get_parent_map)
+    def test_get_sha1s(self):
+        self.lines = {"A": ["FOO"]}
+        self.assertEquals({("A",): osutils.sha_strings(["FOO"])}, 
+                self.texts.get_sha1s([("A",), ("B",)]))
+
+    def test_get_record_stream(self):
+        self.lines = {"A": ["FOO"]}
+        it = self.texts.get_record_stream([("A",)], "unordered", True)
+        record = it.next()
+        self.assertEquals("FOO", record.get_bytes_as("fulltext"))
+
+    def setUp(self):
+        self.texts = FakeVersionedFiles(self.get_parent_map, self.get_lines)
+
+
+class FakeRevisionTextsTests(TestCase,BasicSvnTextsTests):
+    def setUp(self):
+        self.texts = FakeRevisionTexts(self)
+
+    def get_parent_map(self, keys):
+        raise NotImplementedError
+
+
+class FakeInventoryTextsTests(TestCase,BasicSvnTextsTests):
+    def get_inventory_xml(self):
+        return "FOO"
+
+    def get_parent_map(self, keys):
+        return {("A",): (("B",))}
+
+    def setUp(self):
+        self.texts = FakeInventoryTexts(self)
+
+    def test_get_sha1s(self):
+        self.assertEquals({("A",): osutils.sha_strings(["FOO"])}, self.texts.get_sha1s([("A",)]))
+
+
+class FakeSignatureTextsTests(TestCase,BasicSvnTextsTests):
+    def setUp(self):
+        self.texts = FakeSignatureTexts(self)
+
+    def get_parent_map(self, keys):
+        raise NotImplementedError
 

=== modified file 'versionedfiles.py'
--- a/versionedfiles.py	2008-06-27 21:13:27 +0000
+++ b/versionedfiles.py	2008-06-27 21:54:52 +0000
@@ -13,7 +13,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-from bzrlib.versionedfile import VersionedFiles
+from bzrlib import osutils
+from bzrlib.versionedfile import FulltextContentFactory, VersionedFiles
 
 class SvnTexts(VersionedFiles):
     """Subversion texts backend."""
@@ -21,38 +22,81 @@
     def check(self, progressbar=None):
         return True
 
+    def add_mpdiffs(self, records):
+        raise NotImplementedError(self.add_mpdiffs)
+
     # TODO: annotate, get_parent_map, get_record_stream, get_sha1s, 
     # iter_lines_added_or_present_in_keys, keys
 
 
 class FakeVersionedFiles(VersionedFiles):
-    def __init__(self, get_parent_map):
+    def __init__(self, get_parent_map, get_lines):
         self._get_parent_map = get_parent_map
+        self._get_lines = get_lines
         
     def check(self, progressbar=None):
         return True
 
+    def add_mpdiffs(self, records):
+        raise NotImplementedError(self.add_mpdiffs)
+
     def get_parent_map(self, keys):
         return dict([((k,), tuple([(p,) for p in v])) for k,v in self._get_parent_map([k for (k,) in keys]).iteritems()])
 
+    def get_sha1s(self, keys):
+        ret = {}
+        for (k,) in keys:
+            lines = self._get_lines(k)
+            if lines is not None:
+                assert isinstance(lines, list)
+                ret[(k,)] = osutils.sha_strings(lines)
+        return ret
+
+    def get_record_stream(self, keys, ordering, include_delta_closure):
+        for (k,) in keys:
+            lines = self._get_lines(k)
+            if lines is not None:
+                assert isinstance(lines, list)
+                yield FulltextContentFactory((k,), None, 
+                        sha1=osutils.sha_strings(lines),
+                        text=''.join(lines))
+
 
 class FakeRevisionTexts(FakeVersionedFiles):
     """Fake revisions backend."""
-
-    # TODO: annotate, get_record_stream, get_sha1s, 
+    def __init__(self, repository):
+        self.repository = repository
+        super(FakeRevisionTexts, self).__init__(self.repository.get_parent_map, self.get_lines)
+
+    def get_lines(self, key):
+        return None
+
+    # TODO: annotate, get_record_stream, 
     # iter_lines_added_or_present_in_keys, keys
 
 
 class FakeInventoryTexts(FakeVersionedFiles):
     """Fake inventories backend."""
-
-    # TODO: annotate, get_record_stream, get_sha1s, 
+    def __init__(self, repository):
+        self.repository = repository
+        super(FakeInventoryTexts, self).__init__(self.repository.get_parent_map, self.get_lines)
+
+    def get_lines(self, key):
+        return osutils.split_lines(self.repository.get_inventory_xml(key))
+
+    # TODO: annotate, get_record_stream,
     # iter_lines_added_or_present_in_keys, keys
 
 
 class FakeSignatureTexts(FakeVersionedFiles):
     """Fake signatures backend."""
-
-    # TODO: annotate, get_record_stream, get_sha1s, 
+    def __init__(self, repository):
+        self.repository = repository
+        super(FakeSignatureTexts, self).__init__(self.repository.get_parent_map, self.get_lines)
+
+    def get_lines(self, key):
+        return None
+
+    # TODO: annotate, get_record_stream, 
     # iter_lines_added_or_present_in_keys, keys
 




More information about the bazaar-commits mailing list