99import sys
1010import tempfile
1111import textwrap
12- import time
1312import unittest
1413import warnings
1514
@@ -123,15 +122,18 @@ def test_forget(self):
123122 os_helper .unlink (mod_filename )
124123 os_helper .rmtree ('__pycache__' )
125124
125+ @support .requires_working_socket ()
126126 def test_HOST (self ):
127127 s = socket .create_server ((socket_helper .HOST , 0 ))
128128 s .close ()
129129
130+ @support .requires_working_socket ()
130131 def test_find_unused_port (self ):
131132 port = socket_helper .find_unused_port ()
132133 s = socket .create_server ((socket_helper .HOST , port ))
133134 s .close ()
134135
136+ @support .requires_working_socket ()
135137 def test_bind_port (self ):
136138 s = socket .socket ()
137139 socket_helper .bind_port (s )
@@ -198,7 +200,7 @@ def test_temp_dir__existing_dir__quiet_true(self):
198200 f'temporary directory { path !r} : ' ),
199201 warn )
200202
201- @unittest . skipUnless ( hasattr ( os , "fork" ), "test requires os.fork" )
203+ @support . requires_fork ( )
202204 def test_temp_dir__forked_child (self ):
203205 """Test that a forked child process does not remove the directory."""
204206 # See bpo-30028 for details.
@@ -308,7 +310,6 @@ def test_temp_cwd__name_none(self):
308310 def test_sortdict (self ):
309311 self .assertEqual (support .sortdict ({3 :3 , 2 :2 , 1 :1 }), "{1: 1, 2: 2, 3: 3}" )
310312
311- @unittest .skipIf (sys .platform .startswith ("win" ), "TODO: RUSTPYTHON; actual c fds on windows" )
312313 def test_make_bad_fd (self ):
313314 fd = os_helper .make_bad_fd ()
314315 with self .assertRaises (OSError ) as cm :
@@ -429,9 +430,14 @@ def test_check__all__(self):
429430 extra = extra ,
430431 not_exported = not_exported )
431432
432- extra = {'TextTestResult' , 'installHandler' }
433+ extra = {
434+ 'TextTestResult' ,
435+ 'findTestCases' ,
436+ 'getTestCaseNames' ,
437+ 'installHandler' ,
438+ 'makeSuite' ,
439+ }
433440 not_exported = {'load_tests' , "TestProgram" , "BaseTestSuite" }
434-
435441 support .check__all__ (self ,
436442 unittest ,
437443 ("unittest.result" , "unittest.case" ,
@@ -447,6 +453,7 @@ def test_check__all__(self):
447453 @unittest .expectedFailure
448454 @unittest .skipUnless (hasattr (os , 'waitpid' ) and hasattr (os , 'WNOHANG' ),
449455 'need os.waitpid() and os.WNOHANG' )
456+ @support .requires_fork ()
450457 def test_reap_children (self ):
451458 # Make sure that there is no other pending child process
452459 support .reap_children ()
@@ -457,33 +464,20 @@ def test_reap_children(self):
457464 # child process: do nothing, just exit
458465 os ._exit (0 )
459466
460- t0 = time .monotonic ()
461- deadline = time .monotonic () + support .SHORT_TIMEOUT
462-
463467 was_altered = support .environment_altered
464468 try :
465469 support .environment_altered = False
466470 stderr = io .StringIO ()
467471
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 ):
475474 support .reap_children ()
476- finally :
477- sys .__stderr__ = old_stderr
478475
479476 # Use environment_altered to check if reap_children() found
480477 # the child process
481478 if support .environment_altered :
482479 break
483480
484- # loop until the child process completed
485- time .sleep (0.100 )
486-
487481 msg = "Warning -- reap_children() reaped child process %s" % pid
488482 self .assertIn (msg , stderr .getvalue ())
489483 self .assertTrue (support .environment_altered )
@@ -494,6 +488,7 @@ def test_reap_children(self):
494488 # pending child process
495489 support .reap_children ()
496490
491+ @support .requires_subprocess ()
497492 def check_options (self , args , func , expected = None ):
498493 code = f'from test.support import { func } ; print(repr({ func } ()))'
499494 cmd = [sys .executable , * args , '-c' , code ]
@@ -509,6 +504,8 @@ def check_options(self, args, func, expected=None):
509504 self .assertEqual (proc .stdout .rstrip (), repr (expected ))
510505 self .assertEqual (proc .returncode , 0 )
511506
507+ # TODO: RUSTPYTHON
508+ @unittest .expectedFailure
512509 def test_args_from_interpreter_flags (self ):
513510 # Test test.support.args_from_interpreter_flags()
514511 for opts in (
@@ -521,6 +518,7 @@ def test_args_from_interpreter_flags(self):
521518 ['-E' ],
522519 ['-v' ],
523520 ['-b' ],
521+ ['-P' ],
524522 ['-q' ],
525523 ['-I' ],
526524 # same option multiple times
@@ -540,7 +538,8 @@ def test_args_from_interpreter_flags(self):
540538 with self .subTest (opts = opts ):
541539 self .check_options (opts , 'args_from_interpreter_flags' )
542540
543- self .check_options (['-I' , '-E' , '-s' ], 'args_from_interpreter_flags' ,
541+ self .check_options (['-I' , '-E' , '-s' , '-P' ],
542+ 'args_from_interpreter_flags' ,
544543 ['-I' ])
545544
546545 def test_optim_args_from_interpreter_flags (self ):
@@ -660,11 +659,16 @@ def id(self):
660659 self .assertFalse (support .match_test (test_access ))
661660 self .assertTrue (support .match_test (test_chdir ))
662661
662+
663663 @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" )
664666 def test_fd_count (self ):
665667 # We cannot test the absolute value of fd_count(): on old Linux
666668 # kernel or glibc versions, os.urandom() keeps a FD open on
667669 # /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.
668672 start = os_helper .fd_count ()
669673 fd = os .open (__file__ , os .O_RDONLY )
670674 try :
@@ -675,14 +679,8 @@ def test_fd_count(self):
675679
676680 def check_print_warning (self , msg , expected ):
677681 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 ):
682683 support .print_warning (msg )
683- finally :
684- sys .__stderr__ = old_stderr
685-
686684 self .assertEqual (stderr .getvalue (), expected )
687685
688686 def test_print_warning (self ):
@@ -691,6 +689,14 @@ def test_print_warning(self):
691689 self .check_print_warning ("a\n b" ,
692690 'Warning -- a\n Warning -- b\n ' )
693691
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+
694700 # XXX -follows a list of untested API
695701 # make_legacy_pyc
696702 # is_resource_enabled
@@ -716,4 +722,4 @@ def test_print_warning(self):
716722
717723
718724if __name__ == '__main__' :
719- unittest .main ()
725+ unittest .main ()
0 commit comments