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

Skip to content

Run test suites like how CPython runs theirs #3807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ jobs:
- if: runner.os == 'Linux'
name: run cpython platform-independent tests
run:
target/release/rustpython -m test -v ${{ env.PLATFORM_INDEPENDENT_TESTS }}
target/release/rustpython -m test -j 1 -u all --slowest --fail-env-changed -v ${{ env.PLATFORM_INDEPENDENT_TESTS }}
- if: runner.os != 'Windows'
name: run cpython platform-dependent tests
run: target/release/rustpython -m test -v -x ${{ env.PLATFORM_INDEPENDENT_TESTS }}
run: target/release/rustpython -m test -j 1 -u all --slowest --fail-env-changed -v -x ${{ env.PLATFORM_INDEPENDENT_TESTS }}
- if: runner.os == 'Windows'
name: run cpython platform-dependent tests (windows partial - fixme)
run:
target/release/rustpython -m test -v -x ${{ env.PLATFORM_INDEPENDENT_TESTS }}
target/release/rustpython -m test -j 1 -u all --slowest --fail-env-changed -v -x ${{ env.PLATFORM_INDEPENDENT_TESTS }}
test_bool
test_cgi
test_exception_hierarchy
Expand Down
136 changes: 116 additions & 20 deletions Lib/test/test_ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,21 @@ def test_realpath_basic(self):
self.assertPathEqual(ntpath.realpath(os.fsencode(ABSTFN + "1")),
os.fsencode(ABSTFN))

@os_helper.skip_unless_symlink
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
def test_realpath_strict(self):
# Bug #43757: raise FileNotFoundError in strict mode if we encounter
# a path that does not exist.
ABSTFN = ntpath.abspath(os_helper.TESTFN)
os.symlink(ABSTFN + "1", ABSTFN)
self.addCleanup(os_helper.unlink, ABSTFN)
self.assertRaises(FileNotFoundError, ntpath.realpath, ABSTFN, strict=True)
self.assertRaises(FileNotFoundError, ntpath.realpath, ABSTFN + "2", strict=True)

# TODO: RUSTPYTHON, TypeError: got an unexpected keyword argument 'strict'
if sys.platform == "win32":
test_realpath_strict = unittest.expectedFailure(test_realpath_strict)

@os_helper.skip_unless_symlink
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
def test_realpath_relative(self):
Expand Down Expand Up @@ -343,8 +358,9 @@ def test_realpath_broken_symlinks(self):
@os_helper.skip_unless_symlink
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
def test_realpath_symlink_loops(self):
# Symlink loops are non-deterministic as to which path is returned, but
# it will always be the fully resolved path of one member of the cycle
# Symlink loops in non-strict mode are non-deterministic as to which
# path is returned, but it will always be the fully resolved path of
# one member of the cycle
ABSTFN = ntpath.abspath(os_helper.TESTFN)
self.addCleanup(os_helper.unlink, ABSTFN)
self.addCleanup(os_helper.unlink, ABSTFN + "1")
Expand Down Expand Up @@ -386,6 +402,54 @@ def test_realpath_symlink_loops(self):
# Test using relative path as well.
self.assertPathEqual(ntpath.realpath(ntpath.basename(ABSTFN)), ABSTFN)

@os_helper.skip_unless_symlink
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
def test_realpath_symlink_loops_strict(self):
# Symlink loops raise OSError in strict mode
ABSTFN = ntpath.abspath(os_helper.TESTFN)
self.addCleanup(os_helper.unlink, ABSTFN)
self.addCleanup(os_helper.unlink, ABSTFN + "1")
self.addCleanup(os_helper.unlink, ABSTFN + "2")
self.addCleanup(os_helper.unlink, ABSTFN + "y")
self.addCleanup(os_helper.unlink, ABSTFN + "c")
self.addCleanup(os_helper.unlink, ABSTFN + "a")

os.symlink(ABSTFN, ABSTFN)
self.assertRaises(OSError, ntpath.realpath, ABSTFN, strict=True)

os.symlink(ABSTFN + "1", ABSTFN + "2")
os.symlink(ABSTFN + "2", ABSTFN + "1")
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1", strict=True)
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "2", strict=True)
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\x", strict=True)
# Windows eliminates '..' components before resolving links, so the
# following call is not expected to raise.
self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..", strict=True),
ntpath.dirname(ABSTFN))
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\..\\x", strict=True)
os.symlink(ABSTFN + "x", ABSTFN + "y")
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\..\\"
+ ntpath.basename(ABSTFN) + "y",
strict=True)
self.assertRaises(OSError, ntpath.realpath,
ABSTFN + "1\\..\\" + ntpath.basename(ABSTFN) + "1",
strict=True)

os.symlink(ntpath.basename(ABSTFN) + "a\\b", ABSTFN + "a")
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "a", strict=True)

os.symlink("..\\" + ntpath.basename(ntpath.dirname(ABSTFN))
+ "\\" + ntpath.basename(ABSTFN) + "c", ABSTFN + "c")
self.assertRaises(OSError, ntpath.realpath, ABSTFN + "c", strict=True)

# Test using relative path as well.
self.assertRaises(OSError, ntpath.realpath, ntpath.basename(ABSTFN),
strict=True)

# TODO: RUSTPYTHON, FileExistsError: [Errno 183] Cannot create a file when that file already exists. (os error 183): 'None' -> 'None'
if sys.platform == "win32":
test_realpath_symlink_loops_strict = unittest.expectedFailure(test_realpath_symlink_loops_strict)

@os_helper.skip_unless_symlink
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
def test_realpath_symlink_prefix(self):
Expand Down Expand Up @@ -453,6 +517,7 @@ def test_realpath_cwd(self):
with os_helper.change_cwd(test_dir_short):
self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))

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

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

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_expanduser(self):
tester('ntpath.expanduser("test")', 'test')

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

env['HOMEPATH'] = 'eric\\idle'
env['HOMEDRIVE'] = 'C:\\'
tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
env['HOMEPATH'] = 'Users\\eric'
env['USERNAME'] = 'eric'
tester('ntpath.expanduser("~test")', 'C:\\Users\\test')
tester('ntpath.expanduser("~")', 'C:\\Users\\eric')

del env['HOMEDRIVE']
tester('ntpath.expanduser("~test")', 'eric\\test')
tester('ntpath.expanduser("~")', 'eric\\idle')
tester('ntpath.expanduser("~test")', 'Users\\test')
tester('ntpath.expanduser("~")', 'Users\\eric')

env.clear()
env['USERPROFILE'] = 'C:\\eric\\idle'
tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
env['USERPROFILE'] = 'C:\\Users\\eric'
env['USERNAME'] = 'eric'
tester('ntpath.expanduser("~test")', 'C:\\Users\\test')
tester('ntpath.expanduser("~")', 'C:\\Users\\eric')
tester('ntpath.expanduser("~test\\foo\\bar")',
'C:\\eric\\test\\foo\\bar')
'C:\\Users\\test\\foo\\bar')
tester('ntpath.expanduser("~test/foo/bar")',
'C:\\eric\\test/foo/bar')
'C:\\Users\\test/foo/bar')
tester('ntpath.expanduser("~\\foo\\bar")',
'C:\\eric\\idle\\foo\\bar')
'C:\\Users\\eric\\foo\\bar')
tester('ntpath.expanduser("~/foo/bar")',
'C:\\eric\\idle/foo/bar')
'C:\\Users\\eric/foo/bar')

# bpo-36264: ignore `HOME` when set on windows
env.clear()
env['HOME'] = 'F:\\'
env['USERPROFILE'] = 'C:\\eric\\idle'
tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
env['USERPROFILE'] = 'C:\\Users\\eric'
env['USERNAME'] = 'eric'
tester('ntpath.expanduser("~test")', 'C:\\Users\\test')
tester('ntpath.expanduser("~")', 'C:\\Users\\eric')

# bpo-39899: don't guess another user's home directory if
# `%USERNAME% != basename(%USERPROFILE%)`
env.clear()
env['USERPROFILE'] = 'C:\\Users\\eric'
env['USERNAME'] = 'idle'
tester('ntpath.expanduser("~test")', '~test')
tester('ntpath.expanduser("~")', 'C:\\Users\\eric')



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

# TODO: RUSTPYTHON, FileExistsError: [Errno 183] Cannot create a file when that file already exists. (os error 183): 'None' -> 'None'
if sys.platform == "win32":
test_relpath = unittest.expectedFailure(test_relpath)

