diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-08 18:05:42 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-08 18:05:42 (GMT) |
commit | f51d8d3a2ede7ff3330e2a868feb4ecdda0b92c0 (patch) | |
tree | 8a5a261dc53a7b2a20c5bc12c48c25f77122eea9 /Lib/test/test_cmd_line_script.py | |
parent | 0ee4c9f274960bb717492b0827f6d22af0b1e60b (diff) | |
download | cpython-f51d8d3a2ede7ff3330e2a868feb4ecdda0b92c0.zip cpython-f51d8d3a2ede7ff3330e2a868feb4ecdda0b92c0.tar.gz cpython-f51d8d3a2ede7ff3330e2a868feb4ecdda0b92c0.tar.bz2 |
Better Python spawning primitives in test.script_helper, for
easier writing of unit tests and better error reporting.
Diffstat (limited to 'Lib/test/test_cmd_line_script.py')
-rw-r--r-- | Lib/test/test_cmd_line_script.py | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py index d19316b..75e9f8d 100644 --- a/Lib/test/test_cmd_line_script.py +++ b/Lib/test/test_cmd_line_script.py @@ -7,8 +7,8 @@ import py_compile from test import support from test.script_helper import ( - make_pkg, make_script, make_zip_pkg, make_zip_script, run_python, - temp_dir) + make_pkg, make_script, make_zip_pkg, make_zip_script, + assert_python_ok, assert_python_failure, temp_dir) verbose = support.verbose @@ -98,19 +98,19 @@ class CmdLineTest(unittest.TestCase): expected_package, *cmd_line_switches): run_args = cmd_line_switches + (script_name,) - exit_code, data = run_python(*run_args) - self._check_output(script_name, exit_code, data, expected_file, + rc, out, err = assert_python_ok(*run_args) + self._check_output(script_name, rc, out + err, expected_file, expected_argv0, expected_path0, expected_package) def _check_import_error(self, script_name, expected_msg, *cmd_line_switches): run_args = cmd_line_switches + (script_name,) - exit_code, data = run_python(*run_args) + rc, out, err = assert_python_failure(*run_args) if verbose > 1: print('Output from test script %r:' % script_name) - print(data) + print(err) print('Expected output: %r' % expected_msg) - self.assertIn(expected_msg.encode('utf-8'), data) + self.assertIn(expected_msg.encode('utf-8'), err) def test_basic_script(self): with temp_dir() as script_dir: @@ -237,13 +237,12 @@ class CmdLineTest(unittest.TestCase): pkg_dir = os.path.join(script_dir, 'test_pkg') make_pkg(pkg_dir, "import sys; print('init_argv0==%r' % sys.argv[0])") script_name = _make_test_script(pkg_dir, 'script') - exit_code, data = run_python('-m', 'test_pkg.script') + rc, out, err = assert_python_ok('-m', 'test_pkg.script') if verbose > 1: print(data) - self.assertEqual(exit_code, 0) expected = "init_argv0==%r" % '-m' - self.assertIn(expected.encode('utf-8'), data) - self._check_output(script_name, exit_code, data, + self.assertIn(expected.encode('utf-8'), out) + self._check_output(script_name, rc, out, script_name, script_name, '', 'test_pkg') def test_issue8202_dash_c_file_ignored(self): @@ -253,13 +252,12 @@ class CmdLineTest(unittest.TestCase): with support.temp_cwd(path=script_dir): with open("-c", "w") as f: f.write("data") - exit_code, data = run_python('-c', + rc, out, err = assert_python_ok('-c', 'import sys; print("sys.path[0]==%r" % sys.path[0])') if verbose > 1: - print(data) - self.assertEqual(exit_code, 0) + print(out) expected = "sys.path[0]==%r" % '' - self.assertIn(expected.encode('utf-8'), data) + self.assertIn(expected.encode('utf-8'), out) def test_issue8202_dash_m_file_ignored(self): # Make sure a "-m" file in the current directory @@ -269,8 +267,8 @@ class CmdLineTest(unittest.TestCase): with support.temp_cwd(path=script_dir): with open("-m", "w") as f: f.write("data") - exit_code, data = run_python('-m', 'other') - self._check_output(script_name, exit_code, data, + rc, out, err = assert_python_ok('-m', 'other') + self._check_output(script_name, rc, out, script_name, script_name, '', '') def test_main(): |