mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Update test_cmd_line_script.py from CPython v3.12.0
This commit is contained in:
35
Lib/test/test_cmd_line_script.py
vendored
35
Lib/test/test_cmd_line_script.py
vendored
@@ -662,9 +662,9 @@ class CmdLineTest(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
stderr.splitlines()[-3:],
|
||||
[
|
||||
b' foo"""',
|
||||
b' ^',
|
||||
b'SyntaxError: f-string: empty expression not allowed',
|
||||
b' foo = f"""{}',
|
||||
b' ^',
|
||||
b'SyntaxError: f-string: valid expression required before \'}\'',
|
||||
],
|
||||
)
|
||||
|
||||
@@ -685,8 +685,31 @@ class CmdLineTest(unittest.TestCase):
|
||||
],
|
||||
)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_syntaxerror_null_bytes(self):
|
||||
script = "x = '\0' nothing to see here\n';import os;os.system('echo pwnd')\n"
|
||||
with os_helper.temp_dir() as script_dir:
|
||||
script_name = _make_test_script(script_dir, 'script', script)
|
||||
exitcode, stdout, stderr = assert_python_failure(script_name)
|
||||
self.assertEqual(
|
||||
stderr.splitlines()[-2:],
|
||||
[ b" x = '",
|
||||
b'SyntaxError: source code cannot contain null bytes'
|
||||
],
|
||||
)
|
||||
|
||||
def test_syntaxerror_null_bytes_in_multiline_string(self):
|
||||
scripts = ["\n'''\nmultilinestring\0\n'''", "\nf'''\nmultilinestring\0\n'''"] # Both normal and f-strings
|
||||
with os_helper.temp_dir() as script_dir:
|
||||
for script in scripts:
|
||||
script_name = _make_test_script(script_dir, 'script', script)
|
||||
_, _, stderr = assert_python_failure(script_name)
|
||||
self.assertEqual(
|
||||
stderr.splitlines()[-2:],
|
||||
[ b" multilinestring",
|
||||
b'SyntaxError: source code cannot contain null bytes'
|
||||
]
|
||||
)
|
||||
|
||||
def test_consistent_sys_path_for_direct_execution(self):
|
||||
# This test case ensures that the following all give the same
|
||||
# sys.path configuration:
|
||||
@@ -785,7 +808,7 @@ class CmdLineTest(unittest.TestCase):
|
||||
with os_helper.temp_dir() as work_dir:
|
||||
script_name = _make_test_script(work_dir, 'script.py', script)
|
||||
with open(script_name, "r") as fp:
|
||||
p = spawn_python(f"/dev/fd/{fp.fileno()}", close_fds=False, pass_fds=(0,1,2,fp.fileno()))
|
||||
p = spawn_python(f"/dev/fd/{fp.fileno()}", close_fds=True, pass_fds=(0,1,2,fp.fileno()))
|
||||
out, err = p.communicate()
|
||||
self.assertEqual(out, b"12345678912345678912345\n")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user