Example #1
0
    def assert_parse_with_error_contains_message(text, error_message):
        parser = TagExpressionParser()
        with pytest.raises(TagExpressionError) as exc_info:
            parser.parse(text)

        exc_text = exc_info.exconly()
        print(exc_text)
        assert error_message in exc_text
Example #2
0
 def test_not_not_expression_sameas_expression(self, tag_expression_text, expected, tags, case):
     not2_tag_expression_text = "not not "+ tag_expression_text
     tag_expression1 = TagExpressionParser.parse(tag_expression_text)
     tag_expression2 = TagExpressionParser.parse(not2_tag_expression_text)
     value1 = tag_expression1.evaluate(tags)
     value2 = tag_expression2.evaluate(tags)
     assert value1 == value2
     assert expected == value1
Example #3
0
    def assert_parse_with_error_contains_message(text, error_message):
        parser = TagExpressionParser()
        with pytest.raises(TagExpressionError) as exc_info:
            parser.parse(text)

        exc_text = exc_info.exconly()
        print(exc_text)
        assert error_message in exc_text
Example #4
0
 def test_not_not_expression_sameas_expression(self, tag_expression_text,
                                               expected, tags, case):
     not2_tag_expression_text = "not not " + tag_expression_text
     tag_expression1 = TagExpressionParser.parse(tag_expression_text)
     tag_expression2 = TagExpressionParser.parse(not2_tag_expression_text)
     value1 = tag_expression1.evaluate(tags)
     value2 = tag_expression2.evaluate(tags)
     assert value1 == value2
     assert expected == value1
Example #5
0
 def test_or_operation(self, tag_expression_text, expected, tags, case):
     tag_expression = TagExpressionParser.parse(tag_expression_text)
     assert expected == tag_expression.evaluate(tags)
Example #6
0
 def test_fails_when_only_operators_are_used(self, tag_part):
     with pytest.raises(TagExpressionError):
         # -- EXAMPLE: text = "or or"
         text = "{part} {part}".format(part=tag_part)
         TagExpressionParser.parse(text)
Example #7
0
 def test_complex_example(self):
     tag_expression_text = "not @a or @b and not @c or not @d or @e and @f"
     tag_expression = TagExpressionParser.parse(tag_expression_text)
     assert False == tag_expression.evaluate("@a @c @d".split())
Example #8
0
 def test_empty_expression_is_true(self, tag_expression_text, expected,
                                   tags, case):
     tag_expression = TagExpressionParser.parse(tag_expression_text)
     assert expected == tag_expression.evaluate(tags)
Example #9
0
 def test_select_token(self, text, expected):
     token = TagExpressionParser.select_token(text)
     assert token is expected
Example #10
0
 def assert_parse_expression_equals_expression_repr(text, expected):
     parser = TagExpressionParser()
     expression = parser.parse(text)
     expression_text = repr(expression)
     assert expected == expression_text
Example #11
0
 def test_select_token(self, text, expected):
     token = TagExpressionParser.select_token(text)
     assert token is expected
Example #12
0
 def assert_parse_expression_equals_expression_repr(text, expected):
     parser = TagExpressionParser()
     expression = parser.parse(text)
     expression_text = repr(expression)
     assert expected == expression_text
Example #13
0
 def test_or_operation(self, tag_expression_text, expected, tags, case):
     tag_expression = TagExpressionParser.parse(tag_expression_text)
     assert expected == tag_expression.evaluate(tags)
Example #14
0
 def test_fails_when_only_operators_are_used(self, tag_part):
     with pytest.raises(TagExpressionError):
         # -- EXAMPLE: text = "or or"
         text = "{part} {part}".format(part=tag_part)
         TagExpressionParser.parse(text)
Example #15
0
 def test_complex_example(self):
     tag_expression_text = "not @a or @b and not @c or not @d or @e and @f"
     tag_expression = TagExpressionParser.parse(tag_expression_text)
     assert False == tag_expression.evaluate("@a @c @d".split())
Example #16
0
 def test_empty_expression_is_true(self, tag_expression_text, expected, tags, case):
     tag_expression = TagExpressionParser.parse(tag_expression_text)
     assert expected == tag_expression.evaluate(tags)