Пример #1
0
 def assertResults(self, expression, sym_tab, results):
     self.assertEqual(
         list(
             map((
                 lambda args: interpret(expression, {
                     symbol: args[i]
                     for i, symbol in enumerate(sym_tab.keys())
                 })), zip(*tuple(sym_tab.values())))),
         results,
     )
Пример #2
0
def get_matching_ids(query):
    bitmap_all = BitMap(Photo.objects.values_list("id", flat=True))

    # XXX: hacky
    NegBitMap.__invert__ = lambda self: self ^ bitmap_all

    bitmaps = {l: NegBitMap() for l in LABELS.values()}

    for (photo_id, label) in Object.objects.values_list("photo_id", "label"):
        bitmaps[label].add(photo_id)

    return interpret(query, bitmaps)
Пример #3
0
    def test_constant_evaluates_to_its_truthness(self):
        self.assertTrue(interpret('"string"', {}))
        self.assertTrue(interpret('True', {}))
        self.assertTrue(interpret('42', {}))

        self.assertFalse(interpret('0', {}))
        self.assertFalse(interpret('""', {}))
        self.assertFalse(interpret('False', {}))
Пример #4
0
    def test_variable_evaluates_to_its_truthness(self):
        self.assertTrue(interpret('x', {'x': True}))
        self.assertTrue(interpret('x', {'x': 'false'}))
        self.assertTrue(interpret('x', {'x': 42}))

        self.assertFalse(interpret('x', {'x': ''}))
        self.assertFalse(interpret('x', {'x': False}))
        self.assertFalse(interpret('x', {'x': 0}))
Пример #5
0
 def test_interpreter__basic(self):
     text = 'x > 42'
     self.assertTrue(interpret(text, {'x': 50}))
     self.assertFalse(interpret(text, {'x': 10}))
Пример #6
0
 def test_empty_expr_evaluates_to_true(self):
     self.assertTrue(interpret('', {}))
Пример #7
0
 def test_operators_precedence(self):
     sym_tab = {
         'x': 1,
         'y': 'not eligible',
     }
     self.assertTrue(interpret(fixtures.operators_precedence, sym_tab))
Пример #8
0
 def test_undefined(self):
     with self.assertRaises(BambooleanInterpreterError):
         interpret('x', {})
Пример #9
0
 def test_multi_not(self):
     self.assertTrue(interpret('not not x', {'x': True}))
Пример #10
0
 def test_not(self):
     self.assertTrue(interpret('not x', {'x': False}))