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