Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 166c45d

Browse files
authored
Merge pull request #3807 from fanninpm/test-like-cpython-buildbottest
Run test suites like how CPython runs theirs
2 parents 66af821 + 092053f commit 166c45d

File tree

9 files changed

+168
-51
lines changed

9 files changed

+168
-51
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,14 @@ jobs:
191191
- if: runner.os == 'Linux'
192192
name: run cpython platform-independent tests
193193
run:
194-
target/release/rustpython -m test -v ${{ env.PLATFORM_INDEPENDENT_TESTS }}
194+
target/release/rustpython -m test -j 1 -u all --slowest --fail-env-changed -v ${{ env.PLATFORM_INDEPENDENT_TESTS }}
195195
- if: runner.os != 'Windows'
196196
name: run cpython platform-dependent tests
197-
run: target/release/rustpython -m test -v -x ${{ env.PLATFORM_INDEPENDENT_TESTS }}
197+
run: target/release/rustpython -m test -j 1 -u all --slowest --fail-env-changed -v -x ${{ env.PLATFORM_INDEPENDENT_TESTS }}
198198
- if: runner.os == 'Windows'
199199
name: run cpython platform-dependent tests (windows partial - fixme)
200200
run:
201-
target/release/rustpython -m test -v -x ${{ env.PLATFORM_INDEPENDENT_TESTS }}
201+
target/release/rustpython -m test -j 1 -u all --slowest --fail-env-changed -v -x ${{ env.PLATFORM_INDEPENDENT_TESTS }}
202202
test_bool
203203
test_cgi
204204
test_exception_hierarchy

Lib/test/test_ntpath.py

Lines changed: 116 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,21 @@ def test_realpath_basic(self):
269269
self.assertPathEqual(ntpath.realpath(os.fsencode(ABSTFN + "1")),
270270
os.fsencode(ABSTFN))
271271

272+
@os_helper.skip_unless_symlink
273+
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
274+
def test_realpath_strict(self):
275+
# Bug #43757: raise FileNotFoundError in strict mode if we encounter
276+
# a path that does not exist.
277+
ABSTFN = ntpath.abspath(os_helper.TESTFN)
278+
os.symlink(ABSTFN + "1", ABSTFN)
279+
self.addCleanup(os_helper.unlink, ABSTFN)
280+
self.assertRaises(FileNotFoundError, ntpath.realpath, ABSTFN, strict=True)
281+
self.assertRaises(FileNotFoundError, ntpath.realpath, ABSTFN + "2", strict=True)
282+
283+
# TODO: RUSTPYTHON, TypeError: got an unexpected keyword argument 'strict'
284+
if sys.platform == "win32":
285+
test_realpath_strict = unittest.expectedFailure(test_realpath_strict)
286+
272287
@os_helper.skip_unless_symlink
273288
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
274289
def test_realpath_relative(self):
@@ -343,8 +358,9 @@ def test_realpath_broken_symlinks(self):
343358
@os_helper.skip_unless_symlink
344359
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
345360
def test_realpath_symlink_loops(self):
346-
# Symlink loops are non-deterministic as to which path is returned, but
347-
# it will always be the fully resolved path of one member of the cycle
361+
# Symlink loops in non-strict mode are non-deterministic as to which
362+
# path is returned, but it will always be the fully resolved path of
363+
# one member of the cycle
348364
ABSTFN = ntpath.abspath(os_helper.TESTFN)
349365
self.addCleanup(os_helper.unlink, ABSTFN)
350366
self.addCleanup(os_helper.unlink, ABSTFN + "1")
@@ -386,6 +402,54 @@ def test_realpath_symlink_loops(self):
386402
# Test using relative path as well.
387403
self.assertPathEqual(ntpath.realpath(ntpath.basename(ABSTFN)), ABSTFN)
388404

405+
@os_helper.skip_unless_symlink
406+
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
407+
def test_realpath_symlink_loops_strict(self):
408+
# Symlink loops raise OSError in strict mode
409+
ABSTFN = ntpath.abspath(os_helper.TESTFN)
410+
self.addCleanup(os_helper.unlink, ABSTFN)
411+
self.addCleanup(os_helper.unlink, ABSTFN + "1")
412+
self.addCleanup(os_helper.unlink, ABSTFN + "2")
413+
self.addCleanup(os_helper.unlink, ABSTFN + "y")
414+
self.addCleanup(os_helper.unlink, ABSTFN + "c")
415+
self.addCleanup(os_helper.unlink, ABSTFN + "a")
416+
417+
os.symlink(ABSTFN, ABSTFN)
418+
self.assertRaises(OSError, ntpath.realpath, ABSTFN, strict=True)
419+
420+
os.symlink(ABSTFN + "1", ABSTFN + "2")
421+
os.symlink(ABSTFN + "2", ABSTFN + "1")
422+
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1", strict=True)
423+
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "2", strict=True)
424+
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\x", strict=True)
425+
# Windows eliminates '..' components before resolving links, so the
426+
# following call is not expected to raise.
427+
self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..", strict=True),
428+
ntpath.dirname(ABSTFN))
429+
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\..\\x", strict=True)
430+
os.symlink(ABSTFN + "x", ABSTFN + "y")
431+
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\..\\"
432+
+ ntpath.basename(ABSTFN) + "y",
433+
strict=True)
434+
self.assertRaises(OSError, ntpath.realpath,
435+
ABSTFN + "1\\..\\" + ntpath.basename(ABSTFN) + "1",
436+
strict=True)
437+
438+
os.symlink(ntpath.basename(ABSTFN) + "a\\b", ABSTFN + "a")
439+
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "a", strict=True)
440+
441+
os.symlink("..\\" + ntpath.basename(ntpath.dirname(ABSTFN))
442+
+ "\\" + ntpath.basename(ABSTFN) + "c", ABSTFN + "c")
443+
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "c", strict=True)
444+
445+
# Test using relative path as well.
446+
self.assertRaises(OSError, ntpath.realpath, ntpath.basename(ABSTFN),
447+
strict=True)
448+
449+
# TODO: RUSTPYTHON, FileExistsError: [Errno 183] Cannot create a file when that file already exists. (os error 183): 'None' -> 'None'
450+
if sys.platform == "win32":
451+
test_realpath_symlink_loops_strict = unittest.expectedFailure(test_realpath_symlink_loops_strict)
452+
389453
@os_helper.skip_unless_symlink
390454
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
391455
def test_realpath_symlink_prefix(self):
@@ -453,6 +517,7 @@ def test_realpath_cwd(self):
453517
with os_helper.change_cwd(test_dir_short):
454518
self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))
455519

520+
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, ValueError: illegal environment variable name")
456521
def test_expandvars(self):
457522
with os_helper.EnvironmentVarGuard() as env:
458523
env.clear()
@@ -479,6 +544,7 @@ def test_expandvars(self):
479544
tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar")
480545
tester('ntpath.expandvars("bar\'%foo%")', "bar\'%foo%")
481546

547+
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, ValueError: illegal environment variable name")
482548
@unittest.skipUnless(os_helper.FS_NONASCII, 'need os_helper.FS_NONASCII')
483549
def test_expandvars_nonascii(self):
484550
def check(value, expected):
@@ -499,41 +565,56 @@ def check(value, expected):
499565
check('%spam%bar', '%sbar' % nonascii)
500566
check('%{}%bar'.format(nonascii), 'ham%sbar' % nonascii)
501567

568+
# TODO: RUSTPYTHON
569+
@unittest.expectedFailure
502570
def test_expanduser(self):
503571
tester('ntpath.expanduser("test")', 'test')
504572

505573
with os_helper.EnvironmentVarGuard() as env:
506574
env.clear()
507575
tester('ntpath.expanduser("~test")', '~test')
508576

509-
env['HOMEPATH'] = 'eric\\idle'
510577
env['HOMEDRIVE'] = 'C:\\'
511-
tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
512-
tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
578+
env['HOMEPATH'] = 'Users\\eric'
579+
env['USERNAME'] = 'eric'
580+
tester('ntpath.expanduser("~test")', 'C:\\Users\\test')
581+
tester('ntpath.expanduser("~")', 'C:\\Users\\eric')
513582

514583
del env['HOMEDRIVE']
515-
tester('ntpath.expanduser("~test")', 'eric\\test')
516-
tester('ntpath.expanduser("~")', 'eric\\idle')
584+
tester('ntpath.expanduser("~test")', 'Users\\test')
585+
tester('ntpath.expanduser("~")', 'Users\\eric')
517586

518587
env.clear()
519-
env['USERPROFILE'] = 'C:\\eric\\idle'
520-
tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
521-
tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
588+
env['USERPROFILE'] = 'C:\\Users\\eric'
589+
env['USERNAME'] = 'eric'
590+
tester('ntpath.expanduser("~test")', 'C:\\Users\\test')
591+
tester('ntpath.expanduser("~")', 'C:\\Users\\eric')
522592
tester('ntpath.expanduser("~test\\foo\\bar")',
523-
'C:\\eric\\test\\foo\\bar')
593+
'C:\\Users\\test\\foo\\bar')
524594
tester('ntpath.expanduser("~test/foo/bar")',
525-
'C:\\eric\\test/foo/bar')
595+
'C:\\Users\\test/foo/bar')
526596
tester('ntpath.expanduser("~\\foo\\bar")',
527-
'C:\\eric\\idle\\foo\\bar')
597+
'C:\\Users\\eric\\foo\\bar')
528598
tester('ntpath.expanduser("~/foo/bar")',
529-
'C:\\eric\\idle/foo/bar')
599+
'C:\\Users\\eric/foo/bar')
530600

