44
55# TODO Would like help with this test, how do I make it runnable?
66
7+ def test (expect_color : bool , * args : Any , ** kwargs : Any ) -> None :
8+ res = run (* args , stdout = PIPE , stderr = PIPE , ** kwargs )
9+ if expect_color : # Expect color control chars
10+ assert "<string>:1: error:" not in res .stdout
11+ assert "\n Found" not in res .stdout
12+ else : # Expect no color control chars
13+ assert "<string>:1: error:" in res .stdout
14+ assert "\n Found" in res .stdout
15+
16+ colored = partial (test , True )
17+ not_colored = partial (test , False )
18+
719def test_color_output () -> None :
820 # Note: Though we don't check stderr, capturing it is useful
921 # because it provides traceback if mypy crashes due to exception
1022 # and pytest reveals it upon failure (?)
11- def test (expect_color : bool , * args : Any , ** kwargs : Any ) -> None :
12- res = run (* args , stdout = PIPE , stderr = PIPE , ** kwargs )
13- if expect_color : # Expect color control chars
14- assert "<string>:1: error:" not in res .stdout
15- assert "]\n Found" not in res .stdout
16- else : # Expect no color control chars
17- assert "<string>:1: error:" in res .stdout
18- assert "]\n Found" in res .stdout
19- colored = partial (test , True )
20- not_colored = partial (test , False )
2123 not_colored ("mypy -c \" 1+'a'\" " )
2224 colored ("mypy -c \" 1+'a'\" " , env = {"MYPY_FORCE_COLOR" : "1" })
2325 colored ("mypy -c \" 1+'a'\" --color-output" )
2426 not_colored ("mypy -c \" 1+'a'\" --no-color-output" )
25- colored ("mypy -c \" 1+'a'\" --no-color-output" , env = {"MYPY_FORCE_COLOR" : "1" })
27+ colored ("mypy -c \" 1+'a'\" --no-color-output" , env = {"MYPY_FORCE_COLOR" : "1" }) #TODO
28+
29+ # TODO: Tests in the terminal (require manual testing?)
30+ """
31+ In the terminal:
32+ colored: mypy -c "1+'a'"
33+ colored: mypy -c "1+'a'" --color-output
34+ not colored: mypy -c "1+'a'" --no-color-output
35+ colored: mypy -c "1+'a'" --color-output (with MYPY_FORCE_COLOR=1)
36+ colored: mypy -c "1+'a'" --no-color-output (with MYPY_FORCE_COLOR=1)
37+
38+ To test, save this as a .bat and run in a Windows terminal (I don't know the Unix equivalent):
2639
27- # TODO: Tests in the terminal (require manual testing?)
40+ set MYPY_FORCE_COLOR=
41+ mypy -c "1+'a'"
42+ mypy -c "1+'a'" --color-output
43+ mypy -c "1+'a'" --no-color-output
44+ set MYPY_FORCE_COLOR=1
45+ mypy -c "1+'a'" --color-output
46+ mypy -c "1+'a'" --no-color-output
47+ set MYPY_FORCE_COLOR=
48+ """
0 commit comments