Skip to content

Commit a6c60c2

Browse files
committed
Account for col_offset change in Python 3.12
It's now closer to being correct.
1 parent 1ad99c4 commit a6c60c2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/flake8_strftime_test.py

+29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# stdlib
22
import ast
3+
import sys
34
from typing import Set
45

56
# 3rd party
@@ -13,6 +14,7 @@ def results(s: str) -> Set[str]:
1314
return {"{}:{}: {}".format(*r) for r in Plugin(ast.parse(s)).run()}
1415

1516

17+
@pytest.mark.skipif(sys.version_info >= (3, 12), reason="Line numbers are offset on earlier versions")
1618
def test_linux_specific():
1719
assert results('print(f"{now:%Y/%-m/%-d %H:%M}")') == { # noqa: STRFTIME001
1820
"1:9: STRFTIME001 Linux-specific strftime code used.",
@@ -25,6 +27,20 @@ def test_linux_specific():
2527
}
2628

2729

30+
@pytest.mark.skipif(sys.version_info < (3, 12), reason="Line numbers are offset on earlier versions")
31+
def test_linux_specific_312():
32+
assert results('print(f"{now:%Y/%-m/%-d %H:%M}")') == { # noqa: STRFTIME001
33+
"1:16: STRFTIME001 Linux-specific strftime code used.",
34+
"1:20: STRFTIME001 Linux-specific strftime code used.",
35+
}
36+
37+
assert results('print(now.strftime("%Y/%-m/%-d %H:%M"))') == { # noqa: STRFTIME001
38+
"1:22: STRFTIME001 Linux-specific strftime code used.",
39+
"1:26: STRFTIME001 Linux-specific strftime code used.",
40+
}
41+
42+
43+
@pytest.mark.skipif(sys.version_info >= (3, 12), reason="Line numbers are offset on earlier versions")
2844
def test_windows_specific():
2945
assert results('print(f"{now:%Y/%#m/%#d %H:%M}")') == { # noqa: STRFTIME002
3046
"1:9: STRFTIME002 Windows-specific strftime code used.",
@@ -37,6 +53,19 @@ def test_windows_specific():
3753
}
3854

3955

56+
@pytest.mark.skipif(sys.version_info < (3, 12), reason="Line numbers are offset on earlier versions")
57+
def test_windows_specific_312():
58+
assert results('print(f"{now:%Y/%#m/%#d %H:%M}")') == { # noqa: STRFTIME002
59+
"1:16: STRFTIME002 Windows-specific strftime code used.",
60+
"1:20: STRFTIME002 Windows-specific strftime code used.",
61+
}
62+
63+
assert results('print(now.strftime("%Y/%#m/%#d %H:%M"))') == { # noqa: STRFTIME002
64+
"1:22: STRFTIME002 Windows-specific strftime code used.",
65+
"1:26: STRFTIME002 Windows-specific strftime code used.",
66+
}
67+
68+
4069
@pytest.mark.parametrize(
4170
"source",
4271
[

0 commit comments

Comments
 (0)