531601
# bpo-36264: ignore `HOME` when set on windows
532602
env.clear()
533603
env['HOME'] = 'F:\\'
534-
env['USERPROFILE'] = 'C:\\eric\\idle'
535-
tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
536-
tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
604+
env['USERPROFILE'] = 'C:\\Users\\eric'
605+
env['USERNAME'] = 'eric'
606+
tester('ntpath.expanduser("~test")', 'C:\\Users\\test')
607+
tester('ntpath.expanduser("~")', 'C:\\Users\\eric')
608+
609+
# bpo-39899: don't guess another user's home directory if
610+
# `%USERNAME% != basename(%USERPROFILE%)`
611+
env.clear()
612+
env['USERPROFILE'] = 'C:\\Users\\eric'
613+
env['USERNAME'] = 'idle'
614+
tester('ntpath.expanduser("~test")', '~test')
615+
tester('ntpath.expanduser("~")', 'C:\\Users\\eric')
616+
617+
537618

538619
@unittest.skipUnless(nt, "abspath requires 'nt' module")
539620
def test_abspath(self):
@@ -569,6 +650,10 @@ def test_relpath(self):
569650
tester('ntpath.relpath("/a/b", "/a/b")', '.')
570651
tester('ntpath.relpath("c:/foo", "C:/FOO")', '.')
571652

653+
# TODO: RUSTPYTHON, FileExistsError: [Errno 183] Cannot create a file when that file already exists. (os error 183): 'None' -> 'None'
654+
if sys.platform == "win32":
655+
test_relpath = unittest.expectedFailure(test_relpath)
656+
572657
def test_commonpath(self):
573658
def check(paths, expected):
574659
tester(('ntpath.commonpath(%r)' % paths).replace('\\\\', '\\'),
@@ -728,8 +813,13 @@ class NtCommonTest(test_genericpath.CommonTest, unittest.TestCase):
728813
pathmodule = ntpath
729814
attributes = ['relpath']
730815

731-
def test_expandvars_nonascii(self):
732-
super().test_expandvars_nonascii()
816+
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, ValueError: illegal environment variable name")
817+
def test_expandvars(self): # TODO: RUSTPYTHON, remove when this passes
818+
super().test_expandvars() # TODO: RUSTPYTHON, remove when this passes
819+
820+
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, ValueError: illegal environment variable name")
821+
def test_expandvars_nonascii(self): # TODO: RUSTPYTHON, remove when this passes
822+
super().test_expandvars_nonascii() # TODO: RUSTPYTHON, remove when this passes
733823

734824
# TODO: RUSTPYTHON
735825
if sys.platform == "linux":
@@ -767,7 +857,7 @@ class PathLikeTests(NtpathTestCase):
767857
path = ntpath
768858

769859
def setUp(self):
770-
self.file_name = os_helper.TESTFN.lower()
860+
self.file_name = os_helper.TESTFN
771861
self.file_path = FakePath(os_helper.TESTFN)
772862
self.addCleanup(os_helper.unlink, self.file_name)
773863
with open(self.file_name, 'xb', 0) as file:
@@ -778,6 +868,12 @@ def _check_function(self, func):
778868

779869
def test_path_normcase(self):
780870
self._check_function(self.path.normcase)
871+
if sys.platform == 'win32':
872+
self.assertEqual(ntpath.normcase('\u03a9\u2126'), 'ωΩ')
873+
874+
# TODO: RUSTPYTHON, AssertionError: 'ωω' != 'ωΩ'
875+
if sys.platform == "win32":
876+
test_path_normcase = unittest.expectedFailure(test_path_normcase)
781877

782878
def test_path_isabs(self):
783879
self._check_function(self.path.isabs)

Lib/test/test_script_helper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def tearDown(self):
8282
# Reset the private cached state.
8383
script_helper.__dict__['__cached_interp_requires_environment'] = None
8484

85+
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, ValueError: illegal environment variable name")
8586
@mock.patch('subprocess.check_call')
8687
def test_interpreter_requires_environment_true(self, mock_check_call):
8788
with mock.patch.dict(os.environ):
@@ -91,6 +92,7 @@ def test_interpreter_requires_environment_true(self, mock_check_call):
9192
self.assertTrue(script_helper.interpreter_requires_environment())
9293
self.assertEqual(1, mock_check_call.call_count)
9394

95+
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, ValueError: illegal environment variable name")
9496
@mock.patch('subprocess.check_call')
9597
def test_interpreter_requires_environment_false(self, mock_check_call):
9698
with mock.patch.dict(os.environ):
@@ -100,6 +102,7 @@ def test_interpreter_requires_environment_false(self, mock_check_call):
100102
self.assertFalse(script_helper.interpreter_requires_environment())
101103
self.assertEqual(1, mock_check_call.call_count)
102104

105+
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, ValueError: illegal environment variable name")
103106
@mock.patch('subprocess.check_call')
104107
def test_interpreter_requires_environment_details(self, mock_check_call):
105108
with mock.patch.dict(os.environ):
@@ -112,6 +115,7 @@ def test_interpreter_requires_environment_details(self, mock_check_call):
112115
self.assertEqual(sys.executable, check_call_command[0])
113116
self.assertIn('-E', check_call_command)
114117

118+
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, ValueError: illegal environment variable name")
115119
@mock.patch('subprocess.check_call')
116120
def test_interpreter_requires_environment_with_pythonhome(self, mock_check_call):
117121
with mock.patch.dict(os.environ):

Lib/test/test_socket.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,8 +1487,6 @@ def test_getnameinfo(self):
14871487

14881488
@unittest.skipUnless(support.is_resource_enabled('network'),
14891489
'network is not enabled')
1490-
# TODO: RUSTPYTHON, socket.gethostbyname_ex
1491-
@unittest.expectedFailure
14921490
def test_idna(self):
14931491
# Check for internet access before running test
14941492
# (issue #12804, issue #25138).
@@ -1504,6 +1502,10 @@ def test_idna(self):
15041502
# have a reverse entry yet
15051503
# socket.gethostbyaddr('испытание.python.org')
15061504

1505+
# TODO: RUSTPYTHON, socket.gethostbyname_ex
1506+
if sys.platform != "darwin":
1507+
test_idna = unittest.expectedFailure(test_idna)
1508+
15071509
def check_sendall_interrupted(self, with_timeout):
15081510
# socketpair() is not strictly required, but it makes things easier.
15091511
if not hasattr(signal, 'alarm') or not hasattr(socket, 'socketpair'):

Lib/test/test_socketserver.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,19 @@ def test_TCPServer(self):
185185
socketserver.StreamRequestHandler,
186186
self.stream_examine)
187187

