Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Update test_cmd_line_script from Cpython v3.11.2 #4802

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 3 commits into from
Apr 2, 2023
Merged
Changes from 1 commit
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
Next Next commit
Update test_cmd_line_script from Cpython v3.11.2
  • Loading branch information
Masorubka1 committed Apr 2, 2023
commit e169d97713be355c790a4dbb470e061babb59f08
35 changes: 25 additions & 10 deletions 35 Lib/test/test_cmd_line_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def _check_output(self, script_name, exit_code, data,
self.assertIn(printed_file.encode('utf-8'), data)
self.assertIn(printed_package.encode('utf-8'), data)
self.assertIn(printed_argv0.encode('utf-8'), data)
self.assertIn(printed_path0.encode('utf-8'), data)
# PYTHONSAFEPATH=1 changes the default sys.path[0]
if not sys.flags.safe_path:
self.assertIn(printed_path0.encode('utf-8'), data)
self.assertIn(printed_cwd.encode('utf-8'), data)

def _check_script(self, script_exec_args, expected_file,
Expand Down Expand Up @@ -492,7 +494,6 @@ def test_dash_m_errors(self):
br'ModuleNotFoundError'),
('builtins.x.y', br'Error while finding module specification.*'
br'ModuleNotFoundError.*No module named.*not a package'),
('os.path', br'loader.*cannot handle'),
('importlib', br'No module named.*'
br'is a package and cannot be directly executed'),
('importlib.nonexistent', br'No module named'),
Expand Down Expand Up @@ -577,8 +578,9 @@ def test_non_ascii(self):
# Mac OS X denies the creation of a file with an invalid UTF-8 name.
# Windows allows creating a name with an arbitrary bytes name, but
# Python cannot a undecodable bytes argument to a subprocess.
# WASI does not permit invalid UTF-8 names.
if (os_helper.TESTFN_UNDECODABLE
and sys.platform not in ('win32', 'darwin')):
and sys.platform not in ('win32', 'darwin', 'emscripten', 'wasi')):
name = os.fsdecode(os_helper.TESTFN_UNDECODABLE)
elif os_helper.TESTFN_NONASCII:
name = os_helper.TESTFN_NONASCII
Expand Down Expand Up @@ -770,14 +772,27 @@ def test_nonexisting_script(self):
self.assertIn(": can't open file ", err)
self.assertNotEqual(proc.returncode, 0)

# TODO: RUSTPYTHON
# def tearDownModule():
def test_main():
support.run_unittest(CmdLineTest)
@unittest.skipUnless(os.path.exists('/dev/fd/0'), 'requires /dev/fd platform')
@unittest.skipIf(sys.platform.startswith("freebsd") and
os.stat("/dev").st_dev == os.stat("/dev/fd").st_dev,
"Requires fdescfs mounted on /dev/fd on FreeBSD")
def test_script_as_dev_fd(self):
# GH-87235: On macOS passing a non-trivial script to /dev/fd/N can cause
# problems because all open /dev/fd/N file descriptors share the same
# offset.
script = 'print("12345678912345678912345")'
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()))
out, err = p.communicate()
self.assertEqual(out, b"12345678912345678912345\n")



def tearDownModule():
support.reap_children()


if __name__ == '__main__':
# TODO: RUSTPYTHON
# unittest.main()
test_main()
unittest.main()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.