/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_globbing.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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 .. import errors, lazy_regex
21
 
from ..globbing import (
 
18
from bzrlib.globbing import (
22
19
    Globster,
23
20
    ExceptionGlobster,
24
21
    _OrderedGlobster,
25
22
    normalize_pattern
26
23
    )
27
 
from . import (
 
24
from bzrlib.tests import (
28
25
    TestCase,
 
26
    TestCaseInTempDir,
29
27
    )
30
28
 
31
29
 
37
35
                glob = glob_prefix + glob
38
36
            globster = Globster([glob])
39
37
            for name in positive:
40
 
                self.assertTrue(globster.match(name), repr(
 
38
                self.failUnless(globster.match(name), repr(
41
39
                    u'name "%s" does not match glob "%s" (re=%s)' %
42
40
                    (name, glob, globster._regex_patterns[0][0].pattern)))
43
41
            for name in negative:
44
 
                self.assertFalse(globster.match(name), repr(
 
42
                self.failIf(globster.match(name), repr(
45
43
                    u'name "%s" does match glob "%s" (re=%s)' %
46
44
                    (name, glob, globster._regex_patterns[0][0].pattern)))
47
45
 
54
52
    def test_char_group_digit(self):
55
53
        self.assertMatchBasenameAndFullpath([
56
54
            # The definition of digit this uses includes arabic digits from
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>
 
55
            # non-latin scripts (arabic, indic, etc.) and subscript/superscript
 
56
            # digits, but neither roman numerals nor vulgar fractions.
61
57
            (u'[[:digit:]]',
62
 
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21'],
 
58
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9'],
63
59
             [u'T', u'q', u' ', u'\u8336', u'.']),
64
60
            (u'[^[:digit:]]',
65
61
             [u'T', u'q', u' ', u'\u8336', u'.'],
66
 
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21']),
 
62
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9']),
67
63
            ])
68
64
 
69
65
    def test_char_group_space(self):
184
180
             [u'foo', u'foo.bar'],
185
181
             [u'.foo', u'foo/bar', u'foo/.bar']),
186
182
            (u'*bar',
187
 
             [u'bar', u'foobar', u'foo\\nbar', u'foo.bar', u'foo/bar',
 
183
             [u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
188
184
              u'foo/foobar', u'foo/f.bar', u'.bar', u'foo/.bar'],
189
185
             []),
190
186
            ])
222
218
             [u'foo', u'foo.bar'],
223
219
             [u'.foo', u'foo/bar', u'foo/.bar']),
224
220
            (u'**bar',
225
 
             [u'bar', u'foobar', u'foo\\nbar', u'foo.bar', u'foo/bar',
 
221
             [u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
226
222
              u'foo/foobar', u'foo/f.bar', u'.bar', u'foo/.bar'],
227
223
             []),
228
224
            ])
264
260
        self.assertMatch([
265
261
            (u'*.x',
266
262
             [u'foo/bar/baz.x', u'\u8336/Q.x', u'foo.y.x', u'.foo.x',
267
 
              u'bar/.foo.x', u'.x', ],
 
263
              u'bar/.foo.x', u'.x',],
268
264
             [u'foo.x.y']),
269
265
            (u'foo/*.bar',
270
266
             [u'foo/b.bar', u'foo/a.b.bar', u'foo/.bar'],
289
285
 
290
286
        The types being extension, basename and full path.
291
287
        """
292
 
        patterns = [u'*.foo', u'.*.swp', u'./*.png']
 
288
        patterns = [ u'*.foo', u'.*.swp', u'./*.png']
293
289
        globster = Globster(patterns)
294
290
        self.assertEqual(u'*.foo', globster.match('bar.foo'))
295
291
        self.assertEqual(u'./*.png', globster.match('foo.png'))
304
300
        This test assumes the globs are broken into regexs containing 99
305
301
        groups.
306
302
        """
307
 
        patterns = [u'*.%03d' % i for i in range(300)]
 
303
        patterns = [ u'*.%03d' % i for i in xrange(0,300) ]
308
304
        globster = Globster(patterns)
309
305
        # test the fence posts
310
 
        for x in (0, 98, 99, 197, 198, 296, 297, 299):
 
306
        for x in (0,98,99,197,198,296,297,299):
311
307
            filename = u'foo.%03d' % x
312
 
            self.assertEqual(patterns[x], globster.match(filename))
313
 
        self.assertEqual(None, globster.match('foobar.300'))
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(lazy_regex.InvalidPattern, g.match, 'filename')
320
 
        self.assertContainsRe(e.msg,
321
 
                              r"File.*ignore.*contains error.*RE:\[.*RE:\*\.cpp", flags=re.DOTALL)
322
 
 
 
308
            self.assertEqual(patterns[x],globster.match(filename))
 
309
        self.assertEqual(None,globster.match('foobar.300'))
323
310
 
324
311
class TestExceptionGlobster(TestCase):
325
312
 
326
313
    def test_exclusion_patterns(self):
327
314
        """test that exception patterns are not matched"""
328
 
        patterns = [u'*', u'!./local', u'!./local/**/*',
329
 
                    u'!RE:\\.z.*', u'!!./.zcompdump']
 
315
        patterns = [ u'*', u'!./local', u'!./local/**/*', u'!RE:\.z.*',u'!!./.zcompdump' ]
330
316
        globster = ExceptionGlobster(patterns)
331
317
        self.assertEqual(u'*', globster.match('tmp/foo.txt'))
332
318
        self.assertEqual(None, globster.match('local'))
337
323
 
338
324
    def test_exclusion_order(self):
339
325
        """test that ordering of exclusion patterns does not matter"""
340
 
        patterns = [u'static/**/*.html', u'!static/**/versionable.html']
 
326
        patterns = [ u'static/**/*.html', u'!static/**/versionable.html']
341
327
        globster = ExceptionGlobster(patterns)
342
 
        self.assertEqual(u'static/**/*.html',
343
 
                         globster.match('static/foo.html'))
 
328
        self.assertEqual(u'static/**/*.html', globster.match('static/foo.html'))
344
329
        self.assertEqual(None, globster.match('static/versionable.html'))
345
330
        self.assertEqual(None, globster.match('static/bar/versionable.html'))
346
331
        globster = ExceptionGlobster(reversed(patterns))
347
 
        self.assertEqual(u'static/**/*.html',
348
 
                         globster.match('static/foo.html'))
 
332
        self.assertEqual(u'static/**/*.html', globster.match('static/foo.html'))
349
333
        self.assertEqual(None, globster.match('static/versionable.html'))
350
334
        self.assertEqual(None, globster.match('static/bar/versionable.html'))
351
335
 
352
 
 
353
336
class TestOrderedGlobster(TestCase):
354
337
 
355
338
    def test_ordered_globs(self):
356
339
        """test that the first match in a list is the one found"""
357
 
        patterns = [u'*.foo', u'bar.*']
 
340
        patterns = [ u'*.foo', u'bar.*']
358
341
        globster = _OrderedGlobster(patterns)
359
342
        self.assertEqual(u'*.foo', globster.match('bar.foo'))
360
343
        self.assertEqual(None, globster.match('foo.bar'))
387
370
    def test_mixed_slashes(self):
388
371
        """tests that multiple mixed slashes are collapsed to single forward
389
372
        slashes and trailing mixed slashes are removed"""
390
 
        self.assertEqual(
391
 
            u'/foo/bar', normalize_pattern(u'\\/\\foo//\\///bar/\\\\/'))
 
373
        self.assertEqual(u'/foo/bar', normalize_pattern(u'\\/\\foo//\\///bar/\\\\/'))