9
9
import sys
10
10
import tempfile
11
11
import textwrap
12
- import time
13
12
import unittest
14
13
import warnings
15
14
@@ -123,15 +122,18 @@ def test_forget(self):
123
122
os_helper .unlink (mod_filename )
124
123
os_helper .rmtree ('__pycache__' )
125
124
125
+ @support .requires_working_socket ()
126
126
def test_HOST (self ):
127
127
s = socket .create_server ((socket_helper .HOST , 0 ))
128
128
s .close ()
129
129
130
+ @support .requires_working_socket ()
130
131
def test_find_unused_port (self ):
131
132
port = socket_helper .find_unused_port ()
132
133
s = socket .create_server ((socket_helper .HOST , port ))
133
134
s .close ()
134
135
136
+ @support .requires_working_socket ()
135
137
def test_bind_port (self ):
136
138
s = socket .socket ()
137
139
socket_helper .bind_port (s )
@@ -198,7 +200,7 @@ def test_temp_dir__existing_dir__quiet_true(self):
198
200
f'temporary directory { path !r} : ' ),
199
201
warn )
200
202
201
- @unittest . skipUnless ( hasattr ( os , "fork" ), "test requires os.fork" )
203
+ @support . requires_fork ( )
202
204
def test_temp_dir__forked_child (self ):
203
205
"""Test that a forked child process does not remove the directory."""
204
206
# See bpo-30028 for details.
@@ -308,7 +310,6 @@ def test_temp_cwd__name_none(self):
308
310
def test_sortdict (self ):
309
311
self .assertEqual (support .sortdict ({3 :3 , 2 :2 , 1 :1 }), "{1: 1, 2: 2, 3: 3}" )
310
312
311
- @unittest .skipIf (sys .platform .startswith ("win" ), "TODO: RUSTPYTHON; actual c fds on windows" )
312
313
def test_make_bad_fd (self ):
313
314
fd = os_helper .make_bad_fd ()
314
315
with self .assertRaises (OSError ) as cm :
@@ -429,9 +430,14 @@ def test_check__all__(self):
429
430
extra = extra ,
430
431
not_exported = not_exported )
431
432
432
- extra = {'TextTestResult' , 'installHandler' }
433
+ extra = {
434
+ 'TextTestResult' ,
435
+ 'findTestCases' ,
436
+ 'getTestCaseNames' ,
437
+ 'installHandler' ,
438
+ 'makeSuite' ,
439
+ }
433
440
not_exported = {'load_tests' , "TestProgram" , "BaseTestSuite" }
434
-
435
441
support .check__all__ (self ,
436
442
unittest ,
437
443
("unittest.result" , "unittest.case" ,
@@ -447,6 +453,7 @@ def test_check__all__(self):
447
453
@unittest .expectedFailure
448
454
@unittest .skipUnless (hasattr (os , 'waitpid' ) and hasattr (os , 'WNOHANG' ),
449
455
'need os.waitpid() and os.WNOHANG' )
456
+ @support .requires_fork ()
450
457
def test_reap_children (self ):
451
458
# Make sure that there is no other pending child process
452
459
support .reap_children ()
@@ -457,33 +464,20 @@ def test_reap_children(self):
457
464
# child process: do nothing, just exit
458
465
os ._exit (0 )
459
466
460
- t0 = time .monotonic ()
461
- deadline = time .monotonic () + support .SHORT_TIMEOUT
462
-
463
467
was_altered = support .environment_altered
464
468
try :
465
469
support .environment_altered = False
466
470
stderr = io .StringIO ()
467
471
468
- while True :
469
- if time .monotonic () > deadline :
470
- self .fail ("timeout" )
471
-
472
- old_stderr = sys .__stderr__
473
- try :
474
- sys .__stderr__ = stderr
472
+ for _ in support .sleeping_retry (support .SHORT_TIMEOUT ):
473
+ with support .swap_attr (support .print_warning , 'orig_stderr' , stderr ):
475
474
support .reap_children ()
476
- finally :
477
- sys .__stderr__ = old_stderr
478
475
479
476
# Use environment_altered to check if reap_children() found
480
477
# the child process
481
478
if support .environment_altered :
482
479
break
483
480
484
- # loop until the child process completed
485
- time .sleep (0.100 )
486
-
487
481
msg = "Warning -- reap_children() reaped child process %s" % pid
488
482
self .assertIn (msg , stderr .getvalue ())
489
483
self .assertTrue (support .environment_altered )
@@ -494,6 +488,7 @@ def test_reap_children(self):
494
488
# pending child process
495
489
support .reap_children ()
496
490
491
+ @support .requires_subprocess ()
497
492
def check_options (self , args , func , expected = None ):
498
493
code = f'from test.support import { func } ; print(repr({ func } ()))'
499
494
cmd = [sys .executable , * args , '-c' , code ]
@@ -509,6 +504,8 @@ def check_options(self, args, func, expected=None):
509
504
self .assertEqual (proc .stdout .rstrip (), repr (expected ))
510
505
self .assertEqual (proc .returncode , 0 )
511
506
507
+ # TODO: RUSTPYTHON
508
+ @unittest .expectedFailure
512
509
def test_args_from_interpreter_flags (self ):
513
510
# Test test.support.args_from_interpreter_flags()
514
511
for opts in (
@@ -521,6 +518,7 @@ def test_args_from_interpreter_flags(self):
521
518
['-E' ],
522
519
['-v' ],
523
520
['-b' ],
521
+ ['-P' ],
524
522
['-q' ],
525
523
['-I' ],
526
524
# same option multiple times
@@ -540,7 +538,8 @@ def test_args_from_interpreter_flags(self):
540
538
with self .subTest (opts = opts ):
541
539
self .check_options (opts , 'args_from_interpreter_flags' )
542
540
543
- self .check_options (['-I' , '-E' , '-s' ], 'args_from_interpreter_flags' ,
541
+ self .check_options (['-I' , '-E' , '-s' , '-P' ],
542
+ 'args_from_interpreter_flags' ,
544
543
['-I' ])
545
544
546
545
def test_optim_args_from_interpreter_flags (self ):
@@ -660,11 +659,16 @@ def id(self):
660
659
self .assertFalse (support .match_test (test_access ))
661
660
self .assertTrue (support .match_test (test_chdir ))
662
661
662
+
663
663
@unittest .skipIf (sys .platform .startswith ("win" ), "TODO: RUSTPYTHON; os.dup on windows" )
664
+ @unittest .skipIf (support .is_emscripten , "Unstable in Emscripten" )
665
+ @unittest .skipIf (support .is_wasi , "Unavailable on WASI" )
664
666
def test_fd_count (self ):
665
667
# We cannot test the absolute value of fd_count(): on old Linux
666
668
# kernel or glibc versions, os.urandom() keeps a FD open on
667
669
# /dev/urandom device and Python has 4 FD opens instead of 3.
670
+ # Test is unstable on Emscripten. The platform starts and stops
671
+ # background threads that use pipes and epoll fds.
668
672
start = os_helper .fd_count ()
669
673
fd = os .open (__file__ , os .O_RDONLY )
670
674
try :
@@ -675,14 +679,8 @@ def test_fd_count(self):
675
679
676
680
def check_print_warning (self , msg , expected ):
677
681
stderr = io .StringIO ()
678
-
679
- old_stderr = sys .__stderr__
680
- try :
681
- sys .__stderr__ = stderr
682
+ with support .swap_attr (support .print_warning , 'orig_stderr' , stderr ):
682
683
support .print_warning (msg )
683
- finally :
684
- sys .__stderr__ = old_stderr
685
-
686
684
self .assertEqual (stderr .getvalue (), expected )
687
685
688
686
def test_print_warning (self ):
@@ -691,6 +689,14 @@ def test_print_warning(self):
691
689
self .check_print_warning ("a\n b" ,
692
690
'Warning -- a\n Warning -- b\n ' )
693
691
692
+ # TODO: RUSTPYTHON
693
+ @unittest .expectedFailure
694
+ def test_has_strftime_extensions (self ):
695
+ if support .is_emscripten or sys .platform == "win32" :
696
+ self .assertFalse (support .has_strftime_extensions )
697
+ else :
698
+ self .assertTrue (support .has_strftime_extensions )
699
+
694
700
# XXX -follows a list of untested API
695
701
# make_legacy_pyc
696
702
# is_resource_enabled
@@ -716,4 +722,4 @@ def test_print_warning(self):
716
722
717
723
718
724
if __name__ == '__main__' :
719
- unittest .main ()
725
+ unittest .main ()
0 commit comments