Add tests for RegexEq
...also fix a small typo in RegexEq's comment.
This commit is contained in:
parent
05bcddb6f9
commit
3e2985d776
@ -75,7 +75,7 @@ class RegexEq:
|
|||||||
|
|
||||||
def __init__(self, pattern, flags=0):
|
def __init__(self, pattern, flags=0):
|
||||||
# We compile the regex because re.compile also adds flags defined in
|
# We compile the regex because re.compile also adds flags defined in
|
||||||
# the pattern and implicit flags to it's .flags.
|
# the pattern and implicit flags to its .flags.
|
||||||
# See https://docs.python.org/3/library/re.html#re.regex.flags
|
# See https://docs.python.org/3/library/re.html#re.regex.flags
|
||||||
compiled = re.compile(pattern, flags)
|
compiled = re.compile(pattern, flags)
|
||||||
self.pattern = compiled.pattern
|
self.pattern = compiled.pattern
|
||||||
@ -1901,3 +1901,29 @@ class TestUserAgent:
|
|||||||
def test_complete(self, klass):
|
def test_complete(self, klass):
|
||||||
"""Simple smoke test for completion."""
|
"""Simple smoke test for completion."""
|
||||||
klass().complete()
|
klass().complete()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('first, second, equal', [
|
||||||
|
(re.compile('foo'), RegexEq('foo'), True),
|
||||||
|
(RegexEq('bar'), re.compile('bar'), True),
|
||||||
|
(RegexEq('qwer'), RegexEq('qwer'), True),
|
||||||
|
(re.compile('qux'), RegexEq('foo'), False),
|
||||||
|
(RegexEq('spam'), re.compile('eggs'), False),
|
||||||
|
(RegexEq('qwer'), RegexEq('rewq'), False),
|
||||||
|
|
||||||
|
(re.compile('foo', re.I), RegexEq('foo', re.I), True),
|
||||||
|
(RegexEq('bar', re.M), re.compile('bar', re.M), True),
|
||||||
|
(re.compile('qux', re.M), RegexEq('qux', re.I), False),
|
||||||
|
(RegexEq('spam', re.S), re.compile('eggs', re.S), False),
|
||||||
|
|
||||||
|
(re.compile('(?i)foo'), RegexEq('(?i)foo'), True),
|
||||||
|
(re.compile('(?i)bar'), RegexEq('bar'), False),
|
||||||
|
])
|
||||||
|
def test_regex_eq(first, second, equal):
|
||||||
|
if equal:
|
||||||
|
# Assert that the check is commutative
|
||||||
|
assert first == second
|
||||||
|
assert second == first
|
||||||
|
else:
|
||||||
|
assert first != second
|
||||||
|
assert second != first
|
||||||
|
Loading…
Reference in New Issue
Block a user