comparison tests/test-stdio.py @ 49297:402f9f0f9387

tests: remove Python 2 special cases in test-stdio.py
author Manuel Jacob <me@manueljacob.de>
date Tue, 31 May 2022 02:19:07 +0200
parents b6b6ae9ea91e
children
comparison
equal deleted inserted replaced
49296:b6b6ae9ea91e 49297:402f9f0f9387
209 self._test_buffering('stdout', _pipes, UNBUFFERED, python_args=['-u']) 209 self._test_buffering('stdout', _pipes, UNBUFFERED, python_args=['-u'])
210 210
211 def test_buffering_stdout_ptys_unbuffered(self): 211 def test_buffering_stdout_ptys_unbuffered(self):
212 self._test_buffering('stdout', _ptys, UNBUFFERED, python_args=['-u']) 212 self._test_buffering('stdout', _ptys, UNBUFFERED, python_args=['-u'])
213 213
214 if not pycompat.ispy3 and not pycompat.iswindows:
215 # On Python 2 on non-Windows, we manually open stdout in line-buffered
216 # mode if connected to a TTY. We should check if Python was configured
217 # to use unbuffered stdout, but it's hard to do that.
218 test_buffering_stdout_ptys_unbuffered = unittest.expectedFailure(
219 test_buffering_stdout_ptys_unbuffered
220 )
221
222 def _test_large_write(self, stream, rwpair_generator, python_args=[]): 214 def _test_large_write(self, stream, rwpair_generator, python_args=[]):
223 if not pycompat.ispy3 and pycompat.isdarwin:
224 # Python 2 doesn't always retry on EINTR, but the libc might retry.
225 # So far, it was observed only on macOS that EINTR is raised at the
226 # Python level. As Python 2 support will be dropped soon-ish, we
227 # won't attempt to fix it.
228 raise unittest.SkipTest("raises EINTR on macOS")
229
230 def check_output(stream_receiver, proc): 215 def check_output(stream_receiver, proc):
231 if not pycompat.iswindows: 216 if not pycompat.iswindows:
232 # On Unix, we can provoke a partial write() by interrupting it 217 # On Unix, we can provoke a partial write() by interrupting it
233 # by a signal handler as soon as a bit of data was written. 218 # by a signal handler as soon as a bit of data was written.
234 # We test that write() is called until all data is written. 219 # We test that write() is called until all data is written.
241 self.assertEqual( 226 self.assertEqual(
242 _readall(stream_receiver, 131072, buf), b'x' * 1048576 227 _readall(stream_receiver, 131072, buf), b'x' * 1048576
243 ) 228 )
244 229
245 def post_child_check(): 230 def post_child_check():
246 write_result_str = write_result_f.read() 231 self.assertEqual(write_result_f.read(), '1048576')
247 if pycompat.ispy3:
248 # On Python 3, we test that the correct number of bytes is
249 # claimed to have been written.
250 expected_write_result_str = '1048576'
251 else:
252 # On Python 2, we only check that the large write does not
253 # crash.
254 expected_write_result_str = 'None'
255 self.assertEqual(write_result_str, expected_write_result_str)
256 232
257 with tempfile.NamedTemporaryFile('r') as write_result_f: 233 with tempfile.NamedTemporaryFile('r') as write_result_f:
258 self._test( 234 self._test(
259 TEST_LARGE_WRITE_CHILD_SCRIPT.format( 235 TEST_LARGE_WRITE_CHILD_SCRIPT.format(
260 stream=stream, write_result_fn=write_result_f.name 236 stream=stream, write_result_fn=write_result_f.name