@@ -69,7 +69,7 @@ def test(*args: Any, **kwargs: Any) -> None:
6969 output = run_stubtest (
7070 stub = "\n \n " .join (textwrap .dedent (c .stub .lstrip ("\n " )) for c in cases ),
7171 runtime = "\n \n " .join (textwrap .dedent (c .runtime .lstrip ("\n " )) for c in cases ),
72- options = ["--generate-whitelist" ]
72+ options = ["--generate-whitelist" ],
7373 )
7474
7575 actual_errors = set (output .splitlines ())
@@ -609,19 +609,23 @@ def test_ignore_flags(self) -> None:
609609 assert not output
610610
611611 def test_whitelist (self ) -> None :
612- with tempfile .NamedTemporaryFile () as f :
613- f .write ("{}.bad\n # a comment" .format (TEST_MODULE_NAME ).encode ("utf-8" ))
614- f .flush ()
612+ # Can't use this as a context because Windows
613+ whitelist = tempfile .NamedTemporaryFile (mode = "w" , delete = False )
614+ try :
615+ with whitelist :
616+ whitelist .write ("{}.bad\n # a comment" .format (TEST_MODULE_NAME ))
615617
616618 output = run_stubtest (
617619 stub = "def bad(number: int, text: str) -> None: ..." ,
618620 runtime = "def bad(num, text) -> None: pass" ,
619- options = ["--whitelist" , f .name ],
621+ options = ["--whitelist" , whitelist .name ],
620622 )
621623 assert not output
622624
623- output = run_stubtest (stub = "" , runtime = "" , options = ["--whitelist" , f .name ])
625+ output = run_stubtest (stub = "" , runtime = "" , options = ["--whitelist" , whitelist .name ])
624626 assert output == "note: unused whitelist entry {}.bad\n " .format (TEST_MODULE_NAME )
627+ finally :
628+ os .unlink (whitelist .name )
625629
626630 def test_mypy_build (self ) -> None :
627631 output = run_stubtest (stub = "+" , runtime = "" , options = [])
0 commit comments