29
from bzrlib.inventory import (
37
mutable_inventory_from_tree,
28
from bzrlib.inventory import (CHKInventory, Inventory, ROOT_ID, InventoryFile,
29
InventoryDirectory, InventoryEntry, TreeReference)
39
30
from bzrlib.tests import (
41
32
TestCaseWithTransport,
35
split_suite_by_condition,
43
from bzrlib.tests.scenarios import load_tests_apply_scenarios
46
load_tests = load_tests_apply_scenarios
49
def delta_application_scenarios():
37
from bzrlib.tests.per_workingtree import workingtree_formats
40
def load_tests(standard_tests, module, loader):
41
"""Parameterise some inventory tests."""
42
to_adapt, result = split_suite_by_condition(standard_tests,
43
condition_isinstance(TestDeltaApplication))
51
45
('Inventory', {'apply_delta':apply_inventory_Inventory}),
57
51
# just creating trees.
59
53
for _, format in repository.format_registry.iteritems():
60
if format.supports_full_versioned_files:
61
scenarios.append((str(format.__name__), {
62
'apply_delta':apply_inventory_Repository_add_inventory_by_delta,
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:
54
scenarios.append((str(format.__name__), {
55
'apply_delta':apply_inventory_Repository_add_inventory_by_delta,
57
for format in workingtree_formats():
69
59
(str(format.__class__.__name__) + ".update_basis_by_delta", {
70
60
'apply_delta':apply_inventory_WT_basis,
656
643
def test_file_has_text(self):
657
644
file = inventory.InventoryFile('123', 'hello.c', ROOT_ID)
658
self.assertTrue(file.has_text())
645
self.failUnless(file.has_text())
660
647
def test_directory_has_text(self):
661
648
dir = inventory.InventoryDirectory('123', 'hello.c', ROOT_ID)
662
self.assertFalse(dir.has_text())
649
self.failIf(dir.has_text())
664
651
def test_link_has_text(self):
665
652
link = inventory.InventoryLink('123', 'hello.c', ROOT_ID)
666
self.assertFalse(link.has_text())
653
self.failIf(link.has_text())
668
655
def test_make_entry(self):
669
656
self.assertIsInstance(inventory.make_entry("file", "name", ROOT_ID),
1224
1211
self.assertEqual(('tree\xce\xa9name', 'tree-root-id', 'tree-rev-id'),
1225
1212
inv._bytes_to_utf8name_key(bytes))
1227
def make_basic_utf8_inventory(self):
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",))
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()
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()))
1260
def test__preload_populates_cache(self):
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()
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()))
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()
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()))
1310
1215
class TestCHKInventoryExpand(tests.TestCaseWithMemoryTransport):
1437
1342
inv = self.make_simple_inventory()
1438
1343
self.assertExpand(['TREE_ROOT', 'dir1-id', 'sub-dir1-id', 'top-id',
1439
1344
'subsub-file1-id'], inv, ['top-id', 'subsub-file1-id'])
1442
class TestMutableInventoryFromTree(TestCaseWithTransport):
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))
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
1463
self.assertFalse(tree.inventory['thefileid'].executable)
1464
inv['thefileid'].executable = True
1465
self.assertFalse(tree.inventory['thefileid'].executable)