def test_ipy_script_file_attribute(self): """Test that `__file__` is set when running `ipython file.ipy`""" src = "print(__file__)\n" self.mktmp(src, ext='.ipy') err = None tt.ipexec_validate(self.fname, self.fname, err)
def test_ipy_script_file_attribute(self): """Test that `__file__` is set when running `ipython file.ipy`""" src = "print(__file__)\n" self.mktmp(src, ext=".ipy") err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None tt.ipexec_validate(self.fname, self.fname, err)
def test_ipy_script_file_attribute(self): """Test that `__file__` is set when running `ipython file.ipy`""" src = "print(__file__)\n" self.mktmp(src, ext='.ipy') err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None tt.ipexec_validate(self.fname, self.fname, err)
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) err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None tt.ipexec_validate(self.fname, 'float', err, options=['-i'], commands=['type(1/2)', 'exit()'])
def test_main_path(self): """Test with only stdout results. """ self.mktmp("print('A')\n" "print('B')\n" ) out = "A\nB" tt.ipexec_validate(self.fname, out)
def test_main_path2(self): """Test with only stdout results, expecting windows line endings. """ self.mktmp("print('A')\n" "print('B')\n" ) out = "A\r\nB" tt.ipexec_validate(self.fname, 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) err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None tt.ipexec_validate(self.fname, 'False', err, options=['-i'], commands=['"__file__" in globals()', 'exit()'])
def test_obj_del(self): """Test that object's __del__ methods are called on exit.""" # This test is known to fail on win32. # See ticket https://bugs.launchpad.net/bugs/366334 src = "class A(object):\n" " def __del__(self):\n" " print 'object A deleted'\n" "a = A()\n" self.mktmp(src) tt.ipexec_validate(self.fname, "object A deleted")
def test_obj_del(self): """Test that object's __del__ methods are called on exit.""" src = ("class A(object):\n" " def __del__(self):\n" " print('object A deleted')\n" "a = A()\n") self.mktmp(src) err = None tt.ipexec_validate(self.fname, 'object A deleted', err)
def test_extraneous_loads(self): """Test we're not loading modules on startup that we shouldn't. """ self.mktmp("import sys\n" "print('numpy' in sys.modules)\n" "print('IPython.parallel' in sys.modules)\n" "print('IPython.kernel.zmq' in sys.modules)\n") out = "False\nFalse\nFalse\n" tt.ipexec_validate(self.fname, out)
def test_obj_del(self): """Test that object's __del__ methods are called on exit.""" src = ("class A(object):\n" " def __del__(self):\n" " print 'object A deleted'\n" "a = A()\n") self.mktmp(src) tt.ipexec_validate(self.fname, 'object A deleted')
def test_ipy_script_file_attribute(self): """Test that `__file__` is set when running `ipython file.ipy`""" src = "print(__file__)\n" self.mktmp(src, ext='.ipy') if dec.module_not_available('sqlite3'): err = 'WARNING: IPython History requires SQLite, your history will not be saved\n' else: err = None tt.ipexec_validate(self.fname, self.fname, err)
def test_obj_del(self): """Test that object's __del__ methods are called on exit.""" if sys.platform == "win32": try: import win32api except ImportError: raise SkipTest("Test requires pywin32") src = "class A(object):\n" " def __del__(self):\n" " print 'object A deleted'\n" "a = A()\n" self.mktmp(src) tt.ipexec_validate(self.fname, "object A deleted")
def test_extraneous_loads(self): """Test we're not loading modules on startup that we shouldn't. """ self.mktmp("import sys\n" "print('numpy' in sys.modules)\n" "print('IPython.parallel' in sys.modules)\n" "print('IPython.kernel.zmq' in sys.modules)\n" ) out = "False\nFalse\nFalse\n" tt.ipexec_validate(self.fname, out)
def test_exception_path2(self): """Test exception path in exception_validate, expecting windows line endings. """ self.mktmp("import sys\n" "print('A')\n" "print('B')\n" "print('C', file=sys.stderr)\n" "print('D', file=sys.stderr)\n") out = "A\r\nB" tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\r\nD")
def test_obj_del(self): """Test that object's __del__ methods are called on exit.""" # This test is known to fail on win32. # See ticket https://bugs.launchpad.net/bugs/366334 src = ("class A(object):\n" " def __del__(self):\n" " print 'object A deleted'\n" "a = A()\n") self.mktmp(src) tt.ipexec_validate(self.fname, 'object A deleted')
def test_exception_path(self): """Test exception path in exception_validate. """ self.mktmp("from __future__ import print_function\n" "import sys\n" "print('A')\n" "print('B')\n" "print('C', file=sys.stderr)\n" "print('D', file=sys.stderr)\n") out = "A\nB" tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\nD")
def test_tclass(self): mydir = os.path.dirname(__file__) tc = os.path.join(mydir, "tclass") src = ("%%run '%s' C-first\n" "%%run '%s' C-second\n") % (tc, tc) self.mktmp(src, ".ipy") out = """\ ARGV 1-: [u'C-first'] ARGV 1-: [u'C-second'] tclass.py: deleting object: C-first """ tt.ipexec_validate(self.fname, out)
def test_tclass(self): mydir = os.path.dirname(__file__) tc = os.path.join(mydir, 'tclass') src = ("%%run '%s' C-first\n" "%%run '%s' C-second\n") % (tc, tc) self.mktmp(src, '.ipy') out = """\ ARGV 1-: ['C-first'] ARGV 1-: ['C-second'] tclass.py: deleting object: C-first """ tt.ipexec_validate(self.fname, out)
def test_exception_path2(self): """Test exception path in exception_validate, expecting windows line endings. """ self.mktmp("import sys\n" "print('A')\n" "print('B')\n" "print('C', file=sys.stderr)\n" "print('D', file=sys.stderr)\n" ) out = "A\r\nB" tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\r\nD")
def test_exception_path(self): """Test exception path in exception_validate. """ self.mktmp("from __future__ import print_function\n" "import sys\n" "print('A')\n" "print('B')\n" "print('C', file=sys.stderr)\n" "print('D', file=sys.stderr)\n" ) out = "A\nB" tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\nD")
def test_obj_del(self): """Test that object's __del__ methods are called on exit.""" if sys.platform == 'win32': try: import win32api except ImportError: raise SkipTest("Test requires pywin32") src = ("class A(object):\n" " def __del__(self):\n" " print 'object A deleted'\n" "a = A()\n") self.mktmp(src) tt.ipexec_validate(self.fname, 'object A deleted')
def test_startup_py(): # create profile dir pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test') # write startup python file with open(os.path.join(pd.startup_dir, '00-start.py'), 'w') as f: f.write('zzz=123\n') # write simple test file, to check that the startup file was run fname = os.path.join(TMP_TEST_DIR, 'test.py') with open(fname, 'w') as f: f.write('print zzz\n') # validate output tt.ipexec_validate(fname, '123', '', options=['--ipython-dir', IP_TEST_DIR, '--profile', 'test'])
def test_obj_del(self): """Test that object's __del__ methods are called on exit.""" if sys.platform == 'win32': try: import win32api except ImportError: raise SkipTest("Test requires pywin32") src = ("class A(object):\n" " def __del__(self):\n" " print 'object A deleted'\n" "a = A()\n") self.mktmp(py3compat.doctest_refactor_print(src)) tt.ipexec_validate(self.fname, 'object A deleted')
def test_startup_ipy(): # create profile dir pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test') # write startup ipython file with open(os.path.join(pd.startup_dir, '00-start.ipy'), 'w') as f: f.write('%profile\n') # write empty script, because we don't need anything to happen # after the startup file is run fname = os.path.join(TMP_TEST_DIR, 'test.py') with open(fname, 'w') as f: f.write('') # validate output tt.ipexec_validate(fname, 'test', '', options=['--ipython-dir', IP_TEST_DIR, '--profile', 'test'])
def test_obj_del(self): """Test that object's __del__ methods are called on exit.""" if sys.platform == "win32": try: import win32api except ImportError: raise SkipTest("Test requires pywin32") src = "class A(object):\n" " def __del__(self):\n" " print 'object A deleted'\n" "a = A()\n" self.mktmp(py3compat.doctest_refactor_print(src)) if dec.module_not_available("sqlite3"): err = "WARNING: IPython History requires SQLite, your history will not be saved\n" else: err = None tt.ipexec_validate(self.fname, "object A deleted", err)
def test_startup_py(): # create profile dir pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test') # write startup python file with open(os.path.join(pd.startup_dir, '00-start.py'), 'w') as f: f.write('zzz=123\n') # write simple test file, to check that the startup file was run fname = os.path.join(TMP_TEST_DIR, 'test.py') with open(fname, 'w') as f: f.write(py3compat.doctest_refactor_print('print zzz\n')) # validate output tt.ipexec_validate( fname, '123', '', options=['--ipython-dir', IP_TEST_DIR, '--profile', 'test'])
def test_tclass(self): mydir = os.path.dirname(__file__) tc = os.path.join(mydir, 'tclass') src = ("%%run '%s' C-first\n" "%%run '%s' C-second\n" "%%run '%s' C-third\n") % (tc, tc, tc) self.mktmp(src, '.ipy') out = """\ ARGV 1-: [{u}'C-first'] ARGV 1-: [{u}'C-second'] tclass.py: deleting object: C-first ARGV 1-: [{u}'C-third'] tclass.py: deleting object: C-second tclass.py: deleting object: C-third """ tt.ipexec_validate(self.fname, py3compat.u_format(out))
def test_obj_del(self): """Test that object's __del__ methods are called on exit.""" if sys.platform == 'win32': try: import win32api except ImportError: raise SkipTest("Test requires pywin32") src = ("class A(object):\n" " def __del__(self):\n" " print 'object A deleted'\n" "a = A()\n") self.mktmp(py3compat.doctest_refactor_print(src)) if dec.module_not_available('sqlite3'): err = 'WARNING: IPython History requires SQLite, your history will not be saved\n' else: err = None tt.ipexec_validate(self.fname, 'object A deleted', err)
def test_obj_del(self): """Test that object's __del__ methods are called on exit.""" if sys.platform == "win32": try: import win32api except ImportError: raise SkipTest("Test requires pywin32") src = ("class A(object):\n" " def __del__(self):\n" " print('object A deleted')\n" "a = A()\n") self.mktmp(src) if dec.module_not_available("sqlite3"): err = "WARNING: IPython History requires SQLite, your history will not be saved\n" else: err = None tt.ipexec_validate(self.fname, "object A deleted", err)
def test_startup_ipy(): # create profile dir pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test') # write startup ipython file with open(os.path.join(pd.startup_dir, '00-start.ipy'), 'w') as f: f.write('%profile\n') # write empty script, because we don't need anything to happen # after the startup file is run fname = os.path.join(TMP_TEST_DIR, 'test.py') with open(fname, 'w') as f: f.write('') # validate output tt.ipexec_validate( fname, 'test', '', options=['--ipython-dir', IP_TEST_DIR, '--profile', 'test'])
def test_obj_del(self): """Test that object's __del__ methods are called on exit.""" if sys.platform == 'win32': try: import win32api except ImportError: raise SkipTest("Test requires pywin32") src = ("class A(object):\n" " def __del__(self):\n" " print('object A deleted')\n" "a = A()\n") self.mktmp(src) if dec.module_not_available('sqlite3'): err = 'WARNING: IPython History requires SQLite, your history will not be saved\n' else: err = None tt.ipexec_validate(self.fname, 'object A deleted', err)
def test_tclass(self): mydir = os.path.dirname(__file__) tc = os.path.join(mydir, "tclass") src = ("%%run '%s' C-first\n" "%%run '%s' C-second\n" "%%run '%s' C-third\n") % (tc, tc, tc) self.mktmp(src, ".ipy") out = """\ ARGV 1-: ['C-first'] ARGV 1-: ['C-second'] tclass.py: deleting object: C-first ARGV 1-: ['C-third'] tclass.py: deleting object: C-second tclass.py: deleting object: C-third """ if dec.module_not_available("sqlite3"): err = "WARNING: IPython History requires SQLite, your history will not be saved\n" else: err = None tt.ipexec_validate(self.fname, out, err)
def test_tclass(self): mydir = os.path.dirname(__file__) tc = os.path.join(mydir, 'tclass') src = ("%%run '%s' C-first\n" "%%run '%s' C-second\n" "%%run '%s' C-third\n") % (tc, tc, tc) self.mktmp(src, '.ipy') out = """\ ARGV 1-: ['C-first'] ARGV 1-: ['C-second'] tclass.py: deleting object: C-first ARGV 1-: ['C-third'] tclass.py: deleting object: C-second tclass.py: deleting object: C-third """ if dec.module_not_available('sqlite3'): err = 'WARNING: IPython History requires SQLite, your history will not be saved\n' else: err = None tt.ipexec_validate(self.fname, out, err)
def test_tclass(self): mydir = os.path.dirname(__file__) tc = os.path.join(mydir, "tclass") src = f"""\ import gc %run "{tc}" C-first gc.collect(0) %run "{tc}" C-second gc.collect(0) %run "{tc}" C-third gc.collect(0) %reset -f """ self.mktmp(src, ".ipy") out = """\ ARGV 1-: ['C-first'] ARGV 1-: ['C-second'] tclass.py: deleting object: C-first ARGV 1-: ['C-third'] tclass.py: deleting object: C-second tclass.py: deleting object: C-third """ err = None tt.ipexec_validate(self.fname, out, err)
def test_printers(self): self.mktmp(ipy_src, '.ipy') tt.ipexec_validate(self.fname, ipy_out)
def validate(self, output): tt.ipexec_validate(self.fname, output, '', options=self.options)