Esempio n. 1
0
    def test_basic(self):

        v1, v2, v3 = version_objects()
        vs = [v1, v2, v3]

        t1 = v1["committed"]
        t2 = v2["committed"]
        t3 = v3["committed"]

        fkgtA = Filter("key", ">", "/A")

        self.assertTrue(fkgtA(v1))
        self.assertTrue(fkgtA(v2))
        self.assertTrue(fkgtA(v3))

        self.assertTrue(fkgtA.valuePasses("/BCDEG"))
        self.assertTrue(fkgtA.valuePasses("/ZCDEFDSA/fdsafdsa/fdsafdsaf"))
        self.assertFalse(fkgtA.valuePasses("/6353456346543"))
        self.assertFalse(fkgtA.valuePasses("."))
        self.assertTrue(fkgtA.valuePasses("afsdafdsa"))

        self.assertFilter(fkgtA, vs, vs)

        fkltA = Filter("key", "<", "/A")

        self.assertFalse(fkltA(v1))
        self.assertFalse(fkltA(v2))
        self.assertFalse(fkltA(v3))

        self.assertFalse(fkltA.valuePasses("/BCDEG"))
        self.assertFalse(fkltA.valuePasses("/ZCDEFDSA/fdsafdsa/fdsafdsaf"))
        self.assertTrue(fkltA.valuePasses("/6353456346543"))
        self.assertTrue(fkltA.valuePasses("."))
        self.assertFalse(fkltA.valuePasses("A"))
        self.assertFalse(fkltA.valuePasses("afsdafdsa"))

        self.assertFilter(fkltA, vs, [])

        fkeqA = Filter("key", "=", "/ABCD")

        self.assertTrue(fkeqA(v1))
        self.assertTrue(fkeqA(v2))
        self.assertTrue(fkeqA(v3))

        self.assertFalse(fkeqA.valuePasses("/BCDEG"))
        self.assertFalse(fkeqA.valuePasses("/ZCDEFDSA/fdsafdsa/fdsafdsaf"))
        self.assertFalse(fkeqA.valuePasses("/6353456346543"))
        self.assertFalse(fkeqA.valuePasses("A"))
        self.assertFalse(fkeqA.valuePasses("."))
        self.assertFalse(fkeqA.valuePasses("afsdafdsa"))
        self.assertTrue(fkeqA.valuePasses("/ABCD"))

        self.assertFilter(fkeqA, vs, vs)
        self.assertFilter([fkeqA, fkltA], vs, [])
        self.assertFilter([fkeqA, fkeqA], vs, vs)

        fkgtB = Filter("key", ">", "/B")

        self.assertFalse(fkgtB(v1))
        self.assertFalse(fkgtB(v2))
        self.assertFalse(fkgtB(v3))

        self.assertFalse(fkgtB.valuePasses("/A"))
        self.assertTrue(fkgtB.valuePasses("/BCDEG"))
        self.assertTrue(fkgtB.valuePasses("/ZCDEFDSA/fdsafdsa/fdsafdsaf"))
        self.assertFalse(fkgtB.valuePasses("/6353456346543"))
        self.assertFalse(fkgtB.valuePasses("."))
        self.assertTrue(fkgtB.valuePasses("A"))
        self.assertTrue(fkgtB.valuePasses("afsdafdsa"))

        self.assertFilter(fkgtB, vs, [])
        self.assertFilter([fkgtB, fkgtA], vs, [])
        self.assertFilter([fkgtB, fkgtB], vs, [])

        fkltB = Filter("key", "<", "/B")

        self.assertTrue(fkltB(v1))
        self.assertTrue(fkltB(v2))
        self.assertTrue(fkltB(v3))

        self.assertTrue(fkltB.valuePasses("/A"))
        self.assertFalse(fkltB.valuePasses("/BCDEG"))
        self.assertFalse(fkltB.valuePasses("/ZCDEFDSA/fdsafdsa/fdsafdsaf"))
        self.assertTrue(fkltB.valuePasses("/6353456346543"))
        self.assertTrue(fkltB.valuePasses("."))
        self.assertFalse(fkltB.valuePasses("A"))
        self.assertFalse(fkltB.valuePasses("afsdafdsa"))

        self.assertFilter(fkltB, vs, vs)

        fkgtAB = Filter("key", ">", "/AB")

        self.assertTrue(fkgtAB(v1))
        self.assertTrue(fkgtAB(v2))
        self.assertTrue(fkgtAB(v3))

        self.assertFalse(fkgtAB.valuePasses("/A"))
        self.assertTrue(fkgtAB.valuePasses("/BCDEG"))
        self.assertTrue(fkgtAB.valuePasses("/ZCDEFDSA/fdsafdsa/fdsafdsaf"))
        self.assertFalse(fkgtAB.valuePasses("/6353456346543"))
        self.assertFalse(fkgtAB.valuePasses("."))
        self.assertTrue(fkgtAB.valuePasses("A"))
        self.assertTrue(fkgtAB.valuePasses("afsdafdsa"))

        self.assertFilter(fkgtAB, vs, vs)
        self.assertFilter([fkgtAB, fkltB], vs, vs)
        self.assertFilter([fkltB, fkgtAB], vs, vs)

        fgtet1 = Filter("committed", ">=", t1)
        fgtet2 = Filter("committed", ">=", t2)
        fgtet3 = Filter("committed", ">=", t3)

        self.assertTrue(fgtet1(v1))
        self.assertTrue(fgtet1(v2))
        self.assertTrue(fgtet1(v3))

        self.assertFalse(fgtet2(v1))
        self.assertTrue(fgtet2(v2))
        self.assertTrue(fgtet2(v3))

        self.assertFalse(fgtet3(v1))
        self.assertFalse(fgtet3(v2))
        self.assertTrue(fgtet3(v3))

        self.assertFilter(fgtet1, vs, vs)
        self.assertFilter(fgtet2, vs, [v2, v3])
        self.assertFilter(fgtet3, vs, [v3])

        fltet1 = Filter("committed", "<=", t1)
        fltet2 = Filter("committed", "<=", t2)
        fltet3 = Filter("committed", "<=", t3)

        self.assertTrue(fltet1(v1))
        self.assertFalse(fltet1(v2))
        self.assertFalse(fltet1(v3))

        self.assertTrue(fltet2(v1))
        self.assertTrue(fltet2(v2))
        self.assertFalse(fltet2(v3))

        self.assertTrue(fltet3(v1))
        self.assertTrue(fltet3(v2))
        self.assertTrue(fltet3(v3))

        self.assertFilter(fltet1, vs, [v1])
        self.assertFilter(fltet2, vs, [v1, v2])
        self.assertFilter(fltet3, vs, vs)

        self.assertFilter([fgtet2, fltet2], vs, [v2])
        self.assertFilter([fgtet1, fltet3], vs, vs)
        self.assertFilter([fgtet3, fltet1], vs, [])

        feqt1 = Filter("committed", "=", t1)
        feqt2 = Filter("committed", "=", t2)
        feqt3 = Filter("committed", "=", t3)

        self.assertTrue(feqt1(v1))
        self.assertFalse(feqt1(v2))
        self.assertFalse(feqt1(v3))

        self.assertFalse(feqt2(v1))
        self.assertTrue(feqt2(v2))
        self.assertFalse(feqt2(v3))

        self.assertFalse(feqt3(v1))
        self.assertFalse(feqt3(v2))
        self.assertTrue(feqt3(v3))

        self.assertFilter(feqt1, vs, [v1])
        self.assertFilter(feqt2, vs, [v2])
        self.assertFilter(feqt3, vs, [v3])
Esempio n. 2
0
 def assertFilter(self, filter, objects, match):
     result = [o for o in Filter.filter(filter, objects)]
     self.assertEqual(result, match)