206
203
self.assertEquals(our_lock.peek(), None)
206
class TestFormat2WorkingTree(TestCaseWithTransport):
207
"""Tests that are specific to format 2 trees."""
208
209
def create_format2_tree(self, url):
209
return BzrDir.create_standalone_workingtree(url)
210
return self.make_branch_and_tree(
211
url, format=bzrlib.bzrdir.BzrDirFormat6())
211
def test_conflicts_format2(self):
213
def test_conflicts(self):
212
214
# test backwards compatability
213
215
tree = self.create_format2_tree('.')
214
216
self.assertRaises(errors.UnsupportedOperation, tree.set_conflicts,
216
218
file('lala.BASE', 'wb').write('labase')
217
expected = ContentsConflict('lala')
219
expected = conflicts.ContentsConflict('lala')
218
220
self.assertEqual(list(tree.conflicts()), [expected])
219
221
file('lala', 'wb').write('la')
220
222
tree.add('lala', 'lala-id')
221
expected = ContentsConflict('lala', file_id='lala-id')
223
expected = conflicts.ContentsConflict('lala', file_id='lala-id')
222
224
self.assertEqual(list(tree.conflicts()), [expected])
223
225
file('lala.THIS', 'wb').write('lathis')
224
226
file('lala.OTHER', 'wb').write('laother')
225
227
# When "text conflict"s happen, stem, THIS and OTHER are text
226
expected = TextConflict('lala', file_id='lala-id')
228
expected = conflicts.TextConflict('lala', file_id='lala-id')
227
229
self.assertEqual(list(tree.conflicts()), [expected])
228
230
os.unlink('lala.OTHER')
229
231
os.mkdir('lala.OTHER')
230
expected = ContentsConflict('lala', file_id='lala-id')
232
expected = conflicts.ContentsConflict('lala', file_id='lala-id')
231
233
self.assertEqual(list(tree.conflicts()), [expected])
236
class TestNonFormatSpecificCode(TestCaseWithTransport):
237
"""This class contains tests of workingtree that are not format specific."""
240
def test_gen_file_id(self):
241
self.assertStartsWith(bzrlib.workingtree.gen_file_id('bar'), 'bar-')
242
self.assertStartsWith(bzrlib.workingtree.gen_file_id('Mwoo oof\t m'), 'Mwoooofm-')
243
self.assertStartsWith(bzrlib.workingtree.gen_file_id('..gam.py'), 'gam.py-')
244
self.assertStartsWith(bzrlib.workingtree.gen_file_id('..Mwoo oof\t m'), 'Mwoooofm-')
246
def test_next_id_suffix(self):
247
bzrlib.workingtree._gen_id_suffix = None
248
bzrlib.workingtree._next_id_suffix()
249
self.assertNotEqual(None, bzrlib.workingtree._gen_id_suffix)
250
bzrlib.workingtree._gen_id_suffix = "foo-"
251
bzrlib.workingtree._gen_id_serial = 1
252
self.assertEqual("foo-2", bzrlib.workingtree._next_id_suffix())
253
self.assertEqual("foo-3", bzrlib.workingtree._next_id_suffix())
254
self.assertEqual("foo-4", bzrlib.workingtree._next_id_suffix())
255
self.assertEqual("foo-5", bzrlib.workingtree._next_id_suffix())
256
self.assertEqual("foo-6", bzrlib.workingtree._next_id_suffix())
257
self.assertEqual("foo-7", bzrlib.workingtree._next_id_suffix())
258
self.assertEqual("foo-8", bzrlib.workingtree._next_id_suffix())
259
self.assertEqual("foo-9", bzrlib.workingtree._next_id_suffix())
260
self.assertEqual("foo-10", bzrlib.workingtree._next_id_suffix())
262
def test__translate_ignore_rule(self):
263
tree = self.make_branch_and_tree('.')
264
# translation should return the regex, the number of groups in it,
265
# and the original rule in a tuple.
266
# there are three sorts of ignore rules:
267
# root only - regex is the rule itself without the leading ./
270
tree._translate_ignore_rule("./rootdirrule"))
271
# full path - regex is the rule itself
273
"(path\\/to\\/file$)",
274
tree._translate_ignore_rule("path/to/file"))
275
# basename only rule - regex is a rule that ignores everything up
276
# to the last / in the filename
278
"((?:.*/)?(?!.*/)basenamerule$)",
279
tree._translate_ignore_rule("basenamerule"))
281
def test__combine_ignore_rules(self):
282
tree = self.make_branch_and_tree('.')
283
# the combined ignore regexs need the outer group indices
284
# placed in a dictionary with the rules that were combined.
285
# an empty set of rules
286
# this is returned as a list of combined regex,rule sets, because
287
# python has a limit of 100 combined regexes.
288
compiled_rules = tree._combine_ignore_rules([])
289
self.assertEqual([], compiled_rules)
290
# one of each type of rule.
291
compiled_rules = tree._combine_ignore_rules(
292
["rule1", "rule/two", "./three"])[0]
293
# what type *is* the compiled regex to do an isinstance of ?
294
self.assertEqual(3, compiled_rules[0].groups)
296
{0:"rule1",1:"rule/two",2:"./three"},
299
def test__combine_ignore_rules_grouping(self):
300
tree = self.make_branch_and_tree('.')
301
# when there are too many rules, the output is split into groups of 100
303
for index in range(198):
305
self.assertEqual(2, len(tree._combine_ignore_rules(rules)))
307
def test__get_ignore_rules_as_regex(self):
308
tree = self.make_branch_and_tree('.')
309
# test against the default rules.
310
reference_output = tree._combine_ignore_rules(bzrlib.DEFAULT_IGNORE)[0]
311
regex_rules = tree._get_ignore_rules_as_regex()[0]
312
self.assertEqual(len(reference_output[1]), regex_rules[0].groups)
313
self.assertEqual(reference_output[1], regex_rules[1])