File: test_pycodestyle.py

package info (click to toggle)
pycodestyle 2.12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 624 kB
  • sloc: python: 4,697; makefile: 135; sh: 12
file content (48 lines) | stat: -rw-r--r-- 1,079 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import io
import sys
import tokenize

import pytest

from pycodestyle import Checker
from pycodestyle import expand_indent
from pycodestyle import mute_string


@pytest.mark.parametrize(
    ('s', 'expected'),
    (
        ('    ', 4),
        ('\t', 8),
        ('       \t', 8),
        ('        \t', 16),
    ),
)
def test_expand_indent(s, expected):
    assert expand_indent(s) == expected


@pytest.mark.parametrize(
    ('s', 'expected'),
    (
        ('"abc"', '"xxx"'),
        ("'''abc'''", "'''xxx'''"),
        ("r'abc'", "r'xxx'"),
    ),
)
def test_mute_string(s, expected):
    assert mute_string(s) == expected


def test_fstring_logical_line():
    src = '''\
f'hello {{ {thing} }} world'
'''
    checker = Checker(lines=src.splitlines())
    checker.tokens = list(tokenize.generate_tokens(io.StringIO(src).readline))
    checker.build_tokens_line()

    if sys.version_info >= (3, 12):  # pragma: >3.12 cover
        assert checker.logical_line == "f'xxxxxxxxx{thing}xxxxxxxxx'"
    else:
        assert checker.logical_line == "f'xxxxxxxxxxxxxxxxxxxxxxxxx'"