def test_evaluate_marker(): # See: https://www.python.org/dev/peps/pep-0508/#complete-grammar # ((marker_expr, context, extras, expected_output), ...) test_cases = ( # Valid context ('spam == "1.0"', {'spam': '1.0'}, True), # Should parse as (a and b) or c ("a=='a' and b=='b' or c=='c'", {'a': 'a', 'b': 'b', 'c': ''}, True), # Overriding precedence -> a and (b or c) ("a=='a' and (b=='b' or c=='c')", {'a': 'a', 'b': '', 'c': ''}, None), # Overriding precedence -> (a or b) and c ("(a=='a' or b=='b') and c=='c'", {'a': 'a', 'b': '', 'c': ''}, None), ) for marker_expr, context, expected_output in test_cases: output = None if expected_output: output = interpret(marker_expr, context) assert output is expected_output else: output = interpret(marker_expr, context) _print_output(marker_expr, context, output, expected_output) # Test cases syntax error test_cases = ( ('spam == "1.0"', {}, None), ('spam2 == "1.0"', {'spam': '1.0'}, None), # Malformed ('spam2 = "1.0"', {'spam': '1.0'}, None), ) for marker_expr, context, expected_output in test_cases: output = None with pytest.raises(SyntaxError): output = interpret(marker_expr, context)