bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
5630.2.2
by John Arbash Meinel
Start fleshing out the design. Something weird is causing my tests to all fail. |
1 |
# Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
17 |
"""Tests for WorkingTree.check_state."""
|
|
18 |
||
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
19 |
from breezy import ( |
|
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
20 |
errors, |
|
5630.2.2
by John Arbash Meinel
Start fleshing out the design. Something weird is causing my tests to all fail. |
21 |
tests, |
22 |
)
|
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
23 |
from breezy.tests.per_workingtree import TestCaseWithWorkingTree |
|
5630.2.2
by John Arbash Meinel
Start fleshing out the design. Something weird is causing my tests to all fail. |
24 |
|
25 |
||
|
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
26 |
class TestCaseWithState(TestCaseWithWorkingTree): |
27 |
||
28 |
def make_tree_with_broken_dirstate(self, path): |
|
29 |
tree = self.make_branch_and_tree(path) |
|
|
5630.2.5
by John Arbash Meinel
(broken) Intermediate state to make reset_tree work even when things are broken. |
30 |
self.break_dirstate(tree) |
31 |
return tree |
|
32 |
||
|
5630.2.6
by John Arbash Meinel
Implement a reset-to-known-state ability for DirState. |
33 |
def break_dirstate(self, tree, completely=False): |
|
5630.2.5
by John Arbash Meinel
(broken) Intermediate state to make reset_tree work even when things are broken. |
34 |
"""Write garbage into the dirstate file.""" |
|
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
35 |
if getattr(tree, 'current_dirstate', None) is None: |
36 |
raise tests.TestNotApplicable( |
|
37 |
'Only applies to dirstate-based trees') |
|
38 |
tree.lock_read() |
|
39 |
try: |
|
40 |
dirstate = tree.current_dirstate() |
|
41 |
dirstate_path = dirstate._filename |
|
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
42 |
self.assertPathExists(dirstate_path) |
|
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
43 |
finally: |
44 |
tree.unlock() |
|
45 |
# We have to have the tree unlocked at this point, so we can safely
|
|
46 |
# mutate the state file on all platforms.
|
|
|
5630.2.6
by John Arbash Meinel
Implement a reset-to-known-state ability for DirState. |
47 |
if completely: |
48 |
f = open(dirstate_path, 'wb') |
|
49 |
else: |
|
50 |
f = open(dirstate_path, 'ab') |
|
|
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
51 |
try: |
|
6973.7.5
by Jelmer Vernooij
s/file/open. |
52 |
f.write(b'garbage-at-end-of-file\n') |
|
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
53 |
finally: |
54 |
f.close() |
|
55 |
||
56 |
||
57 |
class TestCheckState(TestCaseWithState): |
|
|
5630.2.2
by John Arbash Meinel
Start fleshing out the design. Something weird is causing my tests to all fail. |
58 |
|
59 |
def test_check_state(self): |
|
60 |
tree = self.make_branch_and_tree('tree') |
|
61 |
# Everything should be fine with an unmodified tree, no exception
|
|
62 |
# should be raised.
|
|
|
5630.2.3
by John Arbash Meinel
Looks like it was a stale experimental .pyd file causing trouble. Tests pass again now. |
63 |
tree.check_state() |
|
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
64 |
|
65 |
def test_check_broken_dirstate(self): |
|
66 |
tree = self.make_tree_with_broken_dirstate('tree') |
|
67 |
self.assertRaises(errors.BzrError, tree.check_state) |
|
68 |
||
69 |
||
70 |
class TestResetState(TestCaseWithState): |
|
71 |
||
|
5630.2.6
by John Arbash Meinel
Implement a reset-to-known-state ability for DirState. |
72 |
def make_initial_tree(self): |
|
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
73 |
tree = self.make_branch_and_tree('tree') |
74 |
self.build_tree(['tree/foo', 'tree/dir/', 'tree/dir/bar']) |
|
75 |
tree.add(['foo', 'dir', 'dir/bar']) |
|
76 |
tree.commit('initial') |
|
|
5630.2.6
by John Arbash Meinel
Implement a reset-to-known-state ability for DirState. |
77 |
return tree |
78 |
||
79 |
def test_reset_state_forgets_changes(self): |
|
80 |
tree = self.make_initial_tree() |
|
|
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
81 |
foo_id = tree.path2id('foo') |
82 |
tree.rename_one('foo', 'baz') |
|
|
6883.5.21
by Jelmer Vernooij
Allow not supporting rename tracking in test_check_state. |
83 |
self.assertFalse(tree.is_versioned('foo')) |
84 |
if tree.supports_rename_tracking(): |
|
85 |
self.assertEqual(foo_id, tree.path2id('baz')) |
|
86 |
else: |
|
87 |
self.assertTrue(tree.is_versioned('baz')) |
|
|
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
88 |
tree.reset_state() |
89 |
# After reset, we should have forgotten about the rename, but we won't
|
|
90 |
# have
|
|
91 |
self.assertEqual(foo_id, tree.path2id('foo')) |
|
92 |
self.assertEqual(None, tree.path2id('baz')) |
|
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
93 |
self.assertPathDoesNotExist('tree/foo') |
94 |
self.assertPathExists('tree/baz') |
|
|
5630.2.5
by John Arbash Meinel
(broken) Intermediate state to make reset_tree work even when things are broken. |
95 |
|
96 |
def test_reset_state_handles_corrupted_dirstate(self): |
|
|
5630.2.6
by John Arbash Meinel
Implement a reset-to-known-state ability for DirState. |
97 |
tree = self.make_initial_tree() |
|
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
98 |
rev_id = tree.last_revision() |
|
5630.2.5
by John Arbash Meinel
(broken) Intermediate state to make reset_tree work even when things are broken. |
99 |
self.break_dirstate(tree) |
100 |
tree.reset_state() |
|
101 |
tree.check_state() |
|
|
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
102 |
self.assertEqual(rev_id, tree.last_revision()) |
|
5630.2.6
by John Arbash Meinel
Implement a reset-to-known-state ability for DirState. |
103 |
|
104 |
def test_reset_state_handles_destroyed_dirstate(self): |
|
105 |
# If you pass the revision_id, we can handle a completely destroyed
|
|
106 |
# dirstate file.
|
|
107 |
tree = self.make_initial_tree() |
|
108 |
rev_id = tree.last_revision() |
|
109 |
self.break_dirstate(tree, completely=True) |
|
110 |
tree.reset_state(revision_ids=[rev_id]) |
|
111 |
tree.check_state() |
|
|
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
112 |
self.assertEqual(rev_id, tree.last_revision()) |