Skip to content

Commit af1cb17

Browse files
committed
ruff: update tests for new file pattern
Signed-off-by: phanirithvij <[email protected]>
1 parent 2c29d5e commit af1cb17

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

tests/tools/test_ruff_works.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,38 @@ def test_ruff_works(
5353
expected_path_2 = os.path.join("tests", "data", "notebook_starting_with_md.ipynb")
5454

5555
out, err = capsys.readouterr()
56+
5657
# ignore ruff's suggestions
57-
out = "\n".join([x for x in out.splitlines() if "cell_" in x])
58+
prev = ""
59+
output: list[str] = []
60+
for line in out.splitlines():
61+
if "cell_" in line:
62+
# append previous line and matching line
63+
output.append(prev)
64+
output.append(line)
65+
prev = line
66+
5867
expected_out = (
59-
f"{expected_path_1}:cell_1:1:8: F401 [*] `os` imported but unused\n"
60-
f"{expected_path_1}:cell_1:3:8: F401 [*] `glob` imported but unused\n"
61-
f"{expected_path_1}:cell_1:5:8: F401 [*] `nbqa` imported but unused\n"
62-
f"{expected_path_0}:cell_1:1:8: F401 [*] `os` imported but unused\n"
63-
f"{expected_path_0}:cell_1:3:8: F401 [*] `glob` imported but unused\n"
64-
f"{expected_path_0}:cell_1:5:8: F401 [*] `nbqa` imported but unused\n"
65-
f"{expected_path_0}:cell_4:1:1: E402 Module level import not at top of file\n"
66-
f"{expected_path_0}:cell_4:1:20: F401 [*] `random.randint` imported but unused\n"
67-
f"{expected_path_0}:cell_5:1:1: E402 Module level import not at top of file\n"
68-
f"{expected_path_0}:cell_5:2:1: E402 Module level import not at top of file\n"
69-
f"{expected_path_2}:cell_1:1:8: F401 [*] `os` imported but unused\n"
70-
f"{expected_path_2}:cell_1:3:8: F401 [*] `glob` imported but unused\n"
71-
f"{expected_path_2}:cell_1:5:8: F401 [*] `nbqa` imported but unused\n"
72-
)
73-
assert "\n".join(sorted(out.replace("\r\n", "\n").splitlines())) == "\n".join(
74-
sorted(expected_out.splitlines())
68+
f"F401 [*] `os` imported but unused\n --> {expected_path_1}:cell_1:1:8\n"
69+
f"F401 [*] `glob` imported but unused\n --> {expected_path_1}:cell_1:3:8\n"
70+
f"F401 [*] `nbqa` imported but unused\n --> {expected_path_1}:cell_1:5:8\n"
71+
f"F401 [*] `os` imported but unused\n --> {expected_path_0}:cell_1:1:8\n"
72+
f"F401 [*] `glob` imported but unused\n --> {expected_path_0}:cell_1:3:8\n"
73+
f"F401 [*] `nbqa` imported but unused\n --> {expected_path_0}:cell_1:5:8\n"
74+
f"E402 Module level import not at top of file\n --> {expected_path_0}:cell_4:1:1\n"
75+
f"F401 [*] `random.randint` imported but unused\n --> {expected_path_0}:cell_4:1:20\n"
76+
f"E402 Module level import not at top of file\n --> {expected_path_0}:cell_5:1:1\n"
77+
f"E402 Module level import not at top of file\n --> {expected_path_0}:cell_5:2:1\n"
78+
f"F401 [*] `os` imported but unused\n --> {expected_path_2}:cell_1:1:8\n"
79+
f"F401 [*] `glob` imported but unused\n --> {expected_path_2}:cell_1:3:8\n"
80+
f"F401 [*] `nbqa` imported but unused\n --> {expected_path_2}:cell_1:5:8\n"
7581
)
82+
83+
# simple dedent of '\s+-->'
84+
out = "\n".join(sorted([x.lstrip() for x in output]))
85+
exp = "\n".join(sorted([x.lstrip() for x in expected_out.splitlines()]))
86+
87+
assert out == exp
7688
assert err == ""
7789

7890

0 commit comments

Comments
 (0)