188+
# TODO: RUSTPYTHON, AssertionError: -1 != 18446744073709551615
189+
if os.name == "nt":
190+
test_TCPServer = unittest.expectedFailure(test_TCPServer)
191+
188192
def test_ThreadingTCPServer(self):
189193
self.run_server(socketserver.ThreadingTCPServer,
190194
socketserver.StreamRequestHandler,
191195
self.stream_examine)
192196

197+
# TODO: RUSTPYTHON, AssertionError: -1 != 18446744073709551615
198+
if os.name == "nt":
199+
test_ThreadingTCPServer = unittest.expectedFailure(test_ThreadingTCPServer)
200+
193201
@requires_forking
194202
def test_ForkingTCPServer(self):
195203
with simple_subprocess(self):
@@ -222,11 +230,19 @@ def test_UDPServer(self):
222230
socketserver.DatagramRequestHandler,
223231
self.dgram_examine)
224232

233+
# TODO: RUSTPYTHON, AssertionError: -1 != 18446744073709551615
234+
if os.name == "nt":
235+
test_UDPServer = unittest.expectedFailure(test_UDPServer)
236+
225237
def test_ThreadingUDPServer(self):
226238
self.run_server(socketserver.ThreadingUDPServer,
227239
socketserver.DatagramRequestHandler,
228240
self.dgram_examine)
229241

242+
# TODO: RUSTPYTHON, AssertionError: -1 != 18446744073709551615
243+
if os.name == "nt":
244+
test_ThreadingUDPServer = unittest.expectedFailure(test_ThreadingUDPServer)
245+
230246
@requires_forking
231247
def test_ForkingUDPServer(self):
232248
with simple_subprocess(self):
@@ -302,6 +318,10 @@ def test_context_manager(self):
302318
pass
303319
self.assertEqual(-1, server.socket.fileno())
304320

321+
# TODO: RUSTPYTHON, AssertionError: -1 != 18446744073709551615
322+
if os.name == "nt":
323+
test_context_manager = unittest.expectedFailure(test_context_manager)
324+
305325

306326
class ErrorHandlerTest(unittest.TestCase):
307327
"""Test that the servers pass normal exceptions from the handler to

Lib/test/test_strtod.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ def test_bigcomp(self):
219219
s = '{}e{}'.format(digits, exponent)
220220
self.check_strtod(s)
221221

222-
# TODO: RUSTPYTHON
222+
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, possibly flaky test on Windows?")
223+
# TODO: RUSTPYTHON, Incorrectly rounded str->float conversion for -07e-321
223224
@unittest.expectedFailure
224225
def test_parsing(self):
225226
# make '0' more likely to be chosen than other digits

0 commit comments

Comments
 (0)