~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-12-12 16:29:59 UTC
  • mfrom: (2178.1.1 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20061212162959-cd3c77ebe8d57759
(Kent Gibson, Jan Hudec) Better glob pattern matcher (fixes bug #57637)

Show diffs side-by-side

added added

removed removed

Lines of Context:
268
268
        file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_root_id)
269
269
        self.assertStartsWith(file_id, 'tree_root-')
270
270
        
271
 
    def test__translate_ignore_rule(self):
272
 
        tree = self.make_branch_and_tree('.')
273
 
        # translation should return the regex, the number of groups in it,
274
 
        # and the original rule in a tuple.
275
 
        # there are three sorts of ignore rules:
276
 
        # root only - regex is the rule itself without the leading ./
277
 
        self.assertEqual(
278
 
            "(rootdirrule$)", 
279
 
            tree._translate_ignore_rule("./rootdirrule"))
280
 
        # full path - regex is the rule itself
281
 
        self.assertEqual(
282
 
            "(path\\/to\\/file$)",
283
 
            tree._translate_ignore_rule("path/to/file"))
284
 
        # basename only rule - regex is a rule that ignores everything up
285
 
        # to the last / in the filename
286
 
        self.assertEqual(
287
 
            "((?:.*/)?(?!.*/)basenamerule$)",
288
 
            tree._translate_ignore_rule("basenamerule"))
289
 
 
290
 
    def test__combine_ignore_rules(self):
291
 
        tree = self.make_branch_and_tree('.')
292
 
        # the combined ignore regexs need the outer group indices
293
 
        # placed in a dictionary with the rules that were combined.
294
 
        # an empty set of rules
295
 
        # this is returned as a list of combined regex,rule sets, because
296
 
        # python has a limit of 100 combined regexes.
297
 
        compiled_rules = tree._combine_ignore_rules([])
298
 
        self.assertEqual([], compiled_rules)
299
 
        # one of each type of rule.
300
 
        compiled_rules = tree._combine_ignore_rules(
301
 
            ["rule1", "rule/two", "./three"])[0]
302
 
        # what type *is* the compiled regex to do an isinstance of ?
303
 
        self.assertEqual(3, compiled_rules[0].groups)
304
 
        self.assertEqual(
305
 
            {0:"rule1",1:"rule/two",2:"./three"},
306
 
            compiled_rules[1])
307
 
 
308
 
    def test__combine_ignore_rules_grouping(self):
309
 
        tree = self.make_branch_and_tree('.')
310
 
        # when there are too many rules, the output is split into groups of 100
311
 
        rules = []
312
 
        for index in range(198):
313
 
            rules.append('foo')
314
 
        self.assertEqual(2, len(tree._combine_ignore_rules(rules)))
315
 
 
316
 
    def test__get_ignore_rules_as_regex(self):
317
 
        tree = self.make_branch_and_tree('.')
318
 
        # Setup the default ignore list to be empty
319
 
        ignores._set_user_ignores([])
320
 
 
321
 
        # some plugins (shelf) modifies the DEFAULT_IGNORE list in memory
322
 
        # which causes this test to fail so force the DEFAULT_IGNORE
323
 
        # list to be empty
324
 
        orig_default = bzrlib.DEFAULT_IGNORE
325
 
        # Also make sure the runtime ignore list is empty
326
 
        orig_runtime = ignores._runtime_ignores
327
 
        try:
328
 
            bzrlib.DEFAULT_IGNORE = []
329
 
            ignores._runtime_ignores = set()
330
 
 
331
 
            self.build_tree_contents([('.bzrignore', 'CVS\n.hg\n')])
332
 
            reference_output = tree._combine_ignore_rules(
333
 
                                    set(['CVS', '.hg']))[0]
334
 
            regex_rules = tree._get_ignore_rules_as_regex()[0]
335
 
            self.assertEqual(len(reference_output[1]), regex_rules[0].groups)
336
 
            self.assertEqual(reference_output[1], regex_rules[1])
337
 
        finally:
338
 
            bzrlib.DEFAULT_IGNORE = orig_default
339
 
            ignores._runtime_ignores = orig_runtime
340
 
 
341
271
 
342
272
class InstrumentedTree(object):
343
273
    """A instrumented tree to check the needs_tree_write_lock decorator."""