Пример #1
0
 def test_namespace_to_regex(self):
     """Test regex creation."""
     self.assertEqual(
         namespace_to_regex("db*.foo"), re.compile(r"\Adb([^.]*)\.foo\Z")
     )
     self.assertEqual(namespace_to_regex("db.foo*"), re.compile(r"\Adb\.foo(.*)\Z"))
     self.assertEqual(namespace_to_regex("db.foo"), re.compile(r"\Adb\.foo\Z"))
 def test_from_namespaces(self):
     """Test construction from list of namespaces."""
     self.assertEqual(RegexSet.from_namespaces([]), RegexSet([], []))
     self.assertEqual(
         RegexSet.from_namespaces(["db.bar", "db_*.foo", "db2.*"]),
         RegexSet(
             [namespace_to_regex("db_*.foo"),
              namespace_to_regex("db2.*")], ["db.bar"]))
Пример #3
0
 def test_from_namespaces(self):
     """Test construction from list of namespaces."""
     self.assertEqual(RegexSet.from_namespaces([]),
                      RegexSet([], []))
     self.assertEqual(RegexSet.from_namespaces(["db.bar", "db_*.foo",
                                                "db2.*"]),
                      RegexSet([namespace_to_regex("db_*.foo"),
                                namespace_to_regex("db2.*")],
                               ["db.bar"]))
Пример #4
0
 def test_namespace_to_regex_escapes_metacharacters(self):
     """Test regex creation escapes metacharacters."""
     self.assertEqual(
         namespace_to_regex("db&*.$a^a#a!a[a]a"),
         re.compile(r"\Adb\&([^.]*)\.\$a\^a\#a!a\[a\]a\Z"),
     )
     self.assertEqual(
         namespace_to_regex("db.$a^a#a!a[a]a*"),
         re.compile(r"\Adb\.\$a\^a\#a!a\[a\]a(.*)\Z"),
     )