bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
743
by Martin Pool
- new simple versioning test cases |
1 |
# Copyright (C) 2005 by 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 |
||
17 |
||
18 |
"""Tests of simple versioning operations"""
|
|
19 |
||
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
20 |
# TODO: test trying to commit within a directory that is not yet added
|
21 |
||
22 |
||
23 |
import os |
|
|
1125
by Martin Pool
- test code exercises a successful check and null upgrade of a branch |
24 |
|
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
25 |
from bzrlib.tests import BzrTestBase, TestCaseInTempDir |
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
26 |
from bzrlib.branch import Branch |
|
1185.33.12
by Martin Pool
Remove some direct calls to logging, and some dead code |
27 |
from bzrlib.trace import mutter |
|
1185.31.32
by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \ |
28 |
from bzrlib.osutils import pathjoin |
|
1125
by Martin Pool
- test code exercises a successful check and null upgrade of a branch |
29 |
|
|
743
by Martin Pool
- new simple versioning test cases |
30 |
|
|
1141
by Martin Pool
- rename FunctionalTest to TestCaseInTempDir |
31 |
class TestVersioning(TestCaseInTempDir): |
|
1102
by Martin Pool
- merge test refactoring from robertc |
32 |
|
33 |
def test_mkdir(self): |
|
|
744
by Martin Pool
- show nicer descriptions while running tests |
34 |
"""Basic 'bzr mkdir' operation""" |
|
743
by Martin Pool
- new simple versioning test cases |
35 |
|
|
1478
by Robert Collins
convert versioning tests to use self.run_bzr, making the test suite quieter |
36 |
self.run_bzr('init') |
37 |
self.run_bzr('mkdir', 'foo') |
|
|
743
by Martin Pool
- new simple versioning test cases |
38 |
self.assert_(os.path.isdir('foo')) |
39 |
||
|
1185.35.21
by Aaron Bentley
Changed error status to 3 |
40 |
self.run_bzr('mkdir', 'foo', retcode=3) |
|
749
by Martin Pool
- More tests for bzr mkdir |
41 |
|
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
42 |
from bzrlib.diff import compare_trees |
|
749
by Martin Pool
- More tests for bzr mkdir |
43 |
from bzrlib.branch import Branch |
|
1185.33.66
by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko) |
44 |
b = Branch.open(u'.') |
|
749
by Martin Pool
- More tests for bzr mkdir |
45 |
|
46 |
delta = compare_trees(b.basis_tree(), b.working_tree()) |
|
47 |
||
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
48 |
self.log('delta.added = %r' % delta.added) |
49 |
||
|
749
by Martin Pool
- More tests for bzr mkdir |
50 |
self.assertEquals(len(delta.added), 1) |
51 |
self.assertEquals(delta.added[0][0], 'foo') |
|
52 |
self.failIf(delta.modified) |
|
53 |
||
|
1185.31.7
by John Arbash Meinel
Applying Alexander Belchenko's patch to handle multiple mkdir calls |
54 |
def test_mkdir_in_subdir(self): |
55 |
"""'bzr mkdir' operation in subdirectory""" |
|
56 |
||
57 |
self.run_bzr('init') |
|
58 |
self.run_bzr('mkdir', 'dir') |
|
59 |
self.assert_(os.path.isdir('dir')) |
|
60 |
||
61 |
os.chdir('dir') |
|
62 |
self.log('Run mkdir in subdir') |
|
63 |
self.run_bzr('mkdir', 'subdir') |
|
64 |
self.assert_(os.path.isdir('subdir')) |
|
65 |
os.chdir('..') |
|
66 |
||
67 |
from bzrlib.diff import compare_trees |
|
68 |
from bzrlib.branch import Branch |
|
|
1185.33.66
by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko) |
69 |
b = Branch.open(u'.') |
|
1185.31.7
by John Arbash Meinel
Applying Alexander Belchenko's patch to handle multiple mkdir calls |
70 |
|
71 |
delta = compare_trees(b.basis_tree(), b.working_tree()) |
|
72 |
||
73 |
self.log('delta.added = %r' % delta.added) |
|
74 |
||
75 |
self.assertEquals(len(delta.added), 2) |
|
76 |
self.assertEquals(delta.added[0][0], 'dir') |
|
|
1185.31.32
by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \ |
77 |
self.assertEquals(delta.added[1][0], pathjoin('dir','subdir')) |
|
1185.31.7
by John Arbash Meinel
Applying Alexander Belchenko's patch to handle multiple mkdir calls |
78 |
self.failIf(delta.modified) |
79 |
||
|
1185.31.8
by John Arbash Meinel
Modified mkdir functionality, to handle multiple nested trees. |
80 |
def test_mkdir_w_nested_trees(self): |
81 |
"""'bzr mkdir' with nested trees""" |
|
82 |
||
83 |
self.run_bzr('init') |
|
84 |
os.mkdir('a') |
|
85 |
os.chdir('a') |
|
86 |
self.run_bzr('init') |
|
87 |
os.mkdir('b') |
|
88 |
os.chdir('b') |
|
89 |
self.run_bzr('init') |
|
90 |
os.chdir('../..') |
|
91 |
||
92 |
self.run_bzr('mkdir', 'dir', 'a/dir', 'a/b/dir') |
|
93 |
self.failUnless(os.path.isdir('dir')) |
|
94 |
self.failUnless(os.path.isdir('a/dir')) |
|
95 |
self.failUnless(os.path.isdir('a/b/dir')) |
|
96 |
||
97 |
from bzrlib.diff import compare_trees |
|
|
1185.33.66
by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko) |
98 |
b = Branch.open(u'.') |
|
1185.31.8
by John Arbash Meinel
Modified mkdir functionality, to handle multiple nested trees. |
99 |
b_a = Branch.open('a') |
100 |
b_b = Branch.open('a/b') |
|
101 |
||
102 |
delta = compare_trees(b.basis_tree(), b.working_tree()) |
|
103 |
self.assertEquals(len(delta.added), 1) |
|
104 |
self.assertEquals(delta.added[0][0], 'dir') |
|
105 |
self.failIf(delta.modified) |
|
106 |
||
107 |
delta = compare_trees(b_a.basis_tree(), b_a.working_tree()) |
|
108 |
self.assertEquals(len(delta.added), 1) |
|
109 |
self.assertEquals(delta.added[0][0], 'dir') |
|
110 |
self.failIf(delta.modified) |
|
111 |
||
112 |
delta = compare_trees(b_b.basis_tree(), b_b.working_tree()) |
|
113 |
self.assertEquals(len(delta.added), 1) |
|
114 |
self.assertEquals(delta.added[0][0], 'dir') |
|
115 |
self.failIf(delta.modified) |
|
116 |
||
|
1508.1.5
by Robert Collins
Move add from Branch to WorkingTree. |
117 |
def test_working_tree_add_in_unversioned(self): |
|
754
by Martin Pool
- new check for attempting to add a file in an unversioned |
118 |
"""Try to add a file in an unversioned directory. |
119 |
||
|
1508.1.5
by Robert Collins
Move add from Branch to WorkingTree. |
120 |
"bzr add" adds the parent as necessary, but simple working tree add
|
|
1185.3.3
by Martin Pool
- patch from mpe to automatically add parent directories |
121 |
doesn't do that.
|
|
754
by Martin Pool
- new check for attempting to add a file in an unversioned |
122 |
"""
|
123 |
from bzrlib.branch import Branch |
|
124 |
from bzrlib.errors import NotVersionedError |
|
|
1508.1.5
by Robert Collins
Move add from Branch to WorkingTree. |
125 |
from bzrlib.workingtree import WorkingTree |
|
754
by Martin Pool
- new check for attempting to add a file in an unversioned |
126 |
|
|
1185.33.66
by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko) |
127 |
b = Branch.initialize(u'.') |
|
754
by Martin Pool
- new check for attempting to add a file in an unversioned |
128 |
|
129 |
self.build_tree(['foo/', |
|
130 |
'foo/hello']) |
|
131 |
||
132 |
self.assertRaises(NotVersionedError, |
|
|
1508.1.5
by Robert Collins
Move add from Branch to WorkingTree. |
133 |
WorkingTree(b.base, b).add, |
|
754
by Martin Pool
- new check for attempting to add a file in an unversioned |
134 |
'foo/hello') |
135 |
||
|
1380
by Martin Pool
- upgrade can no longer be done in current version branches |
136 |
self.check_branch() |
|
1125
by Martin Pool
- test code exercises a successful check and null upgrade of a branch |
137 |
|
|
1380
by Martin Pool
- upgrade can no longer be done in current version branches |
138 |
def check_branch(self): |
|
1125
by Martin Pool
- test code exercises a successful check and null upgrade of a branch |
139 |
"""After all the above changes, run the check and upgrade commands. |
140 |
||
141 |
The upgrade should be a no-op."""
|
|
|
1185.33.66
by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko) |
142 |
b = Branch.open(u'.') |
|
1185.33.12
by Martin Pool
Remove some direct calls to logging, and some dead code |
143 |
mutter('branch has %d revisions', b.revno()) |
|
1125
by Martin Pool
- test code exercises a successful check and null upgrade of a branch |
144 |
|
|
1185.33.12
by Martin Pool
Remove some direct calls to logging, and some dead code |
145 |
mutter('check branch...') |
|
1125
by Martin Pool
- test code exercises a successful check and null upgrade of a branch |
146 |
from bzrlib.check import check |
|
1450
by Robert Collins
hah, missed tests in check changes |
147 |
check(b, False) |
|
1506
by Robert Collins
Merge Johns current integration work. |
148 |
|
149 |
||
|
1141
by Martin Pool
- rename FunctionalTest to TestCaseInTempDir |
150 |
class SubdirCommit(TestCaseInTempDir): |
|
1102
by Martin Pool
- merge test refactoring from robertc |
151 |
|
152 |
def test_subdir_commit(self): |
|
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
153 |
"""Test committing a subdirectory, and committing within a directory.""" |
154 |
run_bzr = self.run_bzr |
|
155 |
eq = self.assertEqual |
|
156 |
||
157 |
self.build_tree(['a/', 'b/']) |
|
158 |
||
159 |
run_bzr('init') |
|
|
1185.33.66
by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko) |
160 |
b = Branch.open(u'.') |
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
161 |
|
162 |
for fn in ('a/one', 'b/two', 'top'): |
|
163 |
file(fn, 'w').write('old contents') |
|
164 |
||
165 |
run_bzr('add') |
|
166 |
run_bzr('commit', '-m', 'first revision') |
|
167 |
||
168 |
for fn in ('a/one', 'b/two', 'top'): |
|
169 |
file(fn, 'w').write('new contents') |
|
170 |
||
|
1185.33.12
by Martin Pool
Remove some direct calls to logging, and some dead code |
171 |
mutter('start selective subdir commit') |
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
172 |
run_bzr('commit', 'a', '-m', 'commit a only') |
173 |
||
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
174 |
old = b.revision_tree(b.get_rev_id(1)) |
175 |
new = b.revision_tree(b.get_rev_id(2)) |
|
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
176 |
|
177 |
eq(new.get_file_by_path('b/two').read(), 'old contents') |
|
178 |
eq(new.get_file_by_path('top').read(), 'old contents') |
|
179 |
eq(new.get_file_by_path('a/one').read(), 'new contents') |
|
180 |
||
181 |
os.chdir('a') |
|
182 |
# commit from here should do nothing
|
|
183 |
run_bzr('commit', '.', '-m', 'commit subdir only', '--unchanged') |
|
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
184 |
v3 = b.revision_tree(b.get_rev_id(3)) |
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
185 |
eq(v3.get_file_by_path('b/two').read(), 'old contents') |
186 |
eq(v3.get_file_by_path('top').read(), 'old contents') |
|
187 |
eq(v3.get_file_by_path('a/one').read(), 'new contents') |
|
188 |
||
189 |
# commit in subdirectory commits whole tree
|
|
190 |
run_bzr('commit', '-m', 'commit whole tree from subdir') |
|
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
191 |
v4 = b.revision_tree(b.get_rev_id(4)) |
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
192 |
eq(v4.get_file_by_path('b/two').read(), 'new contents') |
193 |
eq(v4.get_file_by_path('top').read(), 'new contents') |
|
194 |
||
195 |
# TODO: factor out some kind of assert_tree_state() method
|
|
196 |
||
|
1244
by Martin Pool
- let selftest/versioning run as standalone test |
197 |
|
198 |
if __name__ == '__main__': |
|
199 |
import unittest |
|
200 |
unittest.main() |
|
201 |