Beispiel #1
0
def test_multiline_dictionary_literal():
    assert get_flakes(
        '#py foo = {\n'
        '    "bar": "baz",\n'
        '}\n'
        '$foo\n'
    ) == ()
Beispiel #2
0
def test_indented_multiline_dictionary_literal():
    assert get_flakes('#if True\n'
                      '    #py foo = {\n'
                      '        "bar": "baz",\n'
                      '    }\n'
                      '    $foo\n'
                      '#end if\n') == ()
Beispiel #3
0
def test_unicode_literals():
    assert get_flakes("$_(u'hi ☃')", ) == ((
        1,
        'P001',
        'unicode literal prefix is unnecessary (assumed) in cheetah '
        "templates: u'hi ☃'",
    ), )
Beispiel #4
0
def test_redefinition_of_unused_name_block_def():
    assert get_flakes(
        '#block foo\n'
        '#end block\n'
        '#def foo()\n'
        '#end def\n') == ((3, 'F811',
                           "redefinition of unused 'foo' from line 1"), )
Beispiel #5
0
def test_cannot_determine_line_number():
    assert get_flakes(
        '$foo(\n'
        '    $bar == True,\n'
        ')') == ((
            0, 'E712',
            "comparison to True should be 'if cond is True:' or 'if cond:'"), )
Beispiel #6
0
def test_context_manager():
    assert get_flakes('#import contextlib\n'
                      '#@contextlib.contextmanager\n'
                      '#def foo()\n'
                      '    before\n'
                      '    #yield\n'
                      '    after\n'
                      '#end def\n') == ()
Beispiel #7
0
def test_comparison_to_true():
    assert get_flakes('#if $foo == True: herp') == (
        (
            1,
            "E712 comparison to True should be "
            "'if cond is True:' or 'if cond:'",
        ),
    )
Beispiel #8
0
def test_indents_with_tabs():
    assert get_flakes(
        '#if True:\n'
        '\tHello world\n'
        '#end if\n',
    ) == (
        (2, 'T003 Indentation contains tabs'),
    )
Beispiel #9
0
def test_indents_not_four_spaces():
    assert get_flakes(
        '#if True:\n'
        '   Hello world\n'
        '#end if\n'
    ) == (
        (2, 'T004 Indentation is not a multiple of 4'),
    )
Beispiel #10
0
def test_redefinition_of_unused_name():
    assert get_flakes(
        '#import foo.bar\n'
        '#import foo.bar\n'
        '$foo.baz()'
    ) == (
        (2, "F811 redefinition of unused 'foo' from line 1"),
    )
Beispiel #11
0
def test_oneline_directive_followed_by_directive():
    assert get_flakes(
        '#if True\n'
        '    #def title()##end def#\n'
        '    #py foo = "bar"\n'
        '    $foo\n'
        '#end if\n'
    ) == ()
Beispiel #12
0
def test_list_comprehension_redefines_name():
    assert get_flakes(
        '#set foo = $bar\n'
        '#for bar in [foo for foo in (1, 2, 3)]\n'
        '    $bar\n'
        '#end for\n'
    ) == (
        (2, "F812 list comprehension redefines 'foo' from line 1"),
    )
Beispiel #13
0
def test_module_shadowed_by_loop_variable():
    assert get_flakes(
        '#import foo\n'
        '\n'
        '$foo\n'
        '#for foo in (1, 2, 3)\n'
        '    $foo\n'
        '#end for\n') == ((
            4, 'F402', "import 'foo' from line 1 shadowed by loop variable"), )
Beispiel #14
0
def test_star_import():
    assert get_flakes('#from foo import *') == (
        (1, 'F401', "'foo.*' imported but unused"),
        (
            1,
            'F403',
            "'from foo import *' used; unable to detect undefined names",
        ),
    )
Beispiel #15
0
def test_redefinition_of_unused_name_block_def():
    assert get_flakes(
        '#block foo\n'
        '#end block\n'
        '#def foo()\n'
        '#end def\n'
    ) == (
        (3, "F811 redefinition of unused 'foo' from line 1"),
    )
Beispiel #16
0
def test_indented_multiline_dictionary_literal():
    assert get_flakes(
        '#if True\n'
        '    #py foo = {\n'
        '        "bar": "baz",\n'
        '    }\n'
        '    $foo\n'
        '#end if\n'
    ) == ()
Beispiel #17
0
def test_module_imported_but_unused_lots_of_lines():
    assert get_flakes(
        '#import foo\n'
        '#def womp()\n'
        '    $bar\n'
        '#end def\n'
    ) == (
        (1, "F401 'foo' imported but unused"),
    )
Beispiel #18
0
def test_indented_thrice_multiline():
    assert get_flakes('#def foo()\n'
                      '    <div>\n'
                      '        <div>\n'
                      '            $bar(\n'
                      '                $baz,\n'
                      '            )\n'
                      '        </div>\n'
                      '    </div>\n'
                      '#end def\n') == ()
