~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lazy_regex.py

  • Committer: Vincent Ladeuil
  • Date: 2010-09-28 08:57:31 UTC
  • mto: (5490.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 5492.
  • Revision ID: v.ladeuil+lp@free.fr-20100928085731-8h0duqj5wf4acsgy
Add -m to search for a regexp in news entries instead of the bug number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2011 Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Test that lazy regexes are not compiled right away"""
18
18
 
19
 
import pickle
20
19
import re
21
20
 
22
21
from bzrlib import errors
42
41
    def _real_re_compile(self, *args, **kwargs):
43
42
        self._actions.append(('_real_re_compile',
44
43
                                               args, kwargs))
45
 
        return super(InstrumentedLazyRegex, self)._real_re_compile(
46
 
            *args, **kwargs)
 
44
        return super(InstrumentedLazyRegex, self)._real_re_compile(*args, **kwargs)
47
45
 
48
46
 
49
47
class TestLazyRegex(tests.TestCase):
116
114
        pattern = lazy_regex.lazy_compile('[,;]*')
117
115
        self.assertEqual(['x', 'y', 'z'], pattern.split('x,y;z'))
118
116
 
119
 
    def test_pickle(self):
120
 
        # When pickling, just compile the regex.
121
 
        # Sphinx, which we use for documentation, pickles
122
 
        # some compiled regexes.
123
 
        lazy_pattern = lazy_regex.lazy_compile('[,;]*')
124
 
        pickled = pickle.dumps(lazy_pattern)
125
 
        unpickled_lazy_pattern = pickle.loads(pickled)
126
 
        self.assertEqual(['x', 'y', 'z'],
127
 
            unpickled_lazy_pattern.split('x,y;z'))
128
 
 
129
117
 
130
118
class TestInstallLazyCompile(tests.TestCase):
131
 
    """Tests for lazy compiled regexps.
132
119
 
133
 
    Other tests, and bzrlib in general, count on the lazy regexp compiler
134
 
    being installed, and this is done by loading bzrlib.  So these tests
135
 
    assume it is installed, and leave it installed when they're done.
136
 
    """
 
120
    def setUp(self):
 
121
        super(TestInstallLazyCompile, self).setUp()
 
122
        self.addCleanup(lazy_regex.reset_compile)
137
123
 
138
124
    def test_install(self):
139
 
        # Don't count on it being present
140
125
        lazy_regex.install_lazy_compile()
141
126
        pattern = re.compile('foo')
142
127
        self.assertIsInstance(pattern, lazy_regex.LazyRegex)
143
128
 
144
129
    def test_reset(self):
 
130
        lazy_regex.install_lazy_compile()
145
131
        lazy_regex.reset_compile()
146
 
        self.addCleanup(lazy_regex.install_lazy_compile)
147
132
        pattern = re.compile('foo')
148
 
        self.assertFalse(isinstance(pattern, lazy_regex.LazyRegex),
149
 
            'lazy_regex.reset_compile() did not restore the original'
150
 
            ' compile() function %s' % (type(pattern),))
 
133
        self.failIf(isinstance(pattern, lazy_regex.LazyRegex),
 
134
                    'lazy_regex.reset_compile() did not restore the original'
 
135
                    ' compile() function %s' % (type(pattern),))
151
136
        # but the returned object should still support regex operations
152
137
        m = pattern.match('foo')
153
138
        self.assertEqual('foo', m.group())