def test_broad_except(try_statement: str, error: Error | None) -> None:
    expr = ast.parse(try_statement)
    if error is None:
        assert to_errors(Flake8PieCheck(expr, filename="foo.py").run()) == []
    else:
        assert to_errors(Flake8PieCheck(expr,
                                        filename="foo.py").run()) == [error]
def test_celery_task_name_lint(code: str, expected: Error | None) -> None:
    node = ast.parse(code)
    assert isinstance(node, ast.Module)
    expected_errors = [expected] if expected else []
    assert (to_errors(Flake8PieCheck(
        node,
        filename="foo.py").run()) == expected_errors), "missing name property"
Пример #3
0
def test_celery_require_task_expiration(code: str,
                                        expected: Error | None) -> None:
    node = ast.parse(code)
    assert isinstance(node, ast.Module)
    expected_errors = [expected] if expected else []
    assert (to_errors(Flake8PieCheck(
        node,
        filename="foo.py").run())) == expected_errors, "missing expiration"
Пример #4
0
def test_is_assign_and_return(func: str, expected: Optional[ErrorLoc],
                              reason: str) -> None:

    node = ast.parse(func)

    func_def = node.body[0]
    assert isinstance(func_def, ast.FunctionDef)
    assert is_assign_and_return(func_def) == expected, reason

    expected_errors = [expected] if expected is not None else []

    assert list(Flake8PieCheck(node).run()) == expected_errors, reason
def test_celery_crontab_named_args(code: str, expected: Error | None) -> None:
    """
    ensure we pass a explicit params to celery's crontab
    see: https://github.com/celery/celery/blob/0736cff9d908c0519e07babe4de9c399c87cb32b/celery/schedules.py#L403

    You must pass all the params below the level you are creating.
    So if you pass hour, then you must pass minutes.
    If you pass the day arg then you must provide hours and minutes, etc.

    params:  minute, hour, day_of_week, day_of_month, month_of_year
    """
    node = ast.parse(code)
    assert isinstance(node, ast.Module)
    expected_errors = [expected] if expected else []
    assert (to_errors(Flake8PieCheck(node, filename="foo.py").run())
            ) == expected_errors, "missing a required argument"
def test_prefer_unique_enums(code: str, errors: list[Error]) -> None:
    expr = ast.parse(code)
    assert to_errors(Flake8PieCheck(expr, filename="foo.py").run()) == errors
Пример #7
0
def test_no_unnecessary_class(code: str, errors: list[Error]) -> None:
    expr = ast.parse(code)
    assert to_errors(Flake8PieCheck(expr, filename="foo.py").run()) == errors
Пример #8
0
def test_examples(code: str, errors: list[Error]) -> None:
    expr = ast.parse(code)
    assert to_errors(Flake8PieCheck(expr, filename="foo.py").run()) == errors
Пример #9
0
def test_is_assign_and_return(func: str, expected: Error | None, reason: str) -> None:
    expected_errors = [expected] if expected is not None else []
    assert (
        to_errors(Flake8PieCheck(ast.parse(func), filename="foo.py").run())
    ) == expected_errors, reason
def test_no_pointless_statements(code: str, errors: list[Error]) -> None:
    expr = ast.parse(code)
    assert to_errors(Flake8PieCheck(expr, filename="foo.py").run()) == errors
Пример #11
0
def test_no_pointless_f_strings(func: str, expected: Optional[ErrorLoc],
                                reason: str) -> None:
    node = ast.parse(func)

    expected_errors = [expected] if expected else []
    assert list(Flake8PieCheck(node).run()) == expected_errors, reason
def test_prefer_logging_interpolation(code: str, errors: list[Error]) -> None:
    expr = ast.parse(code)
    assert to_errors(Flake8PieCheck(expr, filename="foo.py").run()) == errors
def test_prefer_isinstance_type_compare(code: str,
                                        errors: list[Error]) -> None:
    expr = ast.parse(code)
    assert to_errors(Flake8PieCheck(expr, filename="foo.py").run()) == errors
def test_no_inherit_object(code: str, errors: list[Error]) -> None:
    expr = ast.parse(code)
    assert to_errors(Flake8PieCheck(expr, filename="foo.py").run()) == errors
Пример #15
0
def test_no_bool_condition(code: str, errors: list[Error]) -> None:
    expr = ast.parse(code)
    assert to_errors(Flake8PieCheck(expr, filename="foo.py").run()) == errors