11from subprocess import run , PIPE
22from functools import partial
33from typing import Any
4+ import pytest
45
56# TODO Would like help with this test, how do I make it runnable?
67
78def test (expect_color : bool , * args : Any , ** kwargs : Any ) -> None :
8- res = run (* args , stdout = PIPE , stderr = PIPE , ** kwargs )
9+ res = run (* args , stdout = PIPE , stderr = PIPE , ** kwargs ) #type:ignore[call-overload]
10+ if "Found" not in res .stdout : #??
11+ pytest .fail ("Command failed to complete or did not detect type error" )
912 if expect_color : # Expect color control chars
1013 assert "<string>:1: error:" not in res .stdout
1114 assert "\n Found" not in res .stdout
@@ -16,15 +19,16 @@ def test(expect_color: bool, *args: Any, **kwargs: Any) -> None:
1619colored = partial (test , True )
1720not_colored = partial (test , False )
1821
19- def test_color_output () -> None :
22+ @pytest .mark .parametrize ("command" , ["mypy" , "dmypy run --" ])
23+ def test_color_output (command : str ) -> None :
2024 # Note: Though we don't check stderr, capturing it is useful
2125 # because it provides traceback if mypy crashes due to exception
2226 # and pytest reveals it upon failure (?)
23- not_colored ("mypy -c \" 1+'a'\" " )
24- colored ("mypy -c \" 1+'a'\" " , env = {"MYPY_FORCE_COLOR" : "1" })
25- colored ("mypy -c \" 1+'a'\" --color-output" )
26- not_colored ("mypy -c \" 1+'a'\" --no-color-output" )
27- colored ("mypy -c \" 1+'a'\" --no-color-output" , env = {"MYPY_FORCE_COLOR" : "1" }) #TODO
27+ not_colored (f" { command } -c \" 1+'a'\" " )
28+ colored (f" { command } -c \" 1+'a'\" " , env = {"MYPY_FORCE_COLOR" : "1" })
29+ colored (f" { command } -c \" 1+'a'\" --color-output" )
30+ not_colored (f" { command } -c \" 1+'a'\" --no-color-output" )
31+ colored (f" { command } -c \" 1+'a'\" --no-color-output" , env = {"MYPY_FORCE_COLOR" : "1" }) #TODO
2832
2933# TODO: Tests in the terminal (require manual testing?)
3034"""
0 commit comments