Author: Armin Rigo <[email protected]>
Branch:
Changeset: r59868:b90d91783d29
Date: 2013-01-08 00:09 +0100
http://bitbucket.org/pypy/pypy/changeset/b90d91783d29/
Log: Issue #1337: Give a __file__ to PYTHONSTARTUP.
diff --git a/pypy/translator/goal/app_main.py b/pypy/translator/goal/app_main.py
--- a/pypy/translator/goal/app_main.py
+++ b/pypy/translator/goal/app_main.py
@@ -584,7 +584,12 @@
python_startup,
'exec')
exec co_python_startup in mainmodule.__dict__
+ mainmodule.__file__ = python_startup
run_toplevel(run_it)
+ try:
+ del mainmodule.__file__
+ except (AttributeError, TypeError):
+ pass
# Then we need a prompt.
inspect = True
else:
diff --git a/pypy/translator/goal/test2/test_app_main.py
b/pypy/translator/goal/test2/test_app_main.py
--- a/pypy/translator/goal/test2/test_app_main.py
+++ b/pypy/translator/goal/test2/test_app_main.py
@@ -376,6 +376,30 @@
child.expect('Traceback')
child.expect('NameError')
+ def test_pythonstartup_file1(self, monkeypatch):
+ monkeypatch.setenv('PYTHONPATH', None)
+ monkeypatch.setenv('PYTHONSTARTUP', demo_script)
+ child = self.spawn([])
+ child.expect('File: [^\n]+\.py')
+ child.expect('goodbye')
+ child.expect('>>> ')
+ child.sendline('[myvalue]')
+ child.expect(re.escape('[42]'))
+ child.expect('>>> ')
+ child.sendline('__file__')
+ child.expect('Traceback')
+ child.expect('NameError')
+
+ def test_pythonstartup_file2(self, monkeypatch):
+ monkeypatch.setenv('PYTHONPATH', None)
+ monkeypatch.setenv('PYTHONSTARTUP', crashing_demo_script)
+ child = self.spawn([])
+ child.expect('Traceback')
+ child.expect('>>> ')
+ child.sendline('__file__')
+ child.expect('Traceback')
+ child.expect('NameError')
+
def test_ignore_python_startup(self):
old = os.environ.get('PYTHONSTARTUP', '')
try:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit