@@ -137,19 +137,20 @@ def make_file(self, base: str, path: str) -> None:
137
137
138
138
139
139
class DaemonWatchSuite (unittest .TestCase ):
140
- def setUp (self ):
140
+ def setUp (self ) -> None :
141
141
self .temp_dir = tempfile .TemporaryDirectory ()
142
142
self .temp_path = pathlib .Path (self .temp_dir .name )
143
143
self .output_lines = []
144
144
self .stop_reader = False
145
145
146
- def _read_output (self ):
146
+ def _read_output (self ) -> None :
147
+ assert self .process , "Use self._start_watching before reading the output!"
147
148
for line in self .process .stdout :
148
149
self .output_lines .append (line .strip ())
149
150
if self .stop_reader :
150
151
break
151
152
152
- def _start_watching (self , args : str , start_daemon : bool = True ):
153
+ def _start_watching (self , args : str , start_daemon : bool = True ) -> None :
153
154
if start_daemon :
154
155
subprocess .run (
155
156
[sys .executable , "-m" , "mypy.dmypy" , "start" ],
@@ -172,7 +173,7 @@ def _start_watching(self, args: str, start_daemon: bool = True):
172
173
self .reader_thread = threading .Thread (target = self ._read_output , daemon = True )
173
174
self .reader_thread .start ()
174
175
175
- def _wait_for_output (self , text : str , timeout = 5 ) :
176
+ def _wait_for_output (self , text : str , timeout : int = 5 ) -> bool :
176
177
"""Wait for text to appear in output within timeout seconds."""
177
178
start_time = time .time ()
178
179
while time .time () - start_time < timeout :
@@ -181,7 +182,7 @@ def _wait_for_output(self, text: str, timeout=5):
181
182
time .sleep (0.1 )
182
183
return False
183
184
184
- def test_watcher_reacts_to_file_changes (self ):
185
+ def test_watcher_reacts_to_file_changes (self ) -> None :
185
186
(self .temp_path / "valid.py" ).write_text (
186
187
"def hello_world() -> str:\n return 'Hello World!'"
187
188
)
@@ -198,7 +199,7 @@ def test_watcher_reacts_to_file_changes(self):
198
199
self .assertTrue (self ._wait_for_output ("Incompatible return value type" ))
199
200
self .assertTrue (self ._wait_for_output ("Found 1 error in 1 file" ))
200
201
201
- def tearDown (self ):
202
+ def tearDown (self ) -> None :
202
203
print (self .output_lines )
203
204
subprocess .run ([sys .executable , "-m" , "mypy.dmypy" , "stop" ], cwd = self .temp_path )
204
205
0 commit comments