~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_inv.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-10 07:46:15 UTC
  • mfrom: (5844 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5845.
  • Revision ID: jelmer@samba.org-20110510074615-eptod049ndjxc4i7
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    InventoryDirectory,
35
35
    InventoryEntry,
36
36
    TreeReference,
 
37
    mutable_inventory_from_tree,
37
38
    )
38
39
from bzrlib.tests import (
39
40
    TestCase,
56
57
    # just creating trees.
57
58
    formats = set()
58
59
    for _, format in repository.format_registry.iteritems():
59
 
        scenarios.append((str(format.__name__), {
60
 
            'apply_delta':apply_inventory_Repository_add_inventory_by_delta,
61
 
            'format':format}))
 
60
        if format.supports_full_versioned_files:
 
61
            scenarios.append((str(format.__name__), {
 
62
                'apply_delta':apply_inventory_Repository_add_inventory_by_delta,
 
63
                'format':format}))
62
64
    for format in workingtree.format_registry._get_all():
 
65
        repo_fmt = format._matchingbzrdir.repository_format
 
66
        if not repo_fmt.supports_full_versioned_files:
 
67
            continue
63
68
        scenarios.append(
64
69
            (str(format.__class__.__name__) + ".update_basis_by_delta", {
65
70
            'apply_delta':apply_inventory_WT_basis,
79
84
            lines = []
80
85
        repo.texts.add_lines((ie.file_id, ie.revision), [], lines)
81
86
 
82
 
    
 
87
 
83
88
def apply_inventory_Inventory(self, basis, delta):
84
89
    """Apply delta to basis and return the result.
85
90
    
650
655
 
651
656
    def test_file_has_text(self):
652
657
        file = inventory.InventoryFile('123', 'hello.c', ROOT_ID)
653
 
        self.failUnless(file.has_text())
 
658
        self.assertTrue(file.has_text())
654
659
 
655
660
    def test_directory_has_text(self):
656
661
        dir = inventory.InventoryDirectory('123', 'hello.c', ROOT_ID)
657
 
        self.failIf(dir.has_text())
 
662
        self.assertFalse(dir.has_text())
658
663
 
659
664
    def test_link_has_text(self):
660
665
        link = inventory.InventoryLink('123', 'hello.c', ROOT_ID)
661
 
        self.failIf(link.has_text())
 
666
        self.assertFalse(link.has_text())
662
667
 
663
668
    def test_make_entry(self):
664
669
        self.assertIsInstance(inventory.make_entry("file", "name", ROOT_ID),
1219
1224
        self.assertEqual(('tree\xce\xa9name', 'tree-root-id', 'tree-rev-id'),
1220
1225
                         inv._bytes_to_utf8name_key(bytes))
1221
1226
 
 
1227
    def make_basic_utf8_inventory(self):
 
1228
        inv = Inventory()
 
1229
        inv.revision_id = "revid"
 
1230
        inv.root.revision = "rootrev"
 
1231
        root_id = inv.root.file_id
 
1232
        inv.add(InventoryFile("fileid", u'f\xefle', root_id))
 
1233
        inv["fileid"].revision = "filerev"
 
1234
        inv["fileid"].text_sha1 = "ffff"
 
1235
        inv["fileid"].text_size = 0
 
1236
        inv.add(InventoryDirectory("dirid", u'dir-\N{EURO SIGN}', root_id))
 
1237
        inv.add(InventoryFile("childid", u'ch\xefld', "dirid"))
 
1238
        inv["childid"].revision = "filerev"
 
1239
        inv["childid"].text_sha1 = "ffff"
 
1240
        inv["childid"].text_size = 0
 
1241
        chk_bytes = self.get_chk_bytes()
 
1242
        chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
 
1243
        bytes = ''.join(chk_inv.to_lines())
 
1244
        return CHKInventory.deserialise(chk_bytes, bytes, ("revid",))
 
1245
 
 
1246
    def test__preload_handles_utf8(self):
 
1247
        new_inv = self.make_basic_utf8_inventory()
 
1248
        self.assertEqual({}, new_inv._fileid_to_entry_cache)
 
1249
        self.assertFalse(new_inv._fully_cached)
 
1250
        new_inv._preload_cache()
 
1251
        self.assertEqual(
 
1252
            sorted([new_inv.root_id, "fileid", "dirid", "childid"]),
 
1253
            sorted(new_inv._fileid_to_entry_cache.keys()))
 
1254
        ie_root = new_inv._fileid_to_entry_cache[new_inv.root_id]
 
1255
        self.assertEqual([u'dir-\N{EURO SIGN}', u'f\xefle'],
 
1256
                         sorted(ie_root._children.keys()))
 
1257
        ie_dir = new_inv._fileid_to_entry_cache['dirid']
 
1258
        self.assertEqual([u'ch\xefld'], sorted(ie_dir._children.keys()))
 
1259
 
 
1260
    def test__preload_populates_cache(self):
 
1261
        inv = Inventory()
 
1262
        inv.revision_id = "revid"
 
1263
        inv.root.revision = "rootrev"
 
1264
        root_id = inv.root.file_id
 
1265
        inv.add(InventoryFile("fileid", "file", root_id))
 
1266
        inv["fileid"].revision = "filerev"
 
1267
        inv["fileid"].executable = True
 
1268
        inv["fileid"].text_sha1 = "ffff"
 
1269
        inv["fileid"].text_size = 1
 
1270
        inv.add(InventoryDirectory("dirid", "dir", root_id))
 
1271
        inv.add(InventoryFile("childid", "child", "dirid"))
 
1272
        inv["childid"].revision = "filerev"
 
1273
        inv["childid"].executable = False
 
1274
        inv["childid"].text_sha1 = "dddd"
 
1275
        inv["childid"].text_size = 1
 
1276
        chk_bytes = self.get_chk_bytes()
 
1277
        chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
 
1278
        bytes = ''.join(chk_inv.to_lines())
 
1279
        new_inv = CHKInventory.deserialise(chk_bytes, bytes, ("revid",))
 
1280
        self.assertEqual({}, new_inv._fileid_to_entry_cache)
 
1281
        self.assertFalse(new_inv._fully_cached)
 
1282
        new_inv._preload_cache()
 
1283
        self.assertEqual(
 
1284
            sorted([root_id, "fileid", "dirid", "childid"]),
 
1285
            sorted(new_inv._fileid_to_entry_cache.keys()))
 
1286
        self.assertTrue(new_inv._fully_cached)
 
1287
        ie_root = new_inv._fileid_to_entry_cache[root_id]
 
1288
        self.assertEqual(['dir', 'file'], sorted(ie_root._children.keys()))
 
1289
        ie_dir = new_inv._fileid_to_entry_cache['dirid']
 
1290
        self.assertEqual(['child'], sorted(ie_dir._children.keys()))
 
1291
 
 
1292
    def test__preload_handles_partially_evaluated_inventory(self):
 
1293
        new_inv = self.make_basic_utf8_inventory()
 
1294
        ie = new_inv[new_inv.root_id]
 
1295
        self.assertIs(None, ie._children)
 
1296
        self.assertEqual([u'dir-\N{EURO SIGN}', u'f\xefle'],
 
1297
                         sorted(ie.children.keys()))
 
1298
        # Accessing .children loads _children
 
1299
        self.assertEqual([u'dir-\N{EURO SIGN}', u'f\xefle'],
 
1300
                         sorted(ie._children.keys()))
 
1301
        new_inv._preload_cache()
 
1302
        # No change
 
1303
        self.assertEqual([u'dir-\N{EURO SIGN}', u'f\xefle'],
 
1304
                         sorted(ie._children.keys()))
 
1305
        ie_dir = new_inv["dirid"]
 
1306
        self.assertEqual([u'ch\xefld'],
 
1307
                         sorted(ie_dir._children.keys()))
 
1308
 
1222
1309
 
1223
1310
class TestCHKInventoryExpand(tests.TestCaseWithMemoryTransport):
1224
1311
 
1350
1437
        inv = self.make_simple_inventory()
1351
1438
        self.assertExpand(['TREE_ROOT', 'dir1-id', 'sub-dir1-id', 'top-id',
1352
1439
                           'subsub-file1-id'], inv, ['top-id', 'subsub-file1-id'])
 
1440
 
 
1441
 
 
1442
class TestMutableInventoryFromTree(TestCaseWithTransport):
 
1443
 
 
1444
    def test_empty(self):
 
1445
        repository = self.make_repository('.')
 
1446
        tree = repository.revision_tree(revision.NULL_REVISION)
 
1447
        inv = mutable_inventory_from_tree(tree)
 
1448
        self.assertEquals(revision.NULL_REVISION, inv.revision_id)
 
1449
        self.assertEquals(0, len(inv))
 
1450
 
 
1451
    def test_some_files(self):
 
1452
        wt = self.make_branch_and_tree('.')
 
1453
        self.build_tree(['a'])
 
1454
        wt.add(['a'], ['thefileid'])
 
1455
        revid = wt.commit("commit")
 
1456
        tree = wt.branch.repository.revision_tree(revid)
 
1457
        inv = mutable_inventory_from_tree(tree)
 
1458
        self.assertEquals(revid, inv.revision_id)
 
1459
        self.assertEquals(2, len(inv))
 
1460
        self.assertEquals("a", inv['thefileid'].name)
 
1461
        # The inventory should be mutable and independent of
 
1462
        # the original tree
 
1463
        self.assertFalse(tree.inventory['thefileid'].executable)
 
1464
        inv['thefileid'].executable = True
 
1465
        self.assertFalse(tree.inventory['thefileid'].executable)