コード例 #1
0
    def test_04_compare_matches(self):
        self.assertTrue(compare_values("hello world", "matches",
                                       "hello world"))
        self.assertTrue(compare_values("hello world", "matches", ".*world"))
        self.assertTrue(
            compare_values("uid=hello,cn=users,dc=test,dc=intranet", "matches",
                           "uid=[^,]+,cn=users,dc=test,dc=intranet"))
        # only complete matches
        self.assertFalse(compare_values("hello world", "matches", "world"))
        self.assertFalse(
            compare_values("uid=hello,cn=users,dc=test,dc=intranet,dc=world",
                           "matches",
                           "uid=[^,]+,cn=users,dc=test,dc=intranet"))
        # supports more advanced regex features
        self.assertTrue(
            compare_values("hElLo WoRLd", "matches",
                           "(?i)hello world( and stuff)?"))
        # raises errors on invalid patterns
        with self.assertRaises(CompareError):
            compare_values("hello world", "matches", "this is (invalid")

        # negation
        self.assertTrue(
            compare_values("uid=hello,cn=users,dc=test,dc=intranet",
                           "!matches",
                           "uid=[^,]+,cn=admins,dc=test,dc=intranet"))
        self.assertFalse(
            compare_values("uid=hello,cn=admins,dc=test,dc=intranet",
                           "!matches",
                           "uid=[^,]+,cn=admins,dc=test,dc=intranet"))
コード例 #2
0
    def test_02_compare_contains(self):
        self.assertTrue(compare_values(["hello", "world"], "contains", "hello"))
        self.assertTrue(compare_values(["hello", "world"], "contains", "world"))
        self.assertTrue(compare_values([1, "world"], "contains", 1))
        self.assertFalse(compare_values([1, "world"], "contains", [1, "world"]))

        # must pass a list
        with self.assertRaises(CompareError):
            compare_values("hello world", "contains", "hello")

        # negation
        self.assertTrue(compare_values([1, "world"], "!contains", "hello"))
        self.assertFalse(compare_values([1, "world"], "!contains", "world"))
        with self.assertRaises(CompareError):
            compare_values("hello world", "!contains", "hello")
コード例 #3
0
    def test_06_compare_in(self):
        self.assertTrue(compare_values("hello", "in", "hello"))
        self.assertTrue(compare_values("world", "in", "hello, world, this is a list"))
        self.assertFalse(compare_values("hello", "in", "hello world"))
        self.assertFalse(compare_values("hello,world", "in", 'hello,world'))
        self.assertTrue(compare_values("hello,world", "in", '"hello,world"'))

        # negation
        self.assertTrue(compare_values("hello", "!in", "world"))
        self.assertFalse(compare_values("hello", "!in", " hello, world"))
        self.assertTrue(compare_values("hello", "!in", "hello world"))
コード例 #4
0
 def test_01_compare_equal(self):
     self.assertTrue(compare_values("hello", "equals", "hello"))
     self.assertTrue(compare_values(1, "equals", 1))
     self.assertFalse(compare_values("hello", "equals", " hello"))
     self.assertFalse(compare_values(1, "equals", 2))
     self.assertFalse(compare_values(1, "equals", "1"))
     # negation
     self.assertFalse(compare_values("hello", "!equals", "hello"))
     self.assertTrue(compare_values(1, "!equals", "1"))
コード例 #5
0
 def test_03_compare_errors(self):
     with self.assertRaises(CompareError) as cm:
         compare_values("hello world", "something", "hello")
     self.assertIn("Invalid comparator", repr(cm.exception))
コード例 #6
0
 def test_07_smaller_and_bigger(self):
     self.assertTrue(compare_values("1", "<", 2))
     self.assertTrue(compare_values(7, ">", 1))
     self.assertFalse(compare_values("2", "<", "1"))
     self.assertFalse(compare_values(2, "<", 1))
     self.assertFalse(compare_values(2, ">", "2"))
コード例 #7
0
 def test_01_compare_equal(self):
     self.assertTrue(compare_values("hello", "==", "hello"))
     self.assertTrue(compare_values(1, "==", 1))
     self.assertFalse(compare_values("hello", "==", " hello"))
     self.assertFalse(compare_values(1, "==", 2))
     self.assertFalse(compare_values(1, "==", "1"))