Armin Rigo avatar 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:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.