Skip to content

Commit 0fab6e6

Browse files
authored
Merge pull request RustPython#5127 from NakanoMiku39/main
Update test files from CPython v3.12.0
2 parents dc4f699 + 784b5f1 commit 0fab6e6

17 files changed

+1186
-61
lines changed

Lib/test/test_cmd_line.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
if not support.has_subprocess_support:
1919
raise unittest.SkipTest("test module requires subprocess")
2020

21-
# Debug build?
22-
Py_DEBUG = hasattr(sys, "gettotalrefcount")
23-
2421

2522
# XXX (ncoghlan): Move to script_helper and make consistent with run_python
2623
def _kill_python_and_exit_code(p):
@@ -144,7 +141,7 @@ def run_python(*args):
144141
# "-X showrefcount" shows the refcount, but only in debug builds
145142
rc, out, err = run_python('-I', '-X', 'showrefcount', '-c', code)
146143
self.assertEqual(out.rstrip(), b"{'showrefcount': True}")
147-
if Py_DEBUG:
144+
if support.Py_DEBUG:
148145
# bpo-46417: Tolerate negative reference count which can occur
149146
# because of bugs in C extensions. This test is only about checking
150147
# the showrefcount feature.
@@ -753,7 +750,7 @@ def test_xdev(self):
753750
code = ("import warnings; "
754751
"print(' '.join('%s::%s' % (f[0], f[2].__name__) "
755752
"for f in warnings.filters))")
756-
if Py_DEBUG:
753+
if support.Py_DEBUG:
757754
expected_filters = "default::Warning"
758755
else:
759756
expected_filters = ("default::Warning "
@@ -827,7 +824,7 @@ def test_warnings_filter_precedence(self):
827824
expected_filters = ("error::BytesWarning "
828825
"once::UserWarning "
829826
"always::UserWarning")
830-
if not Py_DEBUG:
827+
if not support.Py_DEBUG:
831828
expected_filters += (" "
832829
"default::DeprecationWarning "
833830
"ignore::DeprecationWarning "
@@ -867,10 +864,10 @@ def test_pythonmalloc(self):
867864
# Test the PYTHONMALLOC environment variable
868865
pymalloc = support.with_pymalloc()
869866
if pymalloc:
870-
default_name = 'pymalloc_debug' if Py_DEBUG else 'pymalloc'
867+
default_name = 'pymalloc_debug' if support.Py_DEBUG else 'pymalloc'
871868
default_name_debug = 'pymalloc_debug'
872869
else:
873-
default_name = 'malloc_debug' if Py_DEBUG else 'malloc'
870+
default_name = 'malloc_debug' if support.Py_DEBUG else 'malloc'
874871
default_name_debug = 'malloc_debug'
875872

876873
tests = [
@@ -933,6 +930,8 @@ def test_parsing_error(self):
933930
self.assertTrue(proc.stderr.startswith(err_msg), proc.stderr)
934931
self.assertNotEqual(proc.returncode, 0)
935932

933+
# TODO: RUSTPYTHON
934+
@unittest.expectedFailure
936935
def test_int_max_str_digits(self):
937936
code = "import sys; print(sys.flags.int_max_str_digits, sys.get_int_max_str_digits())"
938937

@@ -950,7 +949,8 @@ def res2int(res):
950949
return tuple(int(i) for i in out.split())
951950

952951
res = assert_python_ok('-c', code)
953-
self.assertEqual(res2int(res), (-1, sys.get_int_max_str_digits()))
952+
current_max = sys.get_int_max_str_digits()
953+
self.assertEqual(res2int(res), (current_max, current_max))
954954
res = assert_python_ok('-X', 'int_max_str_digits=0', '-c', code)
955955
self.assertEqual(res2int(res), (0, 0))
956956
res = assert_python_ok('-X', 'int_max_str_digits=4000', '-c', code)

Lib/test/test_cmd_line_script.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,9 @@ def test_syntaxerror_multi_line_fstring(self):
662662
self.assertEqual(
663663
stderr.splitlines()[-3:],
664664
[
665-
b' foo"""',
666-
b' ^',
667-
b'SyntaxError: f-string: empty expression not allowed',
665+
b' foo = f"""{}',
666+
b' ^',
667+
b'SyntaxError: f-string: valid expression required before \'}\'',
668668
],
669669
)
670670

@@ -685,6 +685,35 @@ def test_syntaxerror_invalid_escape_sequence_multi_line(self):
685685
],
686686
)
687687

688+
# TODO: RUSTPYTHON
689+
@unittest.expectedFailure
690+
def test_syntaxerror_null_bytes(self):
691+
script = "x = '\0' nothing to see here\n';import os;os.system('echo pwnd')\n"
692+
with os_helper.temp_dir() as script_dir:
693+
script_name = _make_test_script(script_dir, 'script', script)
694+
exitcode, stdout, stderr = assert_python_failure(script_name)
695+
self.assertEqual(
696+
stderr.splitlines()[-2:],
697+
[ b" x = '",
698+
b'SyntaxError: source code cannot contain null bytes'
699+
],
700+
)
701+
702+
# TODO: RUSTPYTHON
703+
@unittest.expectedFailure
704+
def test_syntaxerror_null_bytes_in_multiline_string(self):
705+
scripts = ["\n'''\nmultilinestring\0\n'''", "\nf'''\nmultilinestring\0\n'''"] # Both normal and f-strings
706+
with os_helper.temp_dir() as script_dir:
707+
for script in scripts:
708+
script_name = _make_test_script(script_dir, 'script', script)
709+
_, _, stderr = assert_python_failure(script_name)
710+
self.assertEqual(
711+
stderr.splitlines()[-2:],
712+
[ b" multilinestring",
713+
b'SyntaxError: source code cannot contain null bytes'
714+
]
715+
)
716+
688717
# TODO: RUSTPYTHON
689718
@unittest.expectedFailure
690719
def test_consistent_sys_path_for_direct_execution(self):
@@ -785,7 +814,7 @@ def test_script_as_dev_fd(self):
785814
with os_helper.temp_dir() as work_dir:
786815
script_name = _make_test_script(work_dir, 'script.py', script)
787816
with open(script_name, "r") as fp:
788-
p = spawn_python(f"/dev/fd/{fp.fileno()}", close_fds=False, pass_fds=(0,1,2,fp.fileno()))
817+
p = spawn_python(f"/dev/fd/{fp.fileno()}", close_fds=True, pass_fds=(0,1,2,fp.fileno()))
789818
out, err = p.communicate()
790819
self.assertEqual(out, b"12345678912345678912345\n")
791820

Lib/test/test_code_module.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from unittest import mock
77
from test.support import import_helper
88

9+
910
code = import_helper.import_module('code')
1011

1112

0 commit comments

Comments
 (0)