Exemple #1
0
    def test_multiple_conflicting_constraints(self):
        """Test multiple conflicting constraint in nested constrain()'s."""
        b = BooleanExpression('A xor B xor C')
        with self.assertRaises(AlreadyConstrainedSymbolError) as cm:
            with b.constrain(A=1, B=0, C=1):
                with b.constrain(B=0, A=1):
                    pass

        self.assertIn('Symbols "A", "B"', str(cm.exception))
Exemple #2
0
    def test_single_conflicting_nested_constraint(self):
        """Test single conflicting constraint in nested constrain()'s."""
        b = BooleanExpression('A or B')
        with self.assertRaises(AlreadyConstrainedSymbolError) as cm:
            with b.constrain(A=1):
                with b.constrain(A=1):
                    pass

        self.assertIn('Symbol "A"', str(cm.exception))
Exemple #3
0
 def test_deep_conflicting_nested_constraint(self):
     """Test a conflict that occurs in a deeply nested context manager."""
     b = BooleanExpression('A and B and C and D and E')
     with self.assertRaises(AlreadyConstrainedSymbolError) as cm:
         with b.constrain(A=0):
             with b.constrain(B=0):
                 with b.constrain(C=0):
                     with b.constrain(D=0):
                         with b.constrain(E=0):
                             with b.constrain(B=0, D=0, E=1):
                                 pass
     self.assertIn('Symbols "B", "D", "E"', str(cm.exception))
Exemple #4
0
 def test_invalid_boolean_value(self):
     """Test passing an invalid Boolean value for a constraint."""
     b = BooleanExpression('A or B')
     with self.assertRaises(InvalidBooleanValueError):
         with b.constrain(B='a string'):
             pass
Exemple #5
0
 def test_invalid_symbol(self):
     """Test passing a symbol not present in the expression."""
     b = BooleanExpression('A or B')
     with self.assertRaises(ExtraSymbolError):
         with b.constrain(C=0):
             pass
Exemple #6
0
 def test_empty_constraints(self):
     """Test passing no constraints through kwargs."""
     b = BooleanExpression('A or B')
     with self.assertRaises(InvalidArgumentValueError):
         with b.constrain():
             pass