~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_globbing.py

  • Committer: John Arbash Meinel
  • Date: 2009-09-22 02:18:24 UTC
  • mto: This revision was merged to the branch mainline in revision 4709.
  • Revision ID: john@arbash-meinel.com-20090922021824-j3en52uqoof7ym89
Remove some assert statements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006 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
21
18
from bzrlib.globbing import (
22
19
    Globster,
23
 
    ExceptionGlobster,
24
20
    _OrderedGlobster,
25
 
    normalize_pattern
26
21
    )
27
22
from bzrlib.tests import (
28
23
    TestCase,
55
50
    def test_char_group_digit(self):
56
51
        self.assertMatchBasenameAndFullpath([
57
52
            # The definition of digit this uses includes arabic digits from
58
 
            # non-latin scripts (arabic, indic, etc.) but neither roman
59
 
            # numerals nor vulgar fractions. Some characters such as
60
 
            # subscript/superscript digits may or may not match depending on
61
 
            # the Python version used, see: <http://bugs.python.org/issue6561>
 
53
            # non-latin scripts (arabic, indic, etc.) and subscript/superscript
 
54
            # digits, but neither roman numerals nor vulgar fractions.
62
55
            (u'[[:digit:]]',
63
 
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21'],
 
56
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9'],
64
57
             [u'T', u'q', u' ', u'\u8336', u'.']),
65
58
            (u'[^[:digit:]]',
66
59
             [u'T', u'q', u' ', u'\u8336', u'.'],
67
 
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21']),
 
60
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9']),
68
61
            ])
69
62
 
70
63
    def test_char_group_space(self):
313
306
            self.assertEqual(patterns[x],globster.match(filename))
314
307
        self.assertEqual(None,globster.match('foobar.300'))
315
308
 
316
 
    def test_bad_pattern(self):
317
 
        """Ensure that globster handles bad patterns cleanly."""
318
 
        patterns = [u'RE:[', u'/home/foo', u'RE:*.cpp']
319
 
        g = Globster(patterns)
320
 
        e = self.assertRaises(errors.InvalidPattern, g.match, 'filename')
321
 
        self.assertContainsRe(e.msg,
322
 
            "File.*ignore.*contains error.*RE:\[.*RE:\*\.cpp", flags=re.DOTALL)
323
 
 
324
 
 
325
 
class TestExceptionGlobster(TestCase):
326
 
 
327
 
    def test_exclusion_patterns(self):
328
 
        """test that exception patterns are not matched"""
329
 
        patterns = [ u'*', u'!./local', u'!./local/**/*', u'!RE:\.z.*',u'!!./.zcompdump' ]
330
 
        globster = ExceptionGlobster(patterns)
331
 
        self.assertEqual(u'*', globster.match('tmp/foo.txt'))
332
 
        self.assertEqual(None, globster.match('local'))
333
 
        self.assertEqual(None, globster.match('local/bin/wombat'))
334
 
        self.assertEqual(None, globster.match('.zshrc'))
335
 
        self.assertEqual(None, globster.match('.zfunctions/fiddle/flam'))
336
 
        self.assertEqual(u'!!./.zcompdump', globster.match('.zcompdump'))
337
 
 
338
 
    def test_exclusion_order(self):
339
 
        """test that ordering of exclusion patterns does not matter"""
340
 
        patterns = [ u'static/**/*.html', u'!static/**/versionable.html']
341
 
        globster = ExceptionGlobster(patterns)
342
 
        self.assertEqual(u'static/**/*.html', globster.match('static/foo.html'))
343
 
        self.assertEqual(None, globster.match('static/versionable.html'))
344
 
        self.assertEqual(None, globster.match('static/bar/versionable.html'))
345
 
        globster = ExceptionGlobster(reversed(patterns))
346
 
        self.assertEqual(u'static/**/*.html', globster.match('static/foo.html'))
347
 
        self.assertEqual(None, globster.match('static/versionable.html'))
348
 
        self.assertEqual(None, globster.match('static/bar/versionable.html'))
349
309
 
350
310
class TestOrderedGlobster(TestCase):
351
311
 
358
318
        globster = _OrderedGlobster(reversed(patterns))
359
319
        self.assertEqual(u'bar.*', globster.match('bar.foo'))
360
320
        self.assertEqual(None, globster.match('foo.bar'))
361
 
 
362
 
 
363
 
class TestNormalizePattern(TestCase):
364
 
 
365
 
    def test_backslashes(self):
366
 
        """tests that backslashes are converted to forward slashes, multiple
367
 
        backslashes are collapsed to single forward slashes and trailing
368
 
        backslashes are removed"""
369
 
        self.assertEqual(u'/', normalize_pattern(u'\\'))
370
 
        self.assertEqual(u'/', normalize_pattern(u'\\\\'))
371
 
        self.assertEqual(u'/foo/bar', normalize_pattern(u'\\foo\\bar'))
372
 
        self.assertEqual(u'foo/bar', normalize_pattern(u'foo\\bar\\'))
373
 
        self.assertEqual(u'/foo/bar', normalize_pattern(u'\\\\foo\\\\bar\\\\'))
374
 
 
375
 
    def test_forward_slashes(self):
376
 
        """tests that multiple foward slashes are collapsed to single forward
377
 
        slashes and trailing forward slashes are removed"""
378
 
        self.assertEqual(u'/', normalize_pattern(u'/'))
379
 
        self.assertEqual(u'/', normalize_pattern(u'//'))
380
 
        self.assertEqual(u'/foo/bar', normalize_pattern(u'/foo/bar'))
381
 
        self.assertEqual(u'foo/bar', normalize_pattern(u'foo/bar/'))
382
 
        self.assertEqual(u'/foo/bar', normalize_pattern(u'//foo//bar//'))
383
 
 
384
 
    def test_mixed_slashes(self):
385
 
        """tests that multiple mixed slashes are collapsed to single forward
386
 
        slashes and trailing mixed slashes are removed"""
387
 
        self.assertEqual(u'/foo/bar', normalize_pattern(u'\\/\\foo//\\///bar/\\\\/'))