def test_unicode_equivalence(self): assert compile(u"\u212B")(u"\u00C5") assert compile(u"\u00C5")(u"\u212B") assert compile(u"A\u030a")(u"\u00C5") assert compile(u"A\u030a")(u"\u212B") assert compile(u"o\u0308")(u"o\u0308") assert compile(u"o\u0308")(u"\xf6") assert compile(u"\xf6")(u"o\u0308")
def __init__(self, pattern, mod_string): self.pattern = text_type(pattern) self.mod_string = text_type(mod_string) ignore_case = "c" not in self.mod_string or "i" in self.mod_string dot_all = "s" in self.mod_string asym = "d" in self.mod_string try: self.search = compile(self.pattern, ignore_case, dot_all, asym) except ValueError: raise ParseError( "The regular expression /%s/ is invalid." % self.pattern)
def test_invalid(self): with self.assertRaises(ValueError): compile(u"(F", asym=False) with self.assertRaises(ValueError): compile(u"(F", asym=True)
def test_assert_asym_unicode_equivalence(self): assert compile(u"A", asym=True)(u"\u00C5") assert compile(u"A\u030a", asym=True)(u"\u212B") assert compile(u"\u00C5", asym=True)(u"\u212B") assert compile(u"\u212B", asym=True)(u"\u00C5")
def test_assert_asym(self): assert compile(u"o", asym=True)(u"ö") assert not compile(u"o", asym=False)(u"ö")
def test_assert_dot_all(self): assert compile(u"a.b", dot_all=True)(u"a\nb") assert not compile(u"a.b", dot_all=False)(u"a\nb") assert compile(u"a.b", dot_all=False)(u"a b")
def test_ignore_case(self): assert compile(u"foo", ignore_case=True)(u"Foo") assert not compile(u"foo", ignore_case=False)(u"Foo")
def test_basics_default(self): assert compile(u"foo")(u"foo") assert compile(u"foo")(u"fooo") assert not compile(u"foo")(u"fo")