-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake8_strftime_test.py
More file actions
56 lines (44 loc) · 1.46 KB
/
flake8_strftime_test.py
File metadata and controls
56 lines (44 loc) · 1.46 KB
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
49
50
51
52
53
54
55
56
# stdlib
import ast
from typing import Set
# 3rd party
import pytest
# this package
from flake8_strftime import Plugin
def results(s: str) -> Set[str]:
return {"{}:{}: {}".format(*r) for r in Plugin(ast.parse(s)).run()}
def test_linux_specific():
assert results('print(f"{now:%Y/%-m/%-d %H:%M}")') == { # noqa: SFT001
"1:9: SFT001 Linux-specific strftime code used.",
"1:13: SFT001 Linux-specific strftime code used.",
}
assert results('print(now.strftime("%Y/%-m/%-d %H:%M"))') == { # noqa: SFT001
"1:22: SFT001 Linux-specific strftime code used.",
"1:26: SFT001 Linux-specific strftime code used.",
}
def test_windows_specific():
assert results('print(f"{now:%Y/%#m/%#d %H:%M}")') == { # noqa: SFT002
"1:9: SFT002 Windows-specific strftime code used.",
"1:13: SFT002 Windows-specific strftime code used.",
}
assert results('print(now.strftime("%Y/%#m/%#d %H:%M"))') == { # noqa: SFT002
"1:22: SFT002 Windows-specific strftime code used.",
"1:26: SFT002 Windows-specific strftime code used.",
}
@pytest.mark.parametrize(
"source",
[
"test_none = None",
"test_ellipsis = ...",
"test_int = 42",
"test_float = 1.0",
"test_list = [1, 2, 3]",
"test_tuple = (1, 2, 3)",
"test_set = {1, 2, 3}",
'test_dict = {"a": 1, "b": 2, "c": 3}',
]
)
def test_issue_10(source: str):
# https://github.com/domdfcoding/flake8_strftime/issues/10
# This shouldn't raise an exception
assert not list(Plugin(ast.parse(source)).run())