def test_py_script_file_compiler_directive(self): """Test `__future__` compiler directives with `ipython -i file.py`""" src = "from __future__ import division\n" self.mktmp(src) out, err = tt.ipexec(self.fname, options=['-i'], commands=['type(1/2)', 'exit()']) self.assertIn('float', out)
def test_py_script_file_attribute_interactively(self): """Test that `__file__` is not set after `ipython -i file.py`""" src = "True\n" self.mktmp(src) out, err = tt.ipexec(self.fname, options=['-i'], commands=['"__file__" in globals()', 'exit()']) self.assertIn("False", out)
def test_py_script_file_attribute_interactively(self): """Test that `__file__` is not set after `ipython -i file.py`""" src = "True\n" self.mktmp(src) out, err = tt.ipexec( self.fname, options=["-i"], commands=['"__file__" in globals()', "print(123)", "exit()"], ) assert "False" in out, f"Subprocess stderr:\n{err}\n-----"
def test_py_script_file_attribute_interactively(self): """Test that `__file__` is not set after `ipython -i file.py`""" src = "True\n" self.mktmp(src) out, err = tt.ipexec(self.fname, options=['-i'], commands=['"__file__" in globals()', 'print(123)', 'exit()']) if 'False' not in out: print("Subprocess stderr:") print(err) print('-----') raise AssertionError("'False' not found in %r" % out)
def test_script_tb(): """Test traceback offset in `ipython script.py`""" with TemporaryDirectory() as td: path = pjoin(td, 'foo.py') with open(path, 'w') as f: f.write('\n'.join([ "def foo():", " return bar()", "def bar():", " raise RuntimeError('hello!')", "foo()", ])) out, err = tt.ipexec(path) nt.assert_not_in("execfile", out) nt.assert_in("RuntimeError", out) nt.assert_equal(out.count("---->"), 3)
def test_script_tb(): """Test traceback offset in `ipython script.py`""" with TemporaryDirectory() as td: path = pjoin(td, "foo.py") with open(path, "w", encoding="utf-8") as f: f.write("\n".join([ "def foo():", " return bar()", "def bar():", " raise RuntimeError('hello!')", "foo()", ])) out, err = tt.ipexec(path) assert "execfile" not in out assert "RuntimeError" in out assert out.count("---->") == 3