Skip to content

Commit 82b39bf

Browse files
author
lrraymond13
committed
Fixed bpython#284
1 parent 89b1863 commit 82b39bf

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

bpython/args.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def parse(args, extras=None, ignore_stdin=False):
9090

9191
if not ignore_stdin and not (sys.stdin.isatty() and sys.stdout.isatty()):
9292
interpreter = code.InteractiveInterpreter()
93+
print "Entering st.read %s" % sys.stdout.isatty()
9394
interpreter.runsource(sys.stdin.read())
9495
raise SystemExit
9596

@@ -107,5 +108,6 @@ def exec_code(interpreter, args):
107108
source = sourcefile.read()
108109
old_argv, sys.argv = sys.argv, args
109110
sys.path.insert(0, os.path.abspath(os.path.dirname(args[0])))
111+
interpreter.locals['__file__'] = args[0]
110112
interpreter.runsource(source, args[0], 'exec')
111113
sys.argv = old_argv

bpython/test/test_args.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
import subprocess
3+
import tempfile
4+
import sys
5+
6+
7+
8+
9+
class TestExecArgs(unittest.TestCase):
10+
def test_exec_dunder_file(self):
11+
with tempfile.NamedTemporaryFile(delete=False) as f:
12+
f.write(
13+
"import sys; print 'hello'; sys.stderr.write(__file__); sys.stderr.flush();")
14+
f.flush()
15+
print open(f.name).read()
16+
p = subprocess.Popen(['bpython-curtsies', f.name], stderr= subprocess.PIPE)
17+
18+
self.assertEquals(p.stderr.read().strip(), f.name)
19+
20+

0 commit comments

Comments
 (0)