Skip to content

Commit e5b09d4

Browse files
committed
Fix test type error
1 parent b34512c commit e5b09d4

File tree

1 file changed

+13
-34
lines changed

1 file changed

+13
-34
lines changed

mypy/test/test_color_output.py

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import pytest
66

77
#XXX Would like help with this test, how do I make it runnable?
8-
98
# Haven't run this test yet
109

1110
PTY_SIZE = (80, 40)
1211

1312
if sys.platform == "win32":
1413
if TYPE_CHECKING:
15-
from winpty.winpty import PTY
14+
# This helps my IDE find the type annotations
15+
from winpty.winpty import PTY #type:ignore[import-untyped]
1616
else:
1717
from winpty import PTY
1818

@@ -28,8 +28,9 @@ def run_pty(cmd: str, env: dict[str, str] = {}) -> tuple[str, str]:
2828
from pty import openpty
2929

3030
def run_pty(cmd: str, env: dict[str, str] = {}) -> tuple[str, str]:
31-
# TODO Would like help checking quality of this function,
31+
# NOTE Would like help checking quality of this function,
3232
# it's partially written by Copilot because I'm not familiar with Unix openpty
33+
# and cannot use Unix openpty
3334
master_fd, slave_fd = openpty()
3435
try:
3536
p = subprocess.run(cmd, stdout=slave_fd, stderr=subprocess.PIPE, env=env, text=True)
@@ -66,34 +67,12 @@ def test_it(command: str) -> None:
6667
# Note: Though we don't check stderr, capturing it is useful
6768
# because it provides traceback if mypy crashes due to exception
6869
# and pytest reveals it upon failure (?)
69-
test_pty(True, "mypy -c \"1+'a'\" --color-output=force")
70-
test_pty(False, "mypy -c \"1+'a'\" --no-color-output")
71-
test_not_pty(False, "mypy -c \"1+'a'\" --color-output")
72-
test_not_pty(True, "mypy -c \"1+'a'\" --color-output=force")
73-
test_not_pty(False, "mypy -c \"1+'a'\" --color-output", {"MYPY_FORCE_COLOR": "1"})
74-
test_not_pty(True, "mypy -c \"1+'a'\" --color-output=force", {"MYPY_FORCE_COLOR": "1"})
75-
test_not_pty(False, "mypy -c \"1+'a'\" --no-color-output", {"MYPY_FORCE_COLOR": "1"})
76-
test_not_pty(False, "mypy -c \"1+'a'\" --no-color-output", {"FORCE_COLOR": "1"})
77-
test_not_pty(False, "mypy -c \"1+'a'\" --color-output", {"MYPY_FORCE_COLOR": "0"})
78-
79-
80-
# TODO: Tests in the terminal (require manual testing?)
81-
"""
82-
In the terminal:
83-
colored: mypy -c "1+'a'"
84-
colored: mypy -c "1+'a'" --color-output
85-
not colored: mypy -c "1+'a'" --no-color-output
86-
colored: mypy -c "1+'a'" --color-output (with MYPY_FORCE_COLOR=1)
87-
colored: mypy -c "1+'a'" --no-color-output (with MYPY_FORCE_COLOR=1)
88-
89-
To test, save this as a .bat and run in a Windows terminal (I don't know the Unix equivalent):
90-
91-
set MYPY_FORCE_COLOR=
92-
mypy -c "1+'a'"
93-
mypy -c "1+'a'" --color-output
94-
mypy -c "1+'a'" --no-color-output
95-
set MYPY_FORCE_COLOR=1
96-
mypy -c "1+'a'" --color-output
97-
mypy -c "1+'a'" --no-color-output
98-
set MYPY_FORCE_COLOR=
99-
"""
70+
test_pty(True, f"{command} -c \"1+'a'\" --color-output=force")
71+
test_pty(False, f"{command} -c \"1+'a'\" --no-color-output")
72+
test_not_pty(False, f"{command} -c \"1+'a'\" --color-output")
73+
test_not_pty(True, f"{command} -c \"1+'a'\" --color-output=force")
74+
test_not_pty(False, f"{command} -c \"1+'a'\" --color-output", {"MYPY_FORCE_COLOR": "1"})
75+
test_not_pty(True, f"{command} -c \"1+'a'\" --color-output=force", {"MYPY_FORCE_COLOR": "1"})
76+
test_not_pty(False, f"{command} -c \"1+'a'\" --no-color-output", {"MYPY_FORCE_COLOR": "1"})
77+
test_not_pty(False, f"{command} -c \"1+'a'\" --no-color-output", {"FORCE_COLOR": "1"})
78+
test_not_pty(False, f"{command} -c \"1+'a'\" --color-output", {"MYPY_FORCE_COLOR": "0"})

0 commit comments

Comments
 (0)