~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lazy_regex.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-05-04 12:10:51 UTC
  • mfrom: (5819.1.4 777007-developer-doc)
  • Revision ID: pqm@pqm.ubuntu.com-20110504121051-aovlsmqiivjmc4fc
(jelmer) Small fixes to developer documentation. (Jonathan Riddell)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Test that lazy regexes are not compiled right away"""
18
18
 
19
19
import re
20
20
 
 
21
from bzrlib import errors
21
22
from bzrlib import (
22
23
    lazy_regex,
23
24
    tests,
63
64
                          ('_real_re_compile', ('foo',), {}),
64
65
                         ], actions)
65
66
 
 
67
    def test_bad_pattern(self):
 
68
        """Ensure lazy regex handles bad patterns cleanly."""
 
69
        p = lazy_regex.lazy_compile('RE:[')
 
70
        # As p.match is lazy, we make it into a lambda so its handled
 
71
        # by assertRaises correctly.
 
72
        e = self.assertRaises(errors.InvalidPattern, lambda: p.match('foo'))
 
73
        self.assertEqual(e.msg, '"RE:[" unexpected end of regular expression')
 
74
 
66
75
 
67
76
class TestLazyCompile(tests.TestCase):
68
77
 
121
130
        lazy_regex.install_lazy_compile()
122
131
        lazy_regex.reset_compile()
123
132
        pattern = re.compile('foo')
124
 
        self.failIf(isinstance(pattern, lazy_regex.LazyRegex),
 
133
        self.assertFalse(isinstance(pattern, lazy_regex.LazyRegex),
125
134
                    'lazy_regex.reset_compile() did not restore the original'
126
135
                    ' compile() function %s' % (type(pattern),))
127
136
        # but the returned object should still support regex operations