Beispiel #19
0
def test_unicode_literals():
    assert get_flakes(
        "$_(u'hi ☃')",
    ) == (
        (
            1,
            'P001 unicode literal prefix is unnecessary (assumed) in cheetah '
            "templates: u'hi ☃'"
        ),
    )
Beispiel #20
0
def test_cannot_determine_line_number():
    assert get_flakes(
        '#set foo = "bar"\n'
        '#def foo()\n'
        '   $herp\n'
        '#end def\n'
    ) == (
        # The current reverse-parsing strategy doesn't find this assignment.
        (0, "F841 local variable 'foo' is assigned to but never used"),
    )
Beispiel #21
0
def test_context_manager():
    assert get_flakes(
        '#import contextlib\n'
        '#@contextlib.contextmanager\n'
        '#def foo()\n'
        '    before\n'
        '    #yield\n'
        '    after\n'
        '#end def\n'
    ) == ()
Beispiel #22
0
def test_list_comprehension_redefines_name():
    # python 3 makes this not an issue
    expected = (((1, 'F841',
                  "local variable 'foo' is assigned to but never used"), )
                if five.PY3 else
                ((2, 'F812',
                  "list comprehension redefines 'foo' from line 1"), ))
    assert get_flakes('#py foo = $bar\n'
                      '#for bar in [foo for foo in (1, 2, 3)]\n'
                      '    $bar\n'
                      '#end for\n') == expected
Beispiel #23
0
def test_module_shadowed_by_loop_variable():
    assert get_flakes(
        '#import foo\n'
        '\n'
        '$foo\n'
        '#for foo in (1, 2, 3)\n'
        '    $foo\n'
        '#end for\n'
    ) == (
        (4, "F402 import 'foo' from line 1 shadowed by loop variable"),
    )
Beispiel #24
0
def test_cannot_determine_line_number():
    assert get_flakes(
        '$foo(\n'
        '    $bar == True,\n'
        ')'
    ) == (
        (
            0,
            "E712 comparison to True should be "
            "'if cond is True:' or 'if cond:'"
        ),
    )
Beispiel #25
0
def test_indented_thrice_multiline():
    assert get_flakes(
        '#def foo()\n'
        '    <div>\n'
        '        <div>\n'
        '            $bar(\n'
        '                $baz,\n'
        '            )\n'
        '        </div>\n'
        '    </div>\n'
        '#end def\n'
    ) == ()
Beispiel #26
0
def test_list_comprehension_redefines_name():
    # python 3 makes this not an issue
    expected = (
        ((1, "F841 local variable 'foo' is assigned to but never used"),)
        if five.PY3 else
        ((2, "F812 list comprehension redefines 'foo' from line 1"),)
    )
    assert get_flakes(
        '#py foo = $bar\n'
        '#for bar in [foo for foo in (1, 2, 3)]\n'
        '    $bar\n'
        '#end for\n'
    ) == expected
Beispiel #27
0
def test_duplicated_key_name():
    assert get_flakes(
        '#py x = 1\n'
        '#py y = {x: 1, x: 2}\n'
        '$y\n', ) == (
            (
                2,
                'F602',
                'dictionary key variable x repeated with different values',
            ),
            (
                2,
                'F602',
                'dictionary key variable x repeated with different values',
            ),
        )
Beispiel #28
0
def test_comparison_to_true():
    assert get_flakes('#if $foo == True: herp') == ((
        1,
        'E712',
        "comparison to True should be 'if cond is True:' or 'if cond:'",
    ), )
Beispiel #29
0
def test_compare_against_literal():
    assert get_flakes('#py x = 5\n${x is 5}') == ((
        2, 'F632', 'use ==/!= to compare str, bytes, and int literals'), )
Beispiel #30
0
def test_invalid_escape_sequence():
    with pytest.warns(None):  # in py3 the compilation of this causes a warning
        assert get_flakes(r'${"\q"}') == ((1, 'W605',
                                           r"invalid escape sequence '\q'"), )
Beispiel #31
0
def test_extends_cheetah_template():
    assert get_flakes('#extends Cheetah.Template') == ((
        1,
        'T002',
        "'#extends Cheetah.Template' is assumed without '#extends'",
    ), )
Beispiel #32
0
def test_implements_respond_with_extend():
    assert get_flakes('#extends foo\n#implements respond') == ()
Beispiel #33
0
def test_extends_something_else():
    assert get_flakes('#extends foo') == ()
Beispiel #34
0
def test_syntaxerror():
    assert get_flakes('#if foo = "bar": herp') == (
        (1, "E901 SyntaxError: invalid syntax"),
    )
Beispiel #35
0
def test_identity():
    assert get_flakes('#py bar = foo = None\n#if not $bar is $foo: herp') == (
        (2, "E714 test for object identity should be 'is not'"),
    )