def test_commonpath(self):
def check(paths, expected):
tester(('ntpath.commonpath(%r)' % paths).replace('\\\\', '\\'),
Expand Down Expand Up @@ -728,8 +813,13 @@ class NtCommonTest(test_genericpath.CommonTest, unittest.TestCase):
pathmodule = ntpath
attributes = ['relpath']

def test_expandvars_nonascii(self):
super().test_expandvars_nonascii()
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, ValueError: illegal environment variable name")
def test_expandvars(self): # TODO: RUSTPYTHON, remove when this passes
super().test_expandvars() # TODO: RUSTPYTHON, remove when this passes

@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, ValueError: illegal environment variable name")
def test_expandvars_nonascii(self): # TODO: RUSTPYTHON, remove when this passes
super().test_expandvars_nonascii() # TODO: RUSTPYTHON, remove when this passes

# TODO: RUSTPYTHON
if sys.platform == "linux":
Expand Down Expand Up @@ -767,7 +857,7 @@ class PathLikeTests(NtpathTestCase):
path = ntpath

def setUp(self):
self.file_name = os_helper.TESTFN.lower()
self.file_name = os_helper.TESTFN
self.file_path = FakePath(os_helper.TESTFN)
self.addCleanup(os_helper.unlink, self.file_name)
with open(self.file_name, 'xb', 0) as file:
Expand All @@ -778,6 +868,12 @@ def _check_function(self, func):

def test_path_normcase(self):
self._check_function(self.path.normcase)
if sys.platform == 'win32':
self.assertEqual(ntpath.normcase('\u03a9\u2126'), 'ωΩ')

# TODO: RUSTPYTHON, AssertionError: 'ωω' != 'ωΩ'
if sys.platform == "win32":
test_path_normcase = unittest.expectedFailure(test_path_normcase)

def test_path_isabs(self):
self._check_function(self.path.isabs)
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_script_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def tearDown(self):
# Reset the private cached state.
script_helper.__dict__['__cached_interp_requires_environment'] = None

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

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

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

@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, ValueError: illegal environment variable name")
@mock.patch('subprocess.check_call')
def test_interpreter_requires_environment_with_pythonhome(self, mock_check_call):
with mock.patch.dict(os.environ):
Expand Down
6 changes: 4 additions & 2 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,8 +1487,6 @@ def test_getnameinfo(self):

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

# TODO: RUSTPYTHON, socket.gethostbyname_ex
if sys.platform != "darwin":
test_idna = unittest.expectedFailure(test_idna)

def check_sendall_interrupted(self, with_timeout):
# socketpair() is not strictly required, but it makes things easier.
if not hasattr(signal, 'alarm') or not hasattr(socket, 'socketpair'):
Expand Down
20 changes: 20 additions & 0 deletions Lib/test/test_socketserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,19 @@ def test_TCPServer(self):
socketserver.StreamRequestHandler,
self.stream_examine)

# TODO: RUSTPYTHON, AssertionError: -1 != 18446744073709551615
if os.name == "nt":
test_TCPServer = unittest.expectedFailure(test_TCPServer)

def test_ThreadingTCPServer(self):
self.run_server(socketserver.ThreadingTCPServer,
socketserver.StreamRequestHandler,
self.stream_examine)

# TODO: RUSTPYTHON, AssertionError: -1 != 18446744073709551615
if os.name == "nt":
test_ThreadingTCPServer = unittest.expectedFailure(test_ThreadingTCPServer)

@requires_forking
def test_ForkingTCPServer(self):
with simple_subprocess(self):
Expand Down Expand Up @@ -222,11 +230,19 @@ def test_UDPServer(self):
socketserver.DatagramRequestHandler,
self.dgram_examine)

# TODO: RUSTPYTHON, AssertionError: -1 != 18446744073709551615
if os.name == "nt":
test_UDPServer = unittest.expectedFailure(test_UDPServer)

def test_ThreadingUDPServer(self):
self.run_server(socketserver.ThreadingUDPServer,
socketserver.DatagramRequestHandler,
self.dgram_examine)

# TODO: RUSTPYTHON, AssertionError: -1 != 18446744073709551615
if os.name == "nt":
test_ThreadingUDPServer = unittest.expectedFailure(test_ThreadingUDPServer)

@requires_forking
def test_ForkingUDPServer(self):
with simple_subprocess(self):
Expand Down Expand Up @@ -302,6 +318,10 @@ def test_context_manager(self):
pass
self.assertEqual(-1, server.socket.fileno())

# TODO: RUSTPYTHON, AssertionError: -1 != 18446744073709551615
if os.name == "nt":
test_context_manager = unittest.expectedFailure(test_context_manager)


class ErrorHandlerTest(unittest.TestCase):
"""Test that the servers pass normal exceptions from the handler to
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_strtod.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ def test_bigcomp(self):
s = '{}e{}'.format(digits, exponent)
self.check_strtod(s)

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