summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cmd_line_script.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2013-12-15 10:33:02 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2013-12-15 10:33:02 (GMT)
commit720c7e28cb892204debd1b3820e460a9d654f178 (patch)
treeba0c12cc266baa1c1d1c274134f83d6843d605fd /Lib/test/test_cmd_line_script.py
parent8aa36a3db97cfed3108f32fcb66c9c84e5c4b00d (diff)
downloadcpython-720c7e28cb892204debd1b3820e460a9d654f178.zip
cpython-720c7e28cb892204debd1b3820e460a9d654f178.tar.gz
cpython-720c7e28cb892204debd1b3820e460a9d654f178.tar.bz2
Issue #19700: set __spec__ appropriately in runpy
Note that __spec__.name is not currently guaranteed to be in sys.modules when the code is running, only __name__ is. The "running module is in sys.modules" invariant will be expanded to also cover __spec__.name in a subsequent patch.
Diffstat (limited to 'Lib/test/test_cmd_line_script.py')
-rw-r--r--Lib/test/test_cmd_line_script.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
index f804d86..03c071e 100644
--- a/Lib/test/test_cmd_line_script.py
+++ b/Lib/test/test_cmd_line_script.py
@@ -41,11 +41,28 @@ from importlib.machinery import BuiltinImporter
_loader = __loader__ if __loader__ is BuiltinImporter else type(__loader__)
print('__loader__==%a' % _loader)
print('__file__==%a' % __file__)
-assertEqual(__cached__, None)
+print('__cached__==%a' % __cached__)
print('__package__==%r' % __package__)
+# Check PEP 451 details
+import os.path
+if __package__ is not None:
+ print('__main__ was located through the import system')
+ assertIdentical(__spec__.loader, __loader__)
+ expected_spec_name = os.path.splitext(os.path.basename(__file__))[0]
+ if __package__:
+ expected_spec_name = __package__ + "." + expected_spec_name
+ assertEqual(__spec__.name, expected_spec_name)
+ assertEqual(__spec__.parent, __package__)
+ assertIdentical(__spec__.submodule_search_locations, None)
+ assertEqual(__spec__.origin, __file__)
+ if __spec__.cached is not None:
+ assertEqual(__spec__.cached, __cached__)
# Check the sys module
import sys
assertIdentical(globals(), sys.modules[__name__].__dict__)
+if __spec__ is not None:
+ # XXX: We're not currently making __main__ available under its real name
+ pass # assertIdentical(globals(), sys.modules[__spec__.name].__dict__)
from test import test_cmd_line_script
example_args_list = test_cmd_line_script.example_args
assertEqual(sys.argv[1:], example_args_list)