Esempio n. 1
0
    def testError(self):
        # Invalid field names, meaning no boolean check is done
        tests = ["#invalid!filter#", "m/x/,"]

        # Unknown regexp flag
        tests.append("name=~m#a#g")

        # Incomplete regexp group
        tests.append("name=~^[^")

        # Valid flag, but in uppercase
        tests.append("asdf =~ m|abc|I")

        # Non-matching regexp delimiters
        tests.append("name =~ /foobarbaz#")

        # Invalid operators
        tests.append("name <> value")
        tests.append("name => value")
        tests.append("name =< value")

        for qfilter in tests:
            try:
                qlang.ParseFilter(qfilter, parser=self.parser)
            except errors.QueryFilterParseError as err:
                self.assertEqual(len(err.GetDetails()), 3)
            else:
                self.fail("Invalid filter '%s' did not raise exception" %
                          qfilter)
Esempio n. 2
0
 def _Test(self, qfilter, expected, expect_filter=True):
     self.assertEqual(qlang.MakeFilter([qfilter], not expect_filter),
                      expected)
     self.assertEqual(qlang.ParseFilter(qfilter, parser=self.parser),
                      expected)