コード例 #1
0
 def test_multiple_codes(self):
     p = Parser("""
     E100, E101 : E200, E201
     """)
     assert list(p._parsed_lines()) == [
         (2, ['E100', 'E101'], 'E200, E201'),
     ]
コード例 #2
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
 def test_multiple_codes(self):
     p = Parser("""
     E100, E101 : E200, E201
     """)
     assert list(p._parsed_lines()) == [
         (2, ['E100', 'E101'], 'E200, E201'),
     ]
コード例 #3
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_mixed(self):
        p = Parser('/(a, b)/ , C001, foo.py : E101')

        assert list(p._parsed_lines()) == [
            (1, ['/(a, b)/', 'C001', 'foo.py'], 'E101'),
        ]

        assert p._rules == [
            Rule(
                [
                    RegexSelector('(a, b)'),
                    CodeSelector('C001'),
                    FileSelector('foo.py'),
                ],
                'E101',
            ),
        ]

        p = Parser('foo.py , /def foo/ : +E101')

        assert list(p._parsed_lines()) == [
            (1, ['foo.py', '/def foo/'], '+E101'),
        ]

        assert p._rules == [
            Rule(
                [FileSelector('foo.py'), RegexSelector('def foo')],
                'E101',
            ),
        ]
コード例 #4
0
 def test_no_space(self):
     p = Parser("""
     file.py: E101
     """)
     assert list(p._parsed_lines()) == [
         (2, ['file.py'], 'E101'),
     ]
