Beispiel #1
0
    def testInvalidBoolExprInput(self):
        """Test invalid boolean expression.

    Test whether captures the exceptions caused by invalid boolean expression
    input. Note that only the lowercase and, or, not are allowed.
    """

        with self.assertRaises(boolparse_lib.BoolParseError):
            boolparse_lib.BoolstrResult('', {'A'})
        with self.assertRaises(TypeError):
            boolparse_lib.BoolstrResult(None, {'A'})
Beispiel #2
0
 def testComplexBoolExpr(self):
     self.assertFalse(boolparse_lib.BoolstrResult('A and not B', {}))
     self.assertTrue(boolparse_lib.BoolstrResult('A and not B', {'A'}))
     self.assertFalse(boolparse_lib.BoolstrResult('A and not B',
                                                  {'A', 'B'}))
     self.assertTrue(boolparse_lib.BoolstrResult('not (A and B)', {'A'}))
     self.assertFalse(
         boolparse_lib.BoolstrResult('not (A and B)', {'A', 'B'}))
     self.assertTrue(boolparse_lib.BoolstrResult('A or not B', {'A'}))
     self.assertTrue(boolparse_lib.BoolstrResult('A or not B', {'A', 'B'}))
     self.assertFalse(boolparse_lib.BoolstrResult('A or not B', {'B'}))
     self.assertTrue(boolparse_lib.BoolstrResult('A or not B', {'C'}))
Beispiel #3
0
 def testVariousOperand(self):
     """Test on various operand format."""
     self.assertFalse(
         boolparse_lib.BoolstrResult('A:foo and B:foo', {'A:foo'}))
Beispiel #4
0
    def testCollectionInput(self):
        """Test whether handle different types of collection input."""

        self.assertFalse(boolparse_lib.BoolstrResult('A', None))
        self.assertTrue(boolparse_lib.BoolstrResult('A', ['A', 'A']))
        self.assertFalse(boolparse_lib.BoolstrResult('not A', ('A', 'B', 'B')))
Beispiel #5
0
 def testNotlogic(self):
     self.assertTrue(boolparse_lib.BoolstrResult('not A', {}))
     self.assertFalse(boolparse_lib.BoolstrResult('not A', {'A'}))
     self.assertFalse(boolparse_lib.BoolstrResult('not A', {'A', 'B'}))
     self.assertTrue(boolparse_lib.BoolstrResult('not A', {'B'}))
     self.assertTrue(boolparse_lib.BoolstrResult('not not A', {'A'}))
Beispiel #6
0
 def testOrlogic(self):
     self.assertFalse(boolparse_lib.BoolstrResult('A or B', {}))
     self.assertTrue(boolparse_lib.BoolstrResult('A or B', {'B'}))
     self.assertTrue(boolparse_lib.BoolstrResult('A or B', {'A', 'B'}))
     self.assertTrue(boolparse_lib.BoolstrResult('A or B', {'A', 'C'}))
     self.assertFalse(boolparse_lib.BoolstrResult('A or B', {'C'}))
Beispiel #7
0
 def testAndlogic(self):
     self.assertFalse(boolparse_lib.BoolstrResult('A and B', {}))
     self.assertFalse(boolparse_lib.BoolstrResult('A and B', {}))
     self.assertTrue(boolparse_lib.BoolstrResult('A and B',
                                                 {'A', 'B', 'C'}))
Beispiel #8
0
 def testSingleItem(self):
     self.assertFalse(boolparse_lib.BoolstrResult('A', {}))
     self.assertTrue(boolparse_lib.BoolstrResult('A', {'A', 'B'}))
     self.assertFalse(boolparse_lib.BoolstrResult('A', {'B'}))