Esempio n. 1
0
 def test_Xor(self):
     self.assertTrue(
         snipe.filters.Xor(No(), No(), Yes())._check(None))
     self.assertFalse(
         snipe.filters.Xor(No(), No(), No())._check(None))
     self.assertFalse(
         snipe.filters.Xor(No(), Yes(), Yes())._check(None))
Esempio n. 2
0
 def test_Certitude(self):
     yes = Yes()
     no = No()
     self.assertTrue(yes._check(None))
     self.assertTrue(yes.simplify({}))
     self.assertFalse(no._check(None))
     self.assertFalse(no.simplify({}))
     self.assertEqual(hash(Yes()), hash(yes))
     self.assertEqual(hash(No()), hash(no))
     self.assertNotEqual(hash(yes), hash(no))
Esempio n. 3
0
 def test_Not(self):
     self.assertEqual(str(Not(Yes())), 'not yes')
     self.assertEqual(repr(Not(Yes())), 'Not(Yes())')
     self.assertEqual(Not(Yes()), Not(Yes()))
     self.assertNotEqual(Not(Yes()), Not(No()))
     self.assertEqual(hash(Not(Yes())), hash(Not(Yes())))
     self.assertNotEqual(hash(Not(Yes())), hash(Not(No())))
     self.assertTrue(Not(No()).simplify({}))
     self.assertFalse(
         makefilter('not foo == "bar"').simplify({'foo': 'bar'}))
     self.assertEqual(
         makefilter('not foo == "bar"').simplify({}),
         Not(Compare('==', 'foo', 'bar')))
     self.assertEqual(str(Not(And(Yes(), No()))), 'not (yes and no)')
Esempio n. 4
0
 def test_Or(self):
     self.assertEqual(repr(Or(None, Yes(), No())), 'Or(Yes(), No())')
     self.assertTrue(Or(Yes(), Yes())._check(None))
     self.assertTrue(Or(Yes(), No())._check(None))
     self.assertFalse(Or(No(), No())._check(None))
     self.assertTrue(Or(Yes(), Yes()).simplify({}))
     self.assertTrue(Or(Yes(), No()).simplify({}))
     self.assertTrue(Or(Yes(), Truth('foo')).simplify({}))
     self.assertEqual(Or(Truth('foo'), No()).simplify({}), Truth('foo'))
     self.assertEqual(
         Or(No(), Truth('foo'), Truth('bar')).simplify({}),
         Or(Truth('foo'), Truth('bar')).simplify({}))
     self.assertFalse(Or().simplify(None))
Esempio n. 5
0
    def test_Parser(self):
        snipe.filters.parser = Parser(debug=True)
        self.assertEqual(makefilter('yes'), Yes())
        self.assertEqual(makefilter('yes and no'), And(Yes(), No()))
        self.assertEqual(makefilter('foo = "bar"'), Compare('=', 'foo', 'bar'))
        self.assertEqual(makefilter('foo < "bar"'), Compare('<', 'foo', 'bar'))
        self.assertEqual(makefilter('"bar" = foo'), Compare('=', 'foo', 'bar'))
        self.assertEqual(makefilter('foo = bar'),
                         Compare('=', 'foo', Identifier('bar')))
        self.assertEqual(makefilter('foo = /bar/'),
                         RECompare('=', 'foo', 'bar'))
        self.assertEqual(makefilter('/bar/ = foo'),
                         RECompare('=', 'foo', 'bar'))
        self.assertEqual(makefilter('1 = 1'), Yes())
        self.assertEqual(makefilter('1 = 2'), No())
        self.assertEqual(makefilter('"foo" = /foo/'), Yes())
        self.assertEqual(makefilter('"foo" = /bar/'), No())
        self.assertEqual(makefilter('"Foo" = /foo/i'), Yes())
        self.assertEqual(makefilter('"Foo" != /foo/i'), No())
        self.assertEqual(makefilter('(yes or no) and yes'),
                         And(Or(Yes(), No()), Yes()))
        self.assertEqual(makefilter('yes xor no'), Xor(Yes(), No()))

        self.assertTrue(makefilter('foo = "bar"')(mocks.Message(foo='bar')))
        self.assertFalse(makefilter('foo = "bar"')(mocks.Message(foo='baz')))

        self.assertTrue(makefilter('foo = /b.*/')(mocks.Message(foo='bar')))
        self.assertTrue(makefilter('foo = /b.*/')(mocks.Message(foo='baz')))
        self.assertFalse(makefilter('foo = /b.*/')(mocks.Message(foo='quux')))

        self.assertTrue(
            makefilter('foo = bar')(mocks.Message(foo='quux', bar='quux')))

        self.assertFalse(
            makefilter('foo = bar')(mocks.Message(foo='quux', bar='quuux')))

        self.assertTrue(
            makefilter('foo = "bar"')(mocks.Message(
                foo='Bar',
                Foo='bar',
            )))
        self.assertFalse(
            makefilter('not foo = "bar"')(mocks.Message(
                foo='Bar',
                Foo='bar',
            )))
        self.assertFalse(
            makefilter('foo == "bar"')(mocks.Message(
                foo='Bar',
                Foo='bar',
            )))
        self.assertTrue(
            makefilter('foo = /bar/')(mocks.Message(
                foo='Bar',
                Foo='bar',
            )))
        self.assertFalse(
            makefilter('foo == /bar/')(mocks.Message(
                foo='Bar',
                Foo='bar',
            )))
        self.assertFalse(
            makefilter('foo == /bar[/')(mocks.Message(
                foo='Bar',
                Foo='bar',
            )))

        self.assertEqual(str(makefilter('foo == "bar"')), 'foo == "bar"')
        self.assertEqual(str(makefilter('"bar" == foo')), 'foo == "bar"')

        self.assertEqual(str(makefilter('yes and yes and yes')),
                         'yes and yes and yes')

        self.assertEqual(str(makefilter('no and yes and yes')),
                         'no and yes and yes')

        self.assertEqual(str(makefilter('yes and no and yes')),
                         'yes and no and yes')

        self.assertEqual(str(makefilter('yes and yes and no')),
                         'yes and yes and no')

        self.assertTrue(makefilter('foo')(mocks.Message(foo=True)))
        self.assertFalse(makefilter('foo')(mocks.Message(foo=0)))
        self.assertFalse(makefilter('foo')(mocks.Message(foo=0)))

        self.assertIs(makefilter(''), None)

        self.assertFalse(makefilter('filter foo')(mocks.Message()))
Esempio n. 6
0
 def test_And(self):
     self.assertEqual(repr(And(None, Yes(), No())), 'And(Yes(), No())')
     self.assertTrue(And(Yes(), Yes())._check(None))
     self.assertFalse(And(Yes(), No())._check(None))
     self.assertTrue(And(Yes(), Yes()).simplify({}))
     self.assertFalse(And(Yes(), No()).simplify({}))
     self.assertFalse(And(Truth('foo'), No()).simplify({}))
     self.assertEqual(And(Yes(), Truth('foo')).simplify({}), Truth('foo'))
     self.assertEqual(
         And(Yes(), Truth('foo'), Truth('bar')).simplify({}),
         And(Truth('foo'), Truth('bar')).simplify({}))
     self.assertTrue(And().simplify(None))
     self.assertEqual(hash(And(Yes(), No())), hash(And(Yes(), No())))