コード例 #5
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_regex_colon(self):
        p = Parser('/if.*:/ : E101')
        assert list(p._lines()) == [
            (1, '/if.*:/ : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['/if.*:/'], 'E101'),
        ]
コード例 #6
0
    def test_selector_regex_colon(self):
        p = Parser('/if.*:/ : E101')
        assert list(p._lines()) == [
            (1, '/if.*:/ : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['/if.*:/'], 'E101'),
        ]
コード例 #7
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_regex_multi(self):
        p = Parser('/(a, b)/ , /(c, d)/ : E101')
        assert list(p._lines()) == [
            (1, '/(a, b)/ , /(c, d)/ : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['/(a, b)/', '/(c, d)/'], 'E101'),
        ]

        assert p._rules == [
            Rule([RegexSelector('(a, b)'), RegexSelector('(c, d)')], 'E101'),
        ]
コード例 #8
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_regex_hash(self):
        p = Parser('/# noqa/ : E101')
        assert list(p._lines()) == [
            (1, '/# noqa/ : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['/# noqa/'], 'E101'),
        ]

        assert p._rules == [
            Rule([RegexSelector('# noqa')], 'E101'),
        ]
コード例 #9
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_regex(self):
        p = Parser('/foo/ : E101')
        assert list(p._lines()) == [
            (1, '/foo/ : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['/foo/'], 'E101'),
        ]

        assert p._rules == [
            Rule([RegexSelector('foo')], 'E101'),
        ]
コード例 #10
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_explicit_relative_dir(self):
        p = Parser('./ : E101')
        assert list(p._lines()) == [
            (1, './ : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['./'], 'E101'),
        ]

        assert p._rules == [
            Rule([FileSelector('./')], 'E101'),
        ]
コード例 #11
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_filename_explicit_relative(self):
        p = Parser('./foo.py : E101')
        assert list(p._lines()) == [
            (1, './foo.py : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['./foo.py'], 'E101'),
        ]

        assert p._rules == [
            Rule([FileSelector('./foo.py')], 'E101'),
        ]
コード例 #12
0
    def test_selector_regex(self):
        p = Parser('/foo/ : E101')
        assert list(p._lines()) == [
            (1, '/foo/ : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['/foo/'], 'E101'),
        ]

        assert p._rules == [
            Rule([RegexSelector('foo')], 'E101'),
        ]
コード例 #13
0
    def test_selector_regex_hash(self):
        p = Parser('/# noqa/ : E101')
        assert list(p._lines()) == [
            (1, '/# noqa/ : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['/# noqa/'], 'E101'),
        ]

        assert p._rules == [
            Rule([RegexSelector('# noqa')], 'E101'),
        ]
コード例 #14
0
    def test_selector_explicit_relative_dir(self):
        p = Parser('./ : E101')
        assert list(p._lines()) == [
            (1, './ : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['./'], 'E101'),
        ]

        assert p._rules == [
            Rule([FileSelector('./')], 'E101'),
        ]
コード例 #15
0
    def test_selector_code(self):
        p = Parser('E100 : E101')
        assert list(p._lines()) == [
            (1, 'E100 : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['E100'], 'E101'),
        ]

        assert p._rules == [
            Rule([CodeSelector('E100')], 'E101'),
        ]
コード例 #16
0
    def test_selector_dir(self):
        p = Parser('tests/ : E101')
        assert list(p._lines()) == [
            (1, 'tests/ : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['tests/'], 'E101'),
        ]

        assert p._rules == [
            Rule([FileSelector('tests/')], 'E101'),
        ]
コード例 #17
0
    def test_selector_filename_explicit_relative(self):
        p = Parser('./foo.py : E101')
        assert list(p._lines()) == [
            (1, './foo.py : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['./foo.py'], 'E101'),
        ]

        assert p._rules == [
            Rule([FileSelector('./foo.py')], 'E101'),
        ]
コード例 #18
0
    def test_selector_regex_comma(self):
        p = Parser('/(a, b)/ : E101')
        assert list(p._lines()) == [
            (1, '/(a, b)/ : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['/(a, b)/'], 'E101'),
        ]

        assert p._rules == [
            Rule([RegexSelector('(a, b)')], 'E101'),
        ]
コード例 #19
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_filename(self):
        p = Parser('foo.py : E101')
        assert list(p._lines()) == [
            (1, 'foo.py : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['foo.py'], 'E101'),
        ]

        assert p._rules == [
            Rule([FileSelector('foo.py')], 'E101'),
        ]
コード例 #20
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_code_multi(self):
        p = Parser('E100, E200 : E101')
        assert list(p._lines()) == [
            (1, 'E100, E200 : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['E100', 'E200'], 'E101'),
        ]

        assert p._rules == [
            Rule([CodeSelector('E100'), CodeSelector('E200')], 'E101'),
        ]
コード例 #21
0
    def test_selector_filename(self):
        p = Parser('foo.py : E101')
        assert list(p._lines()) == [
            (1, 'foo.py : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['foo.py'], 'E101'),
        ]

        assert p._rules == [
            Rule([FileSelector('foo.py')], 'E101'),
        ]
コード例 #22
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_comment_suffix(self):
        p = Parser('E100 : E101 # foo')
        assert list(p._lines()) == [
            (1, 'E100 : E101 # foo'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['E100'], 'E101'),
        ]

        assert p._rules == [
            Rule([CodeSelector('E100')], 'E101'),
        ]
コード例 #23
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_dir(self):
        p = Parser('tests/ : E101')
        assert list(p._lines()) == [
            (1, 'tests/ : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['tests/'], 'E101'),
        ]

        assert p._rules == [
            Rule([FileSelector('tests/')], 'E101'),
        ]
コード例 #24
0
    def test_selector_explicit_relative_star(self):
        p = Parser('./* : E101')
        assert list(p._lines()) == [
            (1, './* : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['./*'], 'E101'),
        ]

        # TODO(#9): This should be a FileSelector, not a CodeSelector
        assert p._rules == [
            Rule([CodeSelector('./*')], 'E101'),
        ]
コード例 #25
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_explicit_relative_star(self):
        p = Parser('./* : E101')
        assert list(p._lines()) == [
            (1, './* : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['./*'], 'E101'),
        ]

        # TODO(#9): This should be a FileSelector, not a CodeSelector
        assert p._rules == [
            Rule([CodeSelector('./*')], 'E101'),
        ]
コード例 #26
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_star(self):
        p = Parser('* : E101')
        assert list(p._lines()) == [
            (1, '* : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['*'], 'E101'),
        ]

        # TODO(#9): This is a CodeSelector, which isnt suitable,
        # but a good purpose for this has not been established.
        assert p._rules == [
            Rule([CodeSelector('*')], 'E101'),
        ]
コード例 #27
0
    def test_selector_star(self):
        p = Parser('* : E101')
        assert list(p._lines()) == [
            (1, '* : E101'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['*'], 'E101'),
        ]

        # TODO(#9): This is a CodeSelector, which isnt suitable,
        # but a good purpose for this has not been established.
        assert p._rules == [
            Rule([CodeSelector('*')], 'E101'),
        ]
コード例 #28
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_multiline(self):
        p = Parser("""
        E100 : E101
        """)
        assert list(p._parsed_lines()) == [
            (2, ['E100'], 'E101'),
        ]

        p = Parser("""
        E100 : E101
        E200 : E201
        """)
        assert list(p._parsed_lines()) == [
            (2, ['E100'], 'E101'),
            (3, ['E200'], 'E201'),
        ]
コード例 #29
0
    def test_selector_marker(self):
        p = Parser("python_version == '2.4' : E101")
        assert list(p._lines()) == [
            (1, "python_version == '2.4' : E101"),
        ]

        assert list(p._parsed_lines()) == [
            (1, ["python_version == '2.4'"], 'E101'),
        ]

        assert p._rules == [
            Rule(
                [EnvironmentMarkerSelector("python_version == '2.4'")],
                'E101',
            ),
        ]
コード例 #30
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_marker(self):
        p = Parser("python_version == '2.4' : E101")
        assert list(p._lines()) == [
            (1, "python_version == '2.4' : E101"),
        ]

        assert list(p._parsed_lines()) == [
            (1, ["python_version == '2.4'"], 'E101'),
        ]

        assert p._rules == [
            Rule(
                [EnvironmentMarkerSelector("python_version == '2.4'")],
                'E101',
            ),
        ]
コード例 #31
0
 def test_selector_directory_wildcard(self):
     p = Parser('tests/*/test_*.py : E101')
     assert p._rules[0].file_match_any('tests/foo/test_bar.py')
     assert p._rules[0].file_match_any(
         '.{0}tests/foo/bar/test_baz.py'.format(os.sep), )
     assert p._rules[0].file_match_any('tests/foo/bar/test_.py')
     assert not p._rules[0].file_match_any('tests/test_foo.py')
コード例 #32
0
    def test_selector_regex_codes_append(self):
        p = Parser('/# !qa: *(?P<codes>[A-Z0-9, ]*)/ : +(?P<codes>)')

        assert list(p._lines()) == [
            (1, '/# !qa: *(?P<codes>[A-Z0-9, ]*)/ : +(?P<codes>)'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['/# !qa: *(?P<codes>[A-Z0-9, ]*)/'], '+(?P<codes>)'),
        ]

        assert p._rules == [
            Rule(
                [RegexSelector('# !qa: *(?P<codes>[A-Z0-9, ]*)')],
                '(?P<codes>)',
            ),
        ]
コード例 #33
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
    def test_selector_regex_codes_append(self):
        p = Parser('/# !qa: *(?P<codes>[A-Z0-9, ]*)/ : +(?P<codes>)')

        assert list(p._lines()) == [
            (1, '/# !qa: *(?P<codes>[A-Z0-9, ]*)/ : +(?P<codes>)'),
        ]

        assert list(p._parsed_lines()) == [
            (1, ['/# !qa: *(?P<codes>[A-Z0-9, ]*)/'], '+(?P<codes>)'),
        ]

        assert p._rules == [
            Rule(
                [RegexSelector('# !qa: *(?P<codes>[A-Z0-9, ]*)')],
                '(?P<codes>)',
            ),
        ]
コード例 #34
0
 def test_selector_regex_codes_multi(self):
     p = Parser('/# !qa: *(?P<codes>[A-Z0-9, ]*)/ : +(?P<codes>)')
     assert p._rules[0].regex_match_any(
         ' foo bar # !qa: E101, E102',
         ['E101'],
     )
     assert p._rules[0].regex_match_any(
         ' foo bar # !qa: E101, E102',
         ['E102'],
     )
コード例 #35
0
 def test_selector_regex_codes_multi_match(self):
     p = Parser('/disable=(?P<codes>[A-Z0-9]*)/ : +(?P<codes>)')
     assert p._rules[0].regex_match_any(
         ' foo bar # disable=E101 disable=E102',
         ['E101'],
     )
     assert p._rules[0].regex_match_any(
         ' foo bar # disable=E101 disable=E102',
         ['E102'],
     )
コード例 #36
0
ファイル: extension.py プロジェクト: crhodes2/JAMA-ID-Checker
    def parse_options(cls, options):
        """Parse options and activate `ignore_code` handler."""
        if (not options.putty_select and not options.putty_ignore
                and not options.putty_auto_ignore):
            return

        options._orig_select = options.select
        options._orig_ignore = options.ignore

        options.putty_select = Parser(options.putty_select)._rules
        options.putty_ignore = Parser(options.putty_ignore)._rules

        if options.putty_auto_ignore:
            options.putty_ignore.append(AutoLineDisableRule())

        options.ignore_code = functools.partial(
            putty_ignore_code,
            options,
        )

        options.report._ignore_code = options.ignore_code
コード例 #37
0
    def test_mixed(self):
        p = Parser('/(a, b)/ , C001, foo.py : E101')

        assert list(p._parsed_lines()) == [
            (1, ['/(a, b)/', 'C001', 'foo.py'], 'E101'),
        ]

        assert p._rules == [
            Rule(
                [
                    RegexSelector('(a, b)'),
                    CodeSelector('C001'),
                    FileSelector('foo.py'),
                ],
                'E101',
            ),
        ]

        p = Parser('foo.py , /def foo/ : +E101')

        assert list(p._parsed_lines()) == [
            (1, ['foo.py', '/def foo/'], '+E101'),
        ]

        assert p._rules == [
            Rule(
                [FileSelector('foo.py'),
                 RegexSelector('def foo')],
                'E101',
            ),
        ]
コード例 #38
0
    def test_multiline(self):
        p = Parser("""
        E100 : E101
        """)
        assert list(p._parsed_lines()) == [
            (2, ['E100'], 'E101'),
        ]

        p = Parser("""
        E100 : E101
        E200 : E201
        """)
        assert list(p._parsed_lines()) == [
            (2, ['E100'], 'E101'),
            (3, ['E200'], 'E201'),
        ]
コード例 #39
0
ファイル: test_config.py プロジェクト: jayvdb/flake8-putty
 def test_selector_comment_empty_line(self):
     p = Parser('# foo')
     assert list(p._lines()) == []
コード例 #40
0
 def test_combined_selectors(self):
     p = Parser('test.py, /foo/ : E101')
     assert p._rules[0].match('test.py', 'def foo', ['n/a'])
コード例 #41
0
    def test_selector_environment_marker(self):
        p = Parser("python_version == '2.4' : E101")
        assert not p._rules[0].environment_marker_evaluate()

        p = Parser("python_version > '2.4' : E101")
        assert p._rules[0].environment_marker_evaluate()
コード例 #42
0
 def test_selector_filename_multi(self):
     p = Parser('foo.py, bar.py : E101')
     assert p._rules[0].file_match_any('foo.py')
     assert p._rules[0].file_match_any('.{0}foo.py'.format(os.sep))
     assert p._rules[0].file_match_any('bar.py')
     assert not p._rules[0].file_match_any('foo/bar.py')
コード例 #43
0
 def test_selector_filename_missing(self):
     """Test that file_match_any isnt True if there are no filename rules."""
     p = Parser('/foo/ : E101')
     assert not p._rules[0].file_match_any(' foo ')
コード例 #44
0
 def test_selector_directory_multi(self):
     p = Parser('tests/, vendor/ : E101')
     assert p._rules[0].file_match_any('tests/foo.py')
     assert p._rules[0].file_match_any('vendor/foo.py')
     assert not p._rules[0].file_match_any('other/foo.py')
コード例 #45
0
 def test_selector_regex_codes_append(self):
     p = Parser('/# !qa: *(?P<codes>[A-Z0-9, ]*)/ : +(?P<codes>)')
     assert p._rules[0].regex_match_any(' foo bar # !qa: E101', ['E101'])
     assert not p._rules[0].regex_match_any(' baz # !qa: E101', ['E102'])
コード例 #46
0
 def test_selector_regex_multi(self):
     p = Parser('/foo/ , /bar/ : E101')
     assert p._rules[0].regex_match_any(' foo bar ')
     assert p._rules[0].regex_match_any(' bar ')
     assert not p._rules[0].regex_match_any(' baz ')
コード例 #47
0
 def test_selector_directory_wildcard_multi(self):
     p = Parser('tests/*/test_*.py, vendor/*/test_*.py : E101')
     assert p._rules[0].file_match_any('tests/foo/test_bar.py')
     assert p._rules[0].file_match_any('vendor/foo/test_bar.py')
     assert not p._rules[0].file_match_any('other/foo/test_bar.py')
コード例 #48
0
 def test_selector_directory_wildcard_nested(self):
     p = Parser('tests/*/*/test_*.py : E101')
     assert p._rules[0].file_match_any('tests/foo/bar/test_baz.py')
     assert not p._rules[0].file_match_any('tests/foo/test_bar.py')