Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_cmd_line_script.py @ 84007:dbfbdf2b5c19 3.3
Fix #17967: For ftp urls CWD to target instead of hopping to each directory
towards target. This fixes a bug where target is accessible, but parent
directories are restricted.
| author | Senthil Kumaran <senthil@uthcode.com> |
|---|---|
| date | Sat, 01 Jun 2013 08:27:06 -0700 |
| parents | 4d40c1ce8566 |
| children | 4f0034477ba9 5a2560cb4a8d |
| rev | line source |
|---|---|
| 60648 | 1 # tests command line execution of scripts |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
2 |
|
76566
57d558f1904d
Issue #14605: Make explicit the entries on sys.path_hooks that used to
Brett Cannon <brett@python.org>
parents:
76469
diff
changeset
|
3 import importlib |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
4 import importlib.machinery |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
5 import zipimport |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
6 import unittest |
|
65300
660afdaeb2d6
#9964: fix running test_cmd_line_script under -O and -OO.
Georg Brandl <georg@python.org>
parents:
65182
diff
changeset
|
7 import sys |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
8 import os |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
9 import os.path |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
10 import py_compile |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
11 |
|
77096
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
12 import textwrap |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
13 from test import support |
| 60648 | 14 from test.script_helper import ( |
|
65182
b1fb0539bf98
Better Python spawning primitives in test.script_helper, for
Antoine Pitrou <solipsis@pitrou.net>
parents:
64110
diff
changeset
|
15 make_pkg, make_script, make_zip_pkg, make_zip_script, |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
16 assert_python_ok, assert_python_failure, temp_dir, |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
17 spawn_python, kill_python) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
18 |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
19 verbose = support.verbose |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
20 |
|
76469
22f0044ea366
Close issue #14026 by better testing sys.argv handling in test_cmd_line_script (patch by Jason Yeo)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76416
diff
changeset
|
21 example_args = ['test1', 'test2', 'test3'] |
|
22f0044ea366
Close issue #14026 by better testing sys.argv handling in test_cmd_line_script (patch by Jason Yeo)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76416
diff
changeset
|
22 |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
23 test_source = """\ |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
24 # Script may be run with optimisation enabled, so don't rely on assert |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
25 # statements being executed |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
26 def assertEqual(lhs, rhs): |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
27 if lhs != rhs: |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
28 raise AssertionError('%r != %r' % (lhs, rhs)) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
29 def assertIdentical(lhs, rhs): |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
30 if lhs is not rhs: |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
31 raise AssertionError('%r is not %r' % (lhs, rhs)) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
32 # Check basic code execution |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
33 result = ['Top level assignment'] |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
34 def f(): |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
35 result.append('Lower level reference') |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
36 f() |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
37 assertEqual(result, ['Top level assignment', 'Lower level reference']) |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
38 # Check population of magic variables |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
39 assertEqual(__name__, '__main__') |
|
78110
ba264b26d8d9
Actually initialize __main__.__loader__ with loader instances, not the corresponding type objects
Nick Coghlan <ncoghlan@gmail.com>
parents:
78108
diff
changeset
|
40 from importlib.machinery import BuiltinImporter |
|
ba264b26d8d9
Actually initialize __main__.__loader__ with loader instances, not the corresponding type objects
Nick Coghlan <ncoghlan@gmail.com>
parents:
78108
diff
changeset
|
41 _loader = __loader__ if __loader__ is BuiltinImporter else type(__loader__) |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
42 print('__loader__==%a' % _loader) |
|
65424
0505eba62347
test_cmd_line_script: format paths with ascii() instead of repr()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65300
diff
changeset
|
43 print('__file__==%a' % __file__) |
| 60648 | 44 assertEqual(__cached__, None) |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
45 print('__package__==%r' % __package__) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
46 # Check the sys module |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
47 import sys |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
48 assertIdentical(globals(), sys.modules[__name__].__dict__) |
|
76469
22f0044ea366
Close issue #14026 by better testing sys.argv handling in test_cmd_line_script (patch by Jason Yeo)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76416
diff
changeset
|
49 from test import test_cmd_line_script |
|
22f0044ea366
Close issue #14026 by better testing sys.argv handling in test_cmd_line_script (patch by Jason Yeo)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76416
diff
changeset
|
50 example_args_list = test_cmd_line_script.example_args |
|
22f0044ea366
Close issue #14026 by better testing sys.argv handling in test_cmd_line_script (patch by Jason Yeo)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76416
diff
changeset
|
51 assertEqual(sys.argv[1:], example_args_list) |
|
65424
0505eba62347
test_cmd_line_script: format paths with ascii() instead of repr()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65300
diff
changeset
|
52 print('sys.argv[0]==%a' % sys.argv[0]) |
|
0505eba62347
test_cmd_line_script: format paths with ascii() instead of repr()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65300
diff
changeset
|
53 print('sys.path[0]==%a' % sys.path[0]) |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
54 # Check the working directory |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
55 import os |
|
65424
0505eba62347
test_cmd_line_script: format paths with ascii() instead of repr()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65300
diff
changeset
|
56 print('cwd==%a' % os.getcwd()) |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
57 """ |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
58 |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
59 def _make_test_script(script_dir, script_basename, source=test_source): |
|
76566
57d558f1904d
Issue #14605: Make explicit the entries on sys.path_hooks that used to
Brett Cannon <brett@python.org>
parents:
76469
diff
changeset
|
60 to_return = make_script(script_dir, script_basename, source) |
|
57d558f1904d
Issue #14605: Make explicit the entries on sys.path_hooks that used to
Brett Cannon <brett@python.org>
parents:
76469
diff
changeset
|
61 importlib.invalidate_caches() |
|
57d558f1904d
Issue #14605: Make explicit the entries on sys.path_hooks that used to
Brett Cannon <brett@python.org>
parents:
76469
diff
changeset
|
62 return to_return |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
63 |
|
50164
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
64 def _make_test_zip_pkg(zip_dir, zip_basename, pkg_name, script_basename, |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
65 source=test_source, depth=1): |
|
76566
57d558f1904d
Issue #14605: Make explicit the entries on sys.path_hooks that used to
Brett Cannon <brett@python.org>
parents:
76469
diff
changeset
|
66 to_return = make_zip_pkg(zip_dir, zip_basename, pkg_name, script_basename, |
|
57d558f1904d
Issue #14605: Make explicit the entries on sys.path_hooks that used to
Brett Cannon <brett@python.org>
parents:
76469
diff
changeset
|
67 source, depth) |
|
57d558f1904d
Issue #14605: Make explicit the entries on sys.path_hooks that used to
Brett Cannon <brett@python.org>
parents:
76469
diff
changeset
|
68 importlib.invalidate_caches() |
|
57d558f1904d
Issue #14605: Make explicit the entries on sys.path_hooks that used to
Brett Cannon <brett@python.org>
parents:
76469
diff
changeset
|
69 return to_return |
|
50164
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
70 |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
71 # There's no easy way to pass the script directory in to get |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
72 # -m to work (avoiding that is the whole point of making |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
73 # directories and zipfiles executable!) |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
74 # So we fake it for testing purposes with a custom launch script |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
75 launch_source = """\ |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
76 import sys, os.path, runpy |
|
50164
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
77 sys.path.insert(0, %s) |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
78 runpy._run_module_as_main(%r) |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
79 """ |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
80 |
|
50164
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
81 def _make_launch_script(script_dir, script_basename, module_name, path=None): |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
82 if path is None: |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
83 path = "os.path.dirname(__file__)" |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
84 else: |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
85 path = repr(path) |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
86 source = launch_source % (path, module_name) |
|
76566
57d558f1904d
Issue #14605: Make explicit the entries on sys.path_hooks that used to
Brett Cannon <brett@python.org>
parents:
76469
diff
changeset
|
87 to_return = make_script(script_dir, script_basename, source) |
|
57d558f1904d
Issue #14605: Make explicit the entries on sys.path_hooks that used to
Brett Cannon <brett@python.org>
parents:
76469
diff
changeset
|
88 importlib.invalidate_caches() |
|
57d558f1904d
Issue #14605: Make explicit the entries on sys.path_hooks that used to
Brett Cannon <brett@python.org>
parents:
76469
diff
changeset
|
89 return to_return |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
90 |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
91 class CmdLineTest(unittest.TestCase): |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
92 def _check_output(self, script_name, exit_code, data, |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
93 expected_file, expected_argv0, |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
94 expected_path0, expected_package, |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
95 expected_loader): |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
96 if verbose > 1: |
|
43912
4747ef9640ae
Merged revisions 59041-59055 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43908
diff
changeset
|
97 print("Output from test script %r:" % script_name) |
|
4747ef9640ae
Merged revisions 59041-59055 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43908
diff
changeset
|
98 print(data) |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
99 self.assertEqual(exit_code, 0) |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
100 printed_loader = '__loader__==%a' % expected_loader |
|
65424
0505eba62347
test_cmd_line_script: format paths with ascii() instead of repr()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65300
diff
changeset
|
101 printed_file = '__file__==%a' % expected_file |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
102 printed_package = '__package__==%r' % expected_package |
|
65424
0505eba62347
test_cmd_line_script: format paths with ascii() instead of repr()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65300
diff
changeset
|
103 printed_argv0 = 'sys.argv[0]==%a' % expected_argv0 |
|
0505eba62347
test_cmd_line_script: format paths with ascii() instead of repr()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65300
diff
changeset
|
104 printed_path0 = 'sys.path[0]==%a' % expected_path0 |
|
0505eba62347
test_cmd_line_script: format paths with ascii() instead of repr()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65300
diff
changeset
|
105 printed_cwd = 'cwd==%a' % os.getcwd() |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
106 if verbose > 1: |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
107 print('Expected output:') |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
108 print(printed_file) |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
109 print(printed_package) |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
110 print(printed_argv0) |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
111 print(printed_cwd) |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
112 self.assertIn(printed_loader.encode('utf-8'), data) |
|
58415
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
57291
diff
changeset
|
113 self.assertIn(printed_file.encode('utf-8'), data) |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
57291
diff
changeset
|
114 self.assertIn(printed_package.encode('utf-8'), data) |
|
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
57291
diff
changeset
|
115 self.assertIn(printed_argv0.encode('utf-8'), data) |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
116 self.assertIn(printed_path0.encode('utf-8'), data) |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
117 self.assertIn(printed_cwd.encode('utf-8'), data) |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
118 |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
119 def _check_script(self, script_name, expected_file, |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
120 expected_argv0, expected_path0, |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
121 expected_package, expected_loader, |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
122 *cmd_line_switches): |
|
65300
660afdaeb2d6
#9964: fix running test_cmd_line_script under -O and -OO.
Georg Brandl <georg@python.org>
parents:
65182
diff
changeset
|
123 if not __debug__: |
|
660afdaeb2d6
#9964: fix running test_cmd_line_script under -O and -OO.
Georg Brandl <georg@python.org>
parents:
65182
diff
changeset
|
124 cmd_line_switches += ('-' + 'O' * sys.flags.optimize,) |
|
76469
22f0044ea366
Close issue #14026 by better testing sys.argv handling in test_cmd_line_script (patch by Jason Yeo)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76416
diff
changeset
|
125 run_args = cmd_line_switches + (script_name,) + tuple(example_args) |
|
65182
b1fb0539bf98
Better Python spawning primitives in test.script_helper, for
Antoine Pitrou <solipsis@pitrou.net>
parents:
64110
diff
changeset
|
126 rc, out, err = assert_python_ok(*run_args) |
|
b1fb0539bf98
Better Python spawning primitives in test.script_helper, for
Antoine Pitrou <solipsis@pitrou.net>
parents:
64110
diff
changeset
|
127 self._check_output(script_name, rc, out + err, expected_file, |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
128 expected_argv0, expected_path0, |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
129 expected_package, expected_loader) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
130 |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
131 def _check_import_error(self, script_name, expected_msg, |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
132 *cmd_line_switches): |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
133 run_args = cmd_line_switches + (script_name,) |
|
65182
b1fb0539bf98
Better Python spawning primitives in test.script_helper, for
Antoine Pitrou <solipsis@pitrou.net>
parents:
64110
diff
changeset
|
134 rc, out, err = assert_python_failure(*run_args) |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
135 if verbose > 1: |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
136 print('Output from test script %r:' % script_name) |
|
65182
b1fb0539bf98
Better Python spawning primitives in test.script_helper, for
Antoine Pitrou <solipsis@pitrou.net>
parents:
64110
diff
changeset
|
137 print(err) |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
138 print('Expected output: %r' % expected_msg) |
|
65182
b1fb0539bf98
Better Python spawning primitives in test.script_helper, for
Antoine Pitrou <solipsis@pitrou.net>
parents:
64110
diff
changeset
|
139 self.assertIn(expected_msg.encode('utf-8'), err) |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
140 |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
141 def test_dash_c_loader(self): |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
142 rc, out, err = assert_python_ok("-c", "print(__loader__)") |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
143 expected = repr(importlib.machinery.BuiltinImporter).encode("utf-8") |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
144 self.assertIn(expected, out) |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
145 |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
146 def test_stdin_loader(self): |
|
78108
777bd189f0f1
Note why we can't write an automated test for the code path that brings up the REPL for a bare 'python' call
Nick Coghlan <ncoghlan@gmail.com>
parents:
78107
diff
changeset
|
147 # Unfortunately, there's no way to automatically test the fully |
|
777bd189f0f1
Note why we can't write an automated test for the code path that brings up the REPL for a bare 'python' call
Nick Coghlan <ncoghlan@gmail.com>
parents:
78107
diff
changeset
|
148 # interactive REPL, since that code path only gets executed when |
|
78115
1a08ceae5ef1
Fix typo in a comment (noticed by Terry Reedy)
Nick Coghlan <ncoghlan@gmail.com>
parents:
78110
diff
changeset
|
149 # stdin is an interactive tty. |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
150 p = spawn_python() |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
151 try: |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
152 p.stdin.write(b"print(__loader__)\n") |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
153 p.stdin.flush() |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
154 finally: |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
155 out = kill_python(p) |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
156 expected = repr(importlib.machinery.BuiltinImporter).encode("utf-8") |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
157 self.assertIn(expected, out) |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
158 |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
159 def test_basic_script(self): |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
160 with temp_dir() as script_dir: |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
161 script_name = _make_test_script(script_dir, 'script') |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
162 self._check_script(script_name, script_name, script_name, |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
163 script_dir, None, |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
164 importlib.machinery.SourceFileLoader) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
165 |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
166 def test_script_compiled(self): |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
167 with temp_dir() as script_dir: |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
168 script_name = _make_test_script(script_dir, 'script') |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
169 py_compile.compile(script_name, doraise=True) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
170 os.remove(script_name) |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
171 pyc_file = support.make_legacy_pyc(script_name) |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
172 self._check_script(pyc_file, pyc_file, |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
173 pyc_file, script_dir, None, |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
174 importlib.machinery.SourcelessFileLoader) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
175 |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
176 def test_directory(self): |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
177 with temp_dir() as script_dir: |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
178 script_name = _make_test_script(script_dir, '__main__') |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
179 self._check_script(script_dir, script_name, script_dir, |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
180 script_dir, '', |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
181 importlib.machinery.SourceFileLoader) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
182 |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
183 def test_directory_compiled(self): |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
184 with temp_dir() as script_dir: |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
185 script_name = _make_test_script(script_dir, '__main__') |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
186 py_compile.compile(script_name, doraise=True) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
187 os.remove(script_name) |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
188 pyc_file = support.make_legacy_pyc(script_name) |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
189 self._check_script(script_dir, pyc_file, script_dir, |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
190 script_dir, '', |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
191 importlib.machinery.SourcelessFileLoader) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
192 |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
193 def test_directory_error(self): |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
194 with temp_dir() as script_dir: |
|
57291
fd417cd64341
Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
55593
diff
changeset
|
195 msg = "can't find '__main__' module in %r" % script_dir |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
196 self._check_import_error(script_dir, msg) |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
197 |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
198 def test_zipfile(self): |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
199 with temp_dir() as script_dir: |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
200 script_name = _make_test_script(script_dir, '__main__') |
|
57291
fd417cd64341
Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
55593
diff
changeset
|
201 zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name) |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
202 self._check_script(zip_name, run_name, zip_name, zip_name, '', |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
203 zipimport.zipimporter) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
204 |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
205 def test_zipfile_compiled(self): |
|
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
206 with temp_dir() as script_dir: |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
207 script_name = _make_test_script(script_dir, '__main__') |
| 60648 | 208 compiled_name = py_compile.compile(script_name, doraise=True) |
|
57291
fd417cd64341
Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
55593
diff
changeset
|
209 zip_name, run_name = make_zip_script(script_dir, 'test_zip', compiled_name) |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
210 self._check_script(zip_name, run_name, zip_name, zip_name, '', |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
211 zipimport.zipimporter) |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
212 |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
213 def test_zipfile_error(self): |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
214 with temp_dir() as script_dir: |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
215 script_name = _make_test_script(script_dir, 'not_main') |
|
57291
fd417cd64341
Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
55593
diff
changeset
|
216 zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name) |
|
fd417cd64341
Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
55593
diff
changeset
|
217 msg = "can't find '__main__' module in %r" % zip_name |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
218 self._check_import_error(zip_name, msg) |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
219 |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
220 def test_module_in_package(self): |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
221 with temp_dir() as script_dir: |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
222 pkg_dir = os.path.join(script_dir, 'test_pkg') |
|
57291
fd417cd64341
Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
55593
diff
changeset
|
223 make_pkg(pkg_dir) |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
224 script_name = _make_test_script(pkg_dir, 'script') |
|
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
225 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script') |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
226 self._check_script(launch_name, script_name, script_name, |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
227 script_dir, 'test_pkg', |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
228 importlib.machinery.SourceFileLoader) |
|
50164
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
229 |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
230 def test_module_in_package_in_zipfile(self): |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
231 with temp_dir() as script_dir: |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
232 zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script') |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
233 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script', zip_name) |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
234 self._check_script(launch_name, run_name, run_name, |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
235 zip_name, 'test_pkg', zipimport.zipimporter) |
|
50164
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
236 |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
237 def test_module_in_subpackage_in_zipfile(self): |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
238 with temp_dir() as script_dir: |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
239 zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script', depth=2) |
|
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
47201
diff
changeset
|
240 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.test_pkg.script', zip_name) |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
241 self._check_script(launch_name, run_name, run_name, |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
242 zip_name, 'test_pkg.test_pkg', |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
243 zipimport.zipimporter) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
244 |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
245 def test_package(self): |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
246 with temp_dir() as script_dir: |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
247 pkg_dir = os.path.join(script_dir, 'test_pkg') |
|
57291
fd417cd64341
Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
55593
diff
changeset
|
248 make_pkg(pkg_dir) |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
249 script_name = _make_test_script(pkg_dir, '__main__') |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
250 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg') |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
251 self._check_script(launch_name, script_name, |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
252 script_name, script_dir, 'test_pkg', |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
253 importlib.machinery.SourceFileLoader) |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
254 |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
255 def test_package_compiled(self): |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
256 with temp_dir() as script_dir: |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
257 pkg_dir = os.path.join(script_dir, 'test_pkg') |
|
57291
fd417cd64341
Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
55593
diff
changeset
|
258 make_pkg(pkg_dir) |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
259 script_name = _make_test_script(pkg_dir, '__main__') |
| 60648 | 260 compiled_name = py_compile.compile(script_name, doraise=True) |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
261 os.remove(script_name) |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
262 pyc_file = support.make_legacy_pyc(script_name) |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
263 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg') |
| 60648 | 264 self._check_script(launch_name, pyc_file, |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
265 pyc_file, script_dir, 'test_pkg', |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
266 importlib.machinery.SourcelessFileLoader) |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
267 |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
268 def test_package_error(self): |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
269 with temp_dir() as script_dir: |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
270 pkg_dir = os.path.join(script_dir, 'test_pkg') |
|
57291
fd417cd64341
Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
55593
diff
changeset
|
271 make_pkg(pkg_dir) |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
272 msg = ("'test_pkg' is a package and cannot " |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
273 "be directly executed") |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
274 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg') |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
275 self._check_import_error(launch_name, msg) |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
276 |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
277 def test_package_recursion(self): |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
278 with temp_dir() as script_dir: |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
279 pkg_dir = os.path.join(script_dir, 'test_pkg') |
|
57291
fd417cd64341
Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
55593
diff
changeset
|
280 make_pkg(pkg_dir) |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
281 main_dir = os.path.join(pkg_dir, '__main__') |
|
57291
fd417cd64341
Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
55593
diff
changeset
|
282 make_pkg(main_dir) |
|
51452
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
283 msg = ("Cannot use package as __main__ module; " |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
284 "'test_pkg' is a package and cannot " |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
285 "be directly executed") |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
286 launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg') |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
287 self._check_import_error(launch_name, msg) |
|
2d354f4d77bc
Merged revisions 69419-69420 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
50164
diff
changeset
|
288 |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
289 def test_issue8202(self): |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
290 # Make sure package __init__ modules see "-m" in sys.argv0 while |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
291 # searching for the module to execute |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
292 with temp_dir() as script_dir: |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
293 with support.temp_cwd(path=script_dir): |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
294 pkg_dir = os.path.join(script_dir, 'test_pkg') |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
295 make_pkg(pkg_dir, "import sys; print('init_argv0==%r' % sys.argv[0])") |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
296 script_name = _make_test_script(pkg_dir, 'script') |
|
76469
22f0044ea366
Close issue #14026 by better testing sys.argv handling in test_cmd_line_script (patch by Jason Yeo)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76416
diff
changeset
|
297 rc, out, err = assert_python_ok('-m', 'test_pkg.script', *example_args) |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
298 if verbose > 1: |
|
76416
c4c67c2d8ffc
Close #14032: fix incorrect variable reference in test_cmd_line_script
Nick Coghlan <ncoghlan@gmail.com>
parents:
68257
diff
changeset
|
299 print(out) |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
300 expected = "init_argv0==%r" % '-m' |
|
65182
b1fb0539bf98
Better Python spawning primitives in test.script_helper, for
Antoine Pitrou <solipsis@pitrou.net>
parents:
64110
diff
changeset
|
301 self.assertIn(expected.encode('utf-8'), out) |
|
b1fb0539bf98
Better Python spawning primitives in test.script_helper, for
Antoine Pitrou <solipsis@pitrou.net>
parents:
64110
diff
changeset
|
302 self._check_output(script_name, rc, out, |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
303 script_name, script_name, '', 'test_pkg', |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
304 importlib.machinery.SourceFileLoader) |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
305 |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
306 def test_issue8202_dash_c_file_ignored(self): |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
307 # Make sure a "-c" file in the current directory |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
308 # does not alter the value of sys.path[0] |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
309 with temp_dir() as script_dir: |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
310 with support.temp_cwd(path=script_dir): |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
311 with open("-c", "w") as f: |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
312 f.write("data") |
|
65182
b1fb0539bf98
Better Python spawning primitives in test.script_helper, for
Antoine Pitrou <solipsis@pitrou.net>
parents:
64110
diff
changeset
|
313 rc, out, err = assert_python_ok('-c', |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
314 'import sys; print("sys.path[0]==%r" % sys.path[0])') |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
315 if verbose > 1: |
|
65182
b1fb0539bf98
Better Python spawning primitives in test.script_helper, for
Antoine Pitrou <solipsis@pitrou.net>
parents:
64110
diff
changeset
|
316 print(out) |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
317 expected = "sys.path[0]==%r" % '' |
|
65182
b1fb0539bf98
Better Python spawning primitives in test.script_helper, for
Antoine Pitrou <solipsis@pitrou.net>
parents:
64110
diff
changeset
|
318 self.assertIn(expected.encode('utf-8'), out) |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
319 |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
320 def test_issue8202_dash_m_file_ignored(self): |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
321 # Make sure a "-m" file in the current directory |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
322 # does not alter the value of sys.path[0] |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
323 with temp_dir() as script_dir: |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
324 script_name = _make_test_script(script_dir, 'other') |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
325 with support.temp_cwd(path=script_dir): |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
326 with open("-m", "w") as f: |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
327 f.write("data") |
|
76469
22f0044ea366
Close issue #14026 by better testing sys.argv handling in test_cmd_line_script (patch by Jason Yeo)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76416
diff
changeset
|
328 rc, out, err = assert_python_ok('-m', 'other', *example_args) |
|
65182
b1fb0539bf98
Better Python spawning primitives in test.script_helper, for
Antoine Pitrou <solipsis@pitrou.net>
parents:
64110
diff
changeset
|
329 self._check_output(script_name, rc, out, |
|
78107
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
330 script_name, script_name, '', '', |
|
3987667bf98f
Take the first step in resolving the messy pkgutil vs importlib edge cases by basing pkgutil explicitly on importlib, deprecating its internal import emulation and setting __main__.__loader__ correctly so that runpy still works (Affects #15343, #15314, #15357)
Nick Coghlan <ncoghlan@gmail.com>
parents:
77947
diff
changeset
|
331 importlib.machinery.SourceFileLoader) |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
332 |
|
77946
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
333 def test_dash_m_error_code_is_one(self): |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
334 # If a module is invoked with the -m command line flag |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
335 # and results in an error that the return code to the |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
336 # shell is '1' |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
337 with temp_dir() as script_dir: |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
338 with support.temp_cwd(path=script_dir): |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
339 pkg_dir = os.path.join(script_dir, 'test_pkg') |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
340 make_pkg(pkg_dir) |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
341 script_name = _make_test_script(pkg_dir, 'other', |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
342 "if __name__ == '__main__': raise ValueError") |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
343 rc, out, err = assert_python_failure('-m', 'test_pkg.other', *example_args) |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
344 if verbose > 1: |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
345 print(out) |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
346 self.assertEqual(rc, 1) |
|
fcbd3bda7c0f
Fix issue # 15033 - Return the proper exitcode for failure when modules are invoked using -m switch. Patch contributed by Jeff Knupp
Senthil Kumaran <senthil@uthcode.com>
parents:
76469
diff
changeset
|
347 |
|
77096
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
348 def test_pep_409_verbiage(self): |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
349 # Make sure PEP 409 syntax properly suppresses |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
350 # the context of an exception |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
351 script = textwrap.dedent("""\ |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
352 try: |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
353 raise ValueError |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
354 except: |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
355 raise NameError from None |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
356 """) |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
357 with temp_dir() as script_dir: |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
358 script_name = _make_test_script(script_dir, 'script', script) |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
359 exitcode, stdout, stderr = assert_python_failure(script_name) |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
360 text = stderr.decode('ascii').split('\n') |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
361 self.assertEqual(len(text), 4) |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
362 self.assertTrue(text[0].startswith('Traceback')) |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
363 self.assertTrue(text[1].startswith(' File ')) |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
364 self.assertTrue(text[3].startswith('NameError')) |
|
02f13577b6fe
Close #14136 by cleaning up the PEP 409 command line test (patch by Ethan Furman)
Nick Coghlan <ncoghlan@gmail.com>
parents:
76566
diff
changeset
|
365 |
|
81260
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
366 def test_non_ascii(self): |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
367 # Mac OS X denies the creation of a file with an invalid UTF-8 name. |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
368 # Windows allows to create a name with an arbitrary bytes name, but |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
369 # Python cannot a undecodable bytes argument to a subprocess. |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
370 if (support.TESTFN_UNDECODABLE |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
371 and sys.platform not in ('win32', 'darwin')): |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
372 name = os.fsdecode(support.TESTFN_UNDECODABLE) |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
373 elif support.TESTFN_NONASCII: |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
374 name = support.TESTFN_NONASCII |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
375 else: |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
376 self.skipTest("need support.TESTFN_NONASCII") |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
377 |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
378 # Issue #16218 |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
379 source = 'print(ascii(__file__))\n' |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
380 script_name = _make_test_script(os.curdir, name, source) |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
381 self.addCleanup(support.unlink, script_name) |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
382 rc, stdout, stderr = assert_python_ok(script_name) |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
383 self.assertEqual( |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
384 ascii(script_name), |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
385 stdout.rstrip().decode('ascii'), |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
386 'stdout=%r stderr=%r' % (stdout, stderr)) |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
387 self.assertEqual(0, rc) |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
388 |
|
41658a4fb3cc
Issue #16218, #16414, #16444: Backport FS_NONASCII, TESTFN_UNDECODABLE,
Victor Stinner <victor.stinner@gmail.com>
parents:
77946
diff
changeset
|
389 |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
390 def test_main(): |
|
64110
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
391 support.run_unittest(CmdLineTest) |
|
212a16f906a6
Issue #8202: Set sys.argv[0] to -m rather than -c while searching for the module to execute. Also updates all the cmd_line_script tests to validate the setting of sys.path[0] and the current working directory
Nick Coghlan <ncoghlan@gmail.com>
parents:
60648
diff
changeset
|
392 support.reap_children() |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
393 |
|
44129
b637349336fd
Merged revisions 59275-59303 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43912
diff
changeset
|
394 if __name__ == '__main__': |
|
43897
41f7c13ef161
Merged revisions 59005-59040 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff
changeset
|
395 test_main() |
