Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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()'])
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
    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()'])
Exemplo n.º 8
0
    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()'])
Exemplo n.º 9
0
    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()'])
Exemplo n.º 10
0
    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")
Exemplo n.º 11
0
 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)
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 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')
Exemplo n.º 14
0
    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)
Exemplo n.º 15
0
    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)
Exemplo n.º 16
0
 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")
Exemplo n.º 17
0
 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)
Exemplo n.º 18
0
 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")
Exemplo n.º 19
0
    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')
Exemplo n.º 20
0
 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")
Exemplo n.º 21
0
    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)
Exemplo n.º 22
0
    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)
Exemplo n.º 23
0
 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")
Exemplo n.º 24
0
 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")
Exemplo n.º 25
0
 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')
Exemplo n.º 26
0
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'])
Exemplo n.º 27
0
 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')
Exemplo n.º 28
0
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'])
Exemplo n.º 29
0
 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)
Exemplo n.º 30
0
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'])
Exemplo n.º 31
0
    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))
Exemplo n.º 32
0
 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)
Exemplo n.º 33
0
 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)
Exemplo n.º 34
0
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)
Exemplo n.º 36
0
    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)
Exemplo n.º 37
0
    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)
Exemplo n.º 38
0
    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)
Exemplo n.º 39
0
 def test_printers(self):
     self.mktmp(ipy_src, '.ipy')
     tt.ipexec_validate(self.fname, ipy_out)
Exemplo n.º 40
0
 def validate(self, output):
     tt.ipexec_validate(self.fname, output, '', options=self.options)