Beispiel #36
0
def test_implements_respond_with_extend():
    assert get_flakes('#extends foo\n#implements respond') == ()
Beispiel #37
0
def test_unused_local_variable():
    assert get_flakes('#py foo = $bar') == (
        (1, "F841 local variable 'foo' is assigned to but never used"),
    )
Beispiel #38
0
def test_membership():
    assert get_flakes('#py baz = foo = None\n#if not $baz in $foo: herp') == ((
        2, 'E713', "test for membership should be 'not in'"), )
Beispiel #39
0
def test_compiler_settings():
    assert get_flakes(
        '#compiler-settings#useLegacyImportMode = True#end compiler-settings#',
    ) == ()
Beispiel #40
0
def test_identity():
    assert get_flakes('#py bar = foo = None\n#if not $bar is $foo: herp') == ((
        2, 'E714', "test for object identity should be 'is not'"), )
Beispiel #41
0
def test_indents_not_four_spaces():
    assert get_flakes(
        '#if True:\n'
        '   Hello world\n'
        '#end if\n') == ((2, 'T004', 'Indentation is not a multiple of 4'), )
Beispiel #42
0
def test_indents_with_tabs():
    assert get_flakes('#if True:\n'
                      '\tHello world\n'
                      '#end if\n', ) == ((2, 'T003',
                                          'Indentation contains tabs'), )
Beispiel #43
0
def test_comparison_to_none():
    assert get_flakes('#if $foo == None: herp') == (
        (1, "E711 comparison to None should be 'if cond is None:'"),
    )
Beispiel #44
0
def test_comparison_to_none():
    assert get_flakes('#if $foo == None: herp') == ((
        1, 'E711', "comparison to None should be 'if cond is None:'"), )
Beispiel #45
0
def test_membership():
    assert get_flakes('#py baz = foo = None\n#if not $baz in $foo: herp') == (
        (2, "E713 test for membership should be 'not in'"),
    )
Beispiel #46
0
def test_unused_local_variable():
    assert get_flakes('#py foo = $bar') == ((
        1, 'F841', "local variable 'foo' is assigned to but never used"), )
Beispiel #47
0
def test_has_key():
    assert get_flakes('#if $foo.has_key($bar): herp') == (
        (1, "W601 .has_key() is deprecated, use 'in'"),
    )
Beispiel #48
0
def test_extends_cheetah_template():
    assert get_flakes('#extends Cheetah.Template') == (
        (1, "T002 '#extends Cheetah.Template' is assumed without '#extends'"),
    )
Beispiel #49
0
def test_has_key():
    assert get_flakes('#if $foo.has_key($bar): herp') == ((
        1, 'W601', ".has_key() is deprecated, use 'in'"), )
Beispiel #50
0
def test_duplicated_key_const():
    assert get_flakes('#py x = {True: 1, True: 2}\n$x') == (
        (1, 'F601', 'dictionary key True repeated with different values'),
        (1, 'F601', 'dictionary key True repeated with different values'),
    )
Beispiel #51
0
def test_implements_respond_no_extend():
    assert get_flakes('#implements respond') == (
        (1, "T001 '#implements respond' is assumed without '#extends'"),
    )
Beispiel #52
0
def test_implements_respond_no_extend():
    assert get_flakes('#implements respond') == ((
        1, 'T001', "'#implements respond' is assumed without '#extends'"), )
Beispiel #53
0
def test_implements_non_respond():
    assert get_flakes('#implements foo') == ()
Beispiel #54
0
def test_implements_non_respond():
    assert get_flakes('#implements foo') == ()
Beispiel #55
0
def test_extends_something_else():
    assert get_flakes('#extends foo') == ()
Beispiel #56
0
def test_star_import():
    assert get_flakes('#from foo import *') == (
        (1, "F401 'foo.*' imported but unused"),
        (1, "F403 'from foo import *' used; unable to detect undefined names"),
    )
Beispiel #57
0
def test_module_imported_but_unused_lots_of_lines():
    assert get_flakes('#import foo\n'
                      '#def womp()\n'
                      '    $bar\n'
                      '#end def\n') == ((1, 'F401',
                                         "'foo' imported but unused"), )
Beispiel #58
0
def test_redefinition_of_unused_name():
    assert get_flakes(
        '#import foo.bar\n'
        '#import foo.bar\n'
        '$foo.baz()') == ((2, 'F811',
                           "redefinition of unused 'foo' from line 1"), )
Beispiel #59
0
def test_compiler_settings():
    assert get_flakes(
        '#compiler-settings#useLegacyImportMode = True#end compiler-settings#',
    ) == ()
Beispiel #60
0
def test_syntaxerror():
    assert get_flakes('#if foo = "bar": herp') == ((
        1, 'E999', "SyntaxError: invalid syntax"), )