Beispiel #1
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',
            ),
        ]
Beispiel #2
0
    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'),
        ]
Beispiel #3
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'),
        ]
Beispiel #4
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'),
        ]
Beispiel #5
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>)',
            ),
        ]