/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

Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.

This is used to replace various ad hoc implementations of the same logic,
notably the version used in registry's _LazyObjectGetter which had a bug when
getting a module without also getting a member.  And of course, this new
function has unit tests, unlike the replaced code.

This also adds a KnownHooksRegistry subclass to provide a more natural home for
some other logic.

I'm not thrilled about the name of the new module or the new functions, but it's
hard to think of good names for such generic functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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,
20
23
    ExceptionGlobster,
52
55
    def test_char_group_digit(self):
53
56
        self.assertMatchBasenameAndFullpath([
54
57
            # The definition of digit this uses includes arabic digits from
55
 
            # non-latin scripts (arabic, indic, etc.) and subscript/superscript
56
 
            # digits, but neither roman numerals nor vulgar fractions.
 
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>
57
62
            (u'[[:digit:]]',
58
 
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9'],
 
63
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21'],
59
64
             [u'T', u'q', u' ', u'\u8336', u'.']),
60
65
            (u'[^[:digit:]]',
61
66
             [u'T', u'q', u' ', u'\u8336', u'.'],
62
 
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9']),
 
67
             [u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21']),
63
68
            ])
64
69
 
65
70
    def test_char_group_space(self):
308
313
            self.assertEqual(patterns[x],globster.match(filename))
309
314
        self.assertEqual(None,globster.match('foobar.300'))
310
315
 
 
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
 
311
325
class TestExceptionGlobster(TestCase):
312
326
 
313
327
    def test_exclusion_patterns(self):