/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 breezy/tests/test_lazy_regex.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    def test_invalid_pattern(self):
32
32
        error = lazy_regex.InvalidPattern('Bad pattern msg.')
33
33
        self.assertEqualDiff("Invalid pattern(s) found. Bad pattern msg.",
34
 
            str(error))
 
34
                             str(error))
35
35
 
36
36
 
37
37
class InstrumentedLazyRegex(lazy_regex.LazyRegex):
49
49
 
50
50
    def _real_re_compile(self, *args, **kwargs):
51
51
        self._actions.append(('_real_re_compile',
52
 
                                               args, kwargs))
 
52
                              args, kwargs))
53
53
        return super(InstrumentedLazyRegex, self)._real_re_compile(
54
54
            *args, **kwargs)
55
55
 
72
72
        self.assertEqual([('created regex', 'foo'),
73
73
                          ('__getattr__', 'match'),
74
74
                          ('_real_re_compile', ('foo',), {}),
75
 
                         ], actions)
 
75
                          ], actions)
76
76
 
77
77
    def test_bad_pattern(self):
78
78
        """Ensure lazy regex handles bad patterns cleanly."""
79
79
        p = lazy_regex.lazy_compile('RE:[')
80
80
        # As p.match is lazy, we make it into a lambda so its handled
81
81
        # by assertRaises correctly.
82
 
        e = self.assertRaises(lazy_regex.InvalidPattern, lambda: p.match('foo'))
 
82
        e = self.assertRaises(lazy_regex.InvalidPattern,
 
83
                              lambda: p.match('foo'))
83
84
        # Expect either old or new form of error message
84
85
        self.assertContainsRe(e.msg, '^"RE:\\[" '
85
 
            '(unexpected end of regular expression'
86
 
            '|unterminated character set at position 3)$')
 
86
                              '(unexpected end of regular expression'
 
87
                              '|unterminated character set at position 3)$')
87
88
 
88
89
 
89
90
class TestLazyCompile(tests.TestCase):
135
136
        pickled = pickle.dumps(lazy_pattern)
136
137
        unpickled_lazy_pattern = pickle.loads(pickled)
137
138
        self.assertEqual(['x', 'y', 'z'],
138
 
            unpickled_lazy_pattern.split('x,y;z'))
 
139
                         unpickled_lazy_pattern.split('x,y;z'))
139
140
 
140
141
 
141
142
class TestInstallLazyCompile(tests.TestCase):
157
158
        self.addCleanup(lazy_regex.install_lazy_compile)
158
159
        pattern = re.compile('foo')
159
160
        self.assertFalse(isinstance(pattern, lazy_regex.LazyRegex),
160
 
            'lazy_regex.reset_compile() did not restore the original'
161
 
            ' compile() function %s' % (type(pattern),))
 
161
                         'lazy_regex.reset_compile() did not restore the original'
 
162
                         ' compile() function %s' % (type(pattern),))
162
163
        # but the returned object should still support regex operations
163
164
        m = pattern.match('foo')
164
165
        self.assertEqual('foo', m.group())