1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# Copyright (C) 2007 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Tests for interface conformance of inventories of working trees."""
import os
import time
from bzrlib import (
errors,
inventory,
)
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
class TestRevert(TestCaseWithWorkingTree):
def test_dangling_id(self):
wt = self.make_branch_and_tree('b1')
wt.lock_tree_write()
self.addCleanup(wt.unlock)
self.assertEqual(len(wt.inventory), 1)
open('b1/a', 'wb').write('a test\n')
wt.add('a')
self.assertEqual(len(wt.inventory), 2)
wt.flush() # workaround revert doing wt._write_inventory for now.
os.unlink('b1/a')
wt.revert([])
self.assertEqual(len(wt.inventory), 1)
class TestSnapshot(TestCaseWithWorkingTree):
def setUp(self):
# for full testing we'll need a branch
# with a subdir to test parent changes.
# and a file, link and dir under that.
# but right now I only need one attribute
# to change, and then test merge patterns
# with fake parent entries.
super(TestSnapshot, self).setUp()
self.wt = self.make_branch_and_tree('.')
self.branch = self.wt.branch
self.build_tree(['subdir/', 'subdir/file'], line_endings='binary')
self.wt.add(['subdir', 'subdir/file'],
['dirid', 'fileid'])
self.wt.commit('message_1', rev_id = '1')
self.tree_1 = self.branch.repository.revision_tree('1')
self.inv_1 = self.branch.repository.get_inventory('1')
self.file_1 = self.inv_1['fileid']
self.wt.lock_write()
self.addCleanup(self.wt.unlock)
self.file_active = self.wt.inventory['fileid']
self.builder = self.branch.get_commit_builder([], timestamp=time.time(), revision_id='2')
def test_snapshot_new_revision(self):
# This tests that a simple commit with no parents makes a new
# revision value in the inventory entry
self.file_active.snapshot('2', 'subdir/file', {}, self.wt, self.builder)
# expected outcome - file_1 has a revision id of '2', and we can get
# its text of 'file contents' out of the weave.
self.assertEqual(self.file_1.revision, '1')
self.assertEqual(self.file_active.revision, '2')
# this should be a separate test probably, but lets check it once..
lines = self.branch.repository.weave_store.get_weave(
'fileid',
self.branch.repository.get_transaction()).get_lines('2')
self.assertEqual(lines, ['contents of subdir/file\n'])
def test_snapshot_unchanged(self):
#This tests that a simple commit does not make a new entry for
# an unchanged inventory entry
self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
self.wt, self.builder)
self.assertEqual(self.file_1.revision, '1')
self.assertEqual(self.file_active.revision, '1')
vf = self.branch.repository.weave_store.get_weave(
'fileid',
self.branch.repository.get_transaction())
self.assertRaises(errors.RevisionNotPresent,
vf.get_lines,
'2')
def test_snapshot_merge_identical_different_revid(self):
# This tests that a commit with two identical parents, one of which has
# a different revision id, results in a new revision id in the entry.
# 1->other, commit a merge of other against 1, results in 2.
other_ie = inventory.InventoryFile('fileid', 'newname', self.file_1.parent_id)
other_ie = inventory.InventoryFile('fileid', 'file', self.file_1.parent_id)
other_ie.revision = '1'
other_ie.text_sha1 = self.file_1.text_sha1
other_ie.text_size = self.file_1.text_size
self.assertEqual(self.file_1, other_ie)
other_ie.revision = 'other'
self.assertNotEqual(self.file_1, other_ie)
versionfile = self.branch.repository.weave_store.get_weave(
'fileid', self.branch.repository.get_transaction())
versionfile.clone_text('other', '1', ['1'])
self.file_active.snapshot('2', 'subdir/file',
{'1':self.file_1, 'other':other_ie},
self.wt, self.builder)
self.assertEqual(self.file_active.revision, '2')
def test_snapshot_changed(self):
# This tests that a commit with one different parent results in a new
# revision id in the entry.
self.wt.rename_one('subdir/file', 'subdir/newname')
self.file_active = self.wt.inventory['fileid']
self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1},
self.wt, self.builder)
# expected outcome - file_1 has a revision id of '2'
self.assertEqual(self.file_active.revision, '2')
|