Commits

Armin Rigo committed b90d917

Issue #1337: Give a __file__ to PYTHONSTARTUP.

Comments (0)

Files changed (2)

pypy/translator/goal/app_main.py

                                                         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:

pypy/translator/goal/test2/test_app_main.py

         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: