53
59
def test_match(self):
54
60
stub_tree = StubTree(False)
55
61
matcher = ReturnsUnlockable(stub_tree)
56
self.assertThat(matcher.match(lambda:FakeUnlockable()), Equals(None))
62
self.assertThat(matcher.match(lambda: FakeUnlockable()), Equals(None))
58
64
def test_mismatch(self):
59
65
stub_tree = StubTree(True)
60
66
matcher = ReturnsUnlockable(stub_tree)
61
mismatch = matcher.match(lambda:FakeUnlockable())
67
mismatch = matcher.match(lambda: FakeUnlockable())
62
68
self.assertNotEqual(None, mismatch)
63
69
self.assertThat(mismatch.describe(), Equals("I am da tree is locked"))
72
class TestMatchesAncestry(TestCaseWithTransport):
74
def test__str__(self):
75
matcher = MatchesAncestry("A repository", b"arevid")
77
"MatchesAncestry(repository='A repository', "
78
"revision_id=%r)" % (b'arevid', ),
82
b = self.make_branch_builder('.')
84
revid1 = b.build_commit()
85
revid2 = b.build_commit()
87
branch = b.get_branch()
88
m = MatchesAncestry(branch.repository, revid2)
89
self.assertThat([revid2, revid1], m)
90
self.assertThat([revid1, revid2], m)
91
m = MatchesAncestry(branch.repository, revid1)
92
self.assertThat([revid1], m)
93
m = MatchesAncestry(branch.repository, b"unknown")
94
self.assertThat([b"unknown"], m)
96
def test_mismatch(self):
97
b = self.make_branch_builder('.')
99
revid1 = b.build_commit()
100
revid2 = b.build_commit()
102
branch = b.get_branch()
103
m = MatchesAncestry(branch.repository, revid1)
104
mismatch = m.match([])
105
self.assertIsNot(None, mismatch)
107
"mismatched ancestry for revision %r was [%r], expected []" % (
112
class TestHasLayout(TestCaseWithTransport):
114
def test__str__(self):
115
matcher = HasLayout([(b"a", b"a-id")])
116
self.assertEqual("HasLayout(%r)" % ([(b'a', b'a-id')], ), str(matcher))
118
def test_match(self):
119
t = self.make_branch_and_tree('.')
120
self.build_tree(['a', 'b/', 'b/c'])
121
t.add(['a', 'b', 'b/c'], [b'a-id', b'b-id', b'c-id'])
122
self.assertThat(t, HasLayout(['', 'a', 'b/', 'b/c']))
123
self.assertThat(t, HasLayout(
124
[('', t.path2id('')),
129
def test_mismatch(self):
130
t = self.make_branch_and_tree('.')
131
self.build_tree(['a', 'b/', 'b/c'])
132
t.add(['a', 'b', 'b/c'], [b'a-id', b'b-id', b'c-id'])
133
mismatch = HasLayout(['a']).match(t)
134
self.assertIsNot(None, mismatch)
136
set(("['', 'a', 'b/', 'b/c']", "['a']")),
137
set(mismatch.describe().split(" != ")))
139
def test_no_dirs(self):
140
# Some tree/repository formats do not support versioned directories
141
t = self.make_branch_and_tree('.')
142
t.has_versioned_directories = lambda: False
143
self.build_tree(['a', 'b/', 'b/c'])
144
t.add(['a', 'b', 'b/c'], [b'a-id', b'b-id', b'c-id'])
145
self.assertIs(None, HasLayout(['', 'a', 'b/', 'b/c']).match(t))
146
self.assertIs(None, HasLayout(['', 'a', 'b/', 'b/c', 'd/']).match(t))
147
mismatch = HasLayout([u'', u'a', u'd/']).match(t)
148
self.assertIsNot(None, mismatch)
150
set(("['', 'a', 'b/', 'b/c']", "['', 'a']")),
151
set(mismatch.describe().split(" != ")))
154
class TestHasPathRelations(TestCaseWithTransport):
156
def test__str__(self):
157
t = self.make_branch_and_tree('.')
158
matcher = HasPathRelations(t, [("a", "b")])
159
self.assertEqual("HasPathRelations(%r, %r)" %
160
(t, [('a', 'b')]), str(matcher))
162
def test_match(self):
163
t = self.make_branch_and_tree('.')
164
self.build_tree(['a', 'b/', 'b/c'])
165
t.add(['a', 'b', 'b/c'])
166
self.assertThat(t, HasPathRelations(t,
172
def test_mismatch(self):
173
t = self.make_branch_and_tree('.')
174
self.build_tree(['a', 'b/', 'b/c'])
175
t.add(['a', 'b', 'b/c'])
176
mismatch = HasPathRelations(t, [('a', 'a')]).match(t)
177
self.assertIsNot(None, mismatch)
180
class TestContainsNoVfsCalls(TestCase):
182
def _make_call(self, method, args):
183
return CapturedCall(CallHookParams(method, args, None, None, None), 0)
185
def test__str__(self):
186
self.assertEqual("ContainsNoVfsCalls()", str(ContainsNoVfsCalls()))
188
def test_empty(self):
189
self.assertIs(None, ContainsNoVfsCalls().match([]))
191
def test_no_vfs_calls(self):
192
calls = [self._make_call("Branch.get_config_file", [])]
193
self.assertIs(None, ContainsNoVfsCalls().match(calls))
195
def test_ignores_unknown(self):
196
calls = [self._make_call("unknown", [])]
197
self.assertIs(None, ContainsNoVfsCalls().match(calls))
199
def test_match(self):
200
calls = [self._make_call(b"append", [b"file"]),
201
self._make_call(b"Branch.get_config_file", [])]
202
mismatch = ContainsNoVfsCalls().match(calls)
203
self.assertIsNot(None, mismatch)
204
self.assertEqual([calls[0].call], mismatch.vfs_calls)
205
self.assertIn(mismatch.describe(), [
206
"no VFS calls expected, got: b'append'(b'file')",
207
"no VFS calls expected, got: append('file')"])
210
class TestRevisionHistoryMatches(TestCaseWithTransport):
212
def test_empty(self):
213
tree = self.make_branch_and_tree('.')
214
matcher = RevisionHistoryMatches([])
215
self.assertIs(None, matcher.match(tree.branch))
217
def test_matches(self):
218
tree = self.make_branch_and_tree('.')
219
tree.commit('msg1', rev_id=b'a')
220
tree.commit('msg2', rev_id=b'b')
221
matcher = RevisionHistoryMatches([b'a', b'b'])
222
self.assertIs(None, matcher.match(tree.branch))
224
def test_mismatch(self):
225
tree = self.make_branch_and_tree('.')
226
tree.commit('msg1', rev_id=b'a')
227
tree.commit('msg2', rev_id=b'b')
228
matcher = RevisionHistoryMatches([b'a', b'b', b'c'])
230
set(("[b'a', b'b']", "[b'a', b'b', b'c']")),
231
set(matcher.match(tree.branch).describe().split(" != ")))