Example #1
0
def test_rule_set_return_informative_error_when_rule_not_registered():
    """Assert that a rule that throws an exception on _eval returns it as a validation."""
    cfg = FluffConfig()
    with pytest.raises(ValueError) as e:
        get_rule_from_set("L000", config=cfg)

    e.match("'L000' not in")
Example #2
0
def test__rule_test_case(test_case):
    """Run the tests."""
    res = rules__test_helper(test_case)
    if res is not None and res != test_case.fail_str:
        cfg = FluffConfig(configs=test_case.configs)
        rule = get_rule_from_set(test_case.rule, config=cfg)
        assert is_fix_compatible(
            rule
        ), f'Rule {test_case.rule} returned fixes but does not specify "@document_fix_compatible".'
def test__rule_test_case(test_case, caplog):
    """Run the tests."""
    with caplog.at_level(logging.DEBUG, logger="sqlfluff.rules"):
        res = rules__test_helper(test_case)
        if res is not None and res != test_case.fail_str:
            cfg = FluffConfig(configs=test_case.configs)
            rule = get_rule_from_set(test_case.rule, config=cfg)
            assert is_fix_compatible(
                rule
            ), f'Rule {test_case.rule} returned fixes but does not specify "@document_fix_compatible".'
Example #4
0
def test__rules__std_L003_process_raw_stack(generate_test_segments):
    """Test the _process_raw_stack function.

    Note: This test probably needs expanding. It doesn't
    really check enough of the full functionality.

    """
    cfg = FluffConfig()
    r = get_rule_from_set("L003", config=cfg)
    test_stack = generate_test_segments(["bar", "\n", "     ", "foo", "baar", " \t "])
    res = r._process_raw_stack(test_stack)
    print(res)
    assert sorted(res.keys()) == [1, 2]
    assert res[2]["indent_size"] == 5
Example #5
0
def test__rules__std_L003_process_raw_stack(generate_test_segments, test_elems,
                                            result):
    """Test the _process_raw_stack function.

    Note: This test probably needs expanding. It doesn't
    really check enough of the full functionality.

    """
    cfg = FluffConfig()
    r = get_rule_from_set("L003", config=cfg)
    test_stack = generate_test_segments(test_elems)
    res = r._process_raw_stack(test_stack, {})
    print(res)
    # Verify structure
    assert isinstance(res, dict)
    assert all(isinstance(k, int) for k in res.keys())
    assert all(isinstance(v, dict) for v in res.values())
    # Check keys are all present
    assert all(
        v.keys() == {
            "line_no",
            "templated_line",
            "line_buffer",
            "indent_buffer",
            "indent_size",
            "indent_balance",
            "hanging_indent",
            "clean_indent",
        } for v in res.values())
    for k in res:
        # For testing purposes, we won't be checking the buffer fields. They're
        # just too hard to create in the test cases and aren't critical in
        # determining what course of action to take. Most of the logic uses the
        # values which we *are* still testing.
        del res[k]["line_buffer"]
        del res[k]["indent_buffer"]
        # We also don't check the "templated_file" flag. These tests don't
        # exercise that code.
        del res[k]["templated_line"]
    assert res == result