Commit a15fd1fc authored by Matthias Bernt's avatar Matthias Bernt
Browse files

fix assertion linters

n, min, max, ... accept bytes (eg 500k)

i.e. the type annotation and thereby linting was wrong
I suggest to remove it, since its tested in the xsd linter
anyway (otherwise we would check for str)
parent 5300b135
Loading
Loading
Loading
Loading
+1 −13
Original line number Diff line number Diff line
@@ -152,23 +152,11 @@ def _check_asserts(test_idx, assertions, lint_ctx):
                lint_ctx.error(f"Test {test_idx}: unknown assertion '{a.tag}'", node=a)
                continue
            assert_function_sig = signature(asserts.assertion_functions[assert_function_name])
            # check type of the attributes (int, float ...)
            # check of the attributes
            for attrib in a.attrib:
                if attrib not in assert_function_sig.parameters:
                    lint_ctx.error(f"Test {test_idx}: unknown attribute '{attrib}' for '{a.tag}'", node=a)
                    continue
                annotation = assert_function_sig.parameters[attrib].annotation
                annotation = _handle_optionals(annotation)
                if annotation is not Parameter.empty:
                    try:
                        annotation(a.attrib[attrib])
                    except TypeError:
                        raise Exception(f"Faild to instantiate {attrib} for {assert_function_name}")
                    except ValueError:
                        lint_ctx.error(
                            f"Test {test_idx}: attribute '{attrib}' for '{a.tag}' needs to be '{annotation.__name__}' got '{a.attrib[attrib]}'",
                            node=a,
                        )
            # check missing required attributes
            for p in assert_function_sig.parameters:
                if p in ["output", "output_bytes", "verify_assertions_function", "children"]:
+2 −3
Original line number Diff line number Diff line
@@ -1562,8 +1562,7 @@ def test_tests_asserts(lint_ctx):
    assert "Test 1: unknown assertion 'invalid'" in lint_ctx.error_messages
    assert "Test 1: unknown attribute 'invalid_attrib' for 'has_text'" in lint_ctx.error_messages
    assert "Test 1: missing attribute 'text' for 'has_text'" in lint_ctx.error_messages
    assert "Test 1: attribute 'value' for 'has_size' needs to be 'int' got '500k'" in lint_ctx.error_messages
    assert "Test 1: attribute 'delta' for 'has_size' needs to be 'int' got '1O'" in lint_ctx.error_messages
    assert "Test 1: attribute 'value' for 'has_size' needs to be 'int' got '500k'" not in lint_ctx.error_messages
    assert (
        "Test 1: unknown attribute 'invalid_attrib_also_checked_in_nested_asserts' for 'not_has_text'"
        in lint_ctx.error_messages
@@ -1572,7 +1571,7 @@ def test_tests_asserts(lint_ctx):
    assert "Test 1: 'has_n_columns' needs to specify 'n', 'min', or 'max'" in lint_ctx.error_messages
    assert "Test 1: 'has_n_lines' needs to specify 'n', 'min', or 'max'" in lint_ctx.error_messages
    assert not lint_ctx.warn_messages
    assert len(lint_ctx.error_messages) == 9
    assert len(lint_ctx.error_messages) == 7


def test_tests_output_type_mismatch(lint_ctx):