~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_globbing.py

  • Committer: Vincent Ladeuil
  • Date: 2012-03-13 16:42:20 UTC
  • mto: This revision was merged to the branch mainline in revision 6512.
  • Revision ID: v.ladeuil+lp@free.fr-20120313164220-atkou2zprhlspmwg
Mention that a given config option cannot be safely handled via both APIs at the same time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
 
18
import re
 
19
 
 
20
from bzrlib import errors
18
21
from bzrlib.globbing import (
19
22
    Globster,
 
23
    ExceptionGlobster,
20
24
    _OrderedGlobster,
21
25
    normalize_pattern
22
26
    )
23
27
from bzrlib.tests import (
24
28
    TestCase,
25
 
    TestCaseInTempDir,
26
29
    )
27
30
 
28
31
 
34
37
                glob = glob_prefix + glob
35
38
            globster = Globster([glob])
36
39
            for name in positive:
37
 
                self.failUnless(globster.match(name), repr(
 
40
                self.assertTrue(globster.match(name), repr(
38
41
                    u'name "%s" does not match glob "%s" (re=%s)' %
39
42
                    (name, glob, globster._regex_patterns[0][0].pattern)))
40
43
            for name in negative:
41
 
                self.failIf(globster.match(name), repr(
 
44
                self.assertFalse(globster.match(name), repr(
42
45
                    u'name "%s" does match glob "%s" (re=%s)' %
43
46
                    (name, glob, globster._regex_patterns[0][0].pattern)))
44
47
 
51
54
    def test_char_group_digit(self):
52
55
        self.assertMatchBasenameAndFullpath([
53
56
            # The definition of digit this uses includes arabic digits from
54
 
            # non-latin scripts (arabic, indic, etc.) and subscript/superscript
55
 
            # digits, but neither roman numerals nor vulgar fractions.
 
57
            # non-latin scripts (arabic, indic, etc.) but neither roman
 
58
            # numerals nor vulgar fractions. Some characters such as
 
59
            # subscript/superscript digits may or may not match depending on
 
60
            # the Python version used, see: <http://bugs.python.org/issue6561>
56
61
            (u'[[:digit:]]',
57
 
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9'],
 
62
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21'],
58
63
             [u'T', u'q', u' ', u'\u8336', u'.']),
59
64
            (u'[^[:digit:]]',
60
65
             [u'T', u'q', u' ', u'\u8336', u'.'],
61
 
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9']),
 
66
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21']),
62
67
            ])
63
68
 
64
69
    def test_char_group_space(self):
307
312
            self.assertEqual(patterns[x],globster.match(filename))
308
313
        self.assertEqual(None,globster.match('foobar.300'))
309
314
 
 
315
    def test_bad_pattern(self):
 
316
        """Ensure that globster handles bad patterns cleanly."""
 
317
        patterns = [u'RE:[', u'/home/foo', u'RE:*.cpp']
 
318
        g = Globster(patterns)
 
319
        e = self.assertRaises(errors.InvalidPattern, g.match, 'filename')
 
320
        self.assertContainsRe(e.msg,
 
321
            "File.*ignore.*contains error.*RE:\[.*RE:\*\.cpp", flags=re.DOTALL)
 
322
 
 
323
 
 
324
class TestExceptionGlobster(TestCase):
 
325
 
 
326
    def test_exclusion_patterns(self):
 
327
        """test that exception patterns are not matched"""
 
328
        patterns = [ u'*', u'!./local', u'!./local/**/*', u'!RE:\.z.*',u'!!./.zcompdump' ]
 
329
        globster = ExceptionGlobster(patterns)
 
330
        self.assertEqual(u'*', globster.match('tmp/foo.txt'))
 
331
        self.assertEqual(None, globster.match('local'))
 
332
        self.assertEqual(None, globster.match('local/bin/wombat'))
 
333
        self.assertEqual(None, globster.match('.zshrc'))
 
334
        self.assertEqual(None, globster.match('.zfunctions/fiddle/flam'))
 
335
        self.assertEqual(u'!!./.zcompdump', globster.match('.zcompdump'))
 
336
 
 
337
    def test_exclusion_order(self):
 
338
        """test that ordering of exclusion patterns does not matter"""
 
339
        patterns = [ u'static/**/*.html', u'!static/**/versionable.html']
 
340
        globster = ExceptionGlobster(patterns)
 
341
        self.assertEqual(u'static/**/*.html', globster.match('static/foo.html'))
 
342
        self.assertEqual(None, globster.match('static/versionable.html'))
 
343
        self.assertEqual(None, globster.match('static/bar/versionable.html'))
 
344
        globster = ExceptionGlobster(reversed(patterns))
 
345
        self.assertEqual(u'static/**/*.html', globster.match('static/foo.html'))
 
346
        self.assertEqual(None, globster.match('static/versionable.html'))
 
347
        self.assertEqual(None, globster.match('static/bar/versionable.html'))
310
348
 
311
349
class TestOrderedGlobster(TestCase):
312
350