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
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
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
def test_or_operation(self, tag_expression_text, expected, tags, case): tag_expression = TagExpressionParser.parse(tag_expression_text) assert expected == tag_expression.evaluate(tags)
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)
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())
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)
def test_select_token(self, text, expected): token = TagExpressionParser.select_token(text) assert token is expected
def assert_parse_expression_equals_expression_repr(text, expected): parser = TagExpressionParser() expression = parser.parse(text) expression_text = repr(expression) assert expected == expression_text