~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-07-17 09:40:51 UTC
  • mfrom: (3518.1.2 virtualvf)
  • Revision ID: pqm@pqm.ubuntu.com-20080717094051-cgyo1zagozwcd4mm
(Jelmer) Add VirtualVersionedFiles class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    )
46
46
from bzrlib.symbol_versioning import one_four, one_five
47
47
from bzrlib.tests import (
 
48
    TestCase,
48
49
    TestCaseWithMemoryTransport,
49
50
    TestScenarioApplier,
50
51
    TestSkipped,
63
64
    ConstantMapper,
64
65
    HashEscapedPrefixMapper,
65
66
    PrefixMapper,
 
67
    VirtualVersionedFiles,
66
68
    make_versioned_files_factory,
67
69
    )
68
70
from bzrlib.weave import WeaveFile
2157
2159
            key = ('foo', 'bar',)
2158
2160
        files.add_lines(key, (), [])
2159
2161
        self.assertEqual(set([key]), set(files.keys()))
 
2162
 
 
2163
 
 
2164
class VirtualVersionedFilesTests(TestCase):
 
2165
    """Basic tests for the VirtualVersionedFiles implementations."""
 
2166
 
 
2167
    def _get_parent_map(self, keys):
 
2168
        ret = {}
 
2169
        for k in keys:
 
2170
            if k in self._parent_map:
 
2171
                ret[k] = self._parent_map[k]
 
2172
        return ret
 
2173
 
 
2174
    def setUp(self):
 
2175
        TestCase.setUp(self)
 
2176
        self._lines = {}
 
2177
        self._parent_map = {}
 
2178
        self.texts = VirtualVersionedFiles(self._get_parent_map, 
 
2179
                                           self._lines.get)
 
2180
 
 
2181
    def test_add_lines(self):
 
2182
        self.assertRaises(NotImplementedError, 
 
2183
                self.texts.add_lines, "foo", [], [])
 
2184
 
 
2185
    def test_add_mpdiffs(self):
 
2186
        self.assertRaises(NotImplementedError, 
 
2187
                self.texts.add_mpdiffs, [])
 
2188
 
 
2189
    def test_check(self):
 
2190
        self.assertTrue(self.texts.check())
 
2191
 
 
2192
    def test_insert_record_stream(self):
 
2193
        self.assertRaises(NotImplementedError, self.texts.insert_record_stream,
 
2194
                          [])
 
2195
 
 
2196
    def test_get_sha1s_nonexistent(self):
 
2197
        self.assertEquals({}, self.texts.get_sha1s([("NONEXISTENT",)]))
 
2198
 
 
2199
    def test_get_sha1s(self):
 
2200
        self._lines["key"] = ["dataline1", "dataline2"]
 
2201
        self.assertEquals({("key",): osutils.sha_strings(self._lines["key"])},
 
2202
                           self.texts.get_sha1s([("key",)]))
 
2203
 
 
2204
    def test_get_parent_map(self):
 
2205
        self._parent_map = {"G": ("A", "B")}
 
2206
        self.assertEquals({("G",): (("A",),("B",))}, 
 
2207
                          self.texts.get_parent_map([("G",), ("L",)]))
 
2208
 
 
2209
    def test_get_record_stream(self):
 
2210
        self._lines["A"] = ["FOO", "BAR"]
 
2211
        it = self.texts.get_record_stream([("A",)], "unordered", True)
 
2212
        record = it.next()
 
2213
        self.assertEquals("fulltext", record.storage_kind)
 
2214
        self.assertEquals("FOOBAR", record.get_bytes_as("fulltext"))
 
2215
 
 
2216
    def test_get_record_stream_absent(self):
 
2217
        it = self.texts.get_record_stream([("A",)], "unordered", True)
 
2218
        record = it.next()
 
2219
        self.assertEquals("absent", record.storage_kind)
 
2220