Beispiel #1
0
    def test_builtins_id(self):
        """Check that %run doesn't damage __builtins__ """

        # Test that the id of __builtins__ is not modified by %run
        bid1 = id(_ip.user_ns['__builtins__'])
        self.run_tmpfile()
        bid2 = id(_ip.user_ns['__builtins__'])
        tt.assert_equals(bid1, bid2)
Beispiel #2
0
 def test_builtins_id(self):
     """Check that %run doesn't damage __builtins__ """
     _ip = get_ipython()
     # Test that the id of __builtins__ is not modified by %run
     bid1 = id(_ip.user_ns['__builtins__'])
     self.run_tmpfile()
     bid2 = id(_ip.user_ns['__builtins__'])
     tt.assert_equals(bid1, bid2)
Beispiel #3
0
 def test_builtins_type(self):
     """Check that the type of __builtins__ doesn't change with %run.
     
     However, the above could pass if __builtins__ was already modified to
     be a dict (it should be a module) by a previous use of %run.  So we
     also check explicitly that it really is a module:
     """
     self.run_tmpfile()
     tt.assert_equals(type(_ip.user_ns['__builtins__']),type(sys))
Beispiel #4
0
 def test_run_i_after_reset(self):
     """Check that %run -i still works after %reset (gh-693)"""
     src = "yy = zz\n"
     self.mktmp(src)
     _ip.run_cell("zz = 23")
     _ip.magic('run -i %s' % self.fname)
     tt.assert_equals(_ip.user_ns['yy'], 23)
     _ip.magic('reset -f')
     _ip.run_cell("zz = 23")
     _ip.magic('run -i %s' % self.fname)
     tt.assert_equals(_ip.user_ns['yy'], 23)
 def test_run_i_after_reset(self):
     """Check that %run -i still works after %reset (gh-693)"""
     src = "yy = zz\n"
     self.mktmp(src)
     _ip.run_cell("zz = 23")
     _ip.magic('run -i %s' % self.fname)
     tt.assert_equals(_ip.user_ns['yy'], 23)
     _ip.magic('reset -f')
     _ip.run_cell("zz = 23")
     _ip.magic('run -i %s' % self.fname)
     tt.assert_equals(_ip.user_ns['yy'], 23)
Beispiel #6
0
    def test_aggressive_namespace_cleanup(self):
        """Test that namespace cleanup is not too aggressive GH-238

        Returning from another run magic deletes the namespace"""
        # see ticket https://github.com/ipython/ipython/issues/238
        class secondtmp(tt.TempFileMixin): pass
        empty = secondtmp()
        empty.mktmp('')
        src = ("ip = get_ipython()\n"
               "for i in range(5):\n"
               "   try:\n"
               "       ip.magic('run %s')\n"
               "   except NameError, e:\n"
               "       print i;break\n" % empty.fname)
        self.mktmp(py3compat.doctest_refactor_print(src))
        _ip.magic('run %s' % self.fname)
        _ip.run_cell('ip == get_ipython()')
        tt.assert_equals(_ip.user_ns['i'], 5)
Beispiel #7
0
    def test_aggressive_namespace_cleanup(self):
        """Test that namespace cleanup is not too aggressive GH-238

        Returning from another run magic deletes the namespace"""
        # see ticket https://github.com/ipython/ipython/issues/238
        class secondtmp(tt.TempFileMixin): pass
        empty = secondtmp()
        empty.mktmp('')
        src = ("ip = get_ipython()\n"
               "for i in range(5):\n"
               "   try:\n"
               "       ip.magic('run %s')\n"
               "   except NameError, e:\n"
               "       print i;break\n" % empty.fname)
        self.mktmp(py3compat.doctest_refactor_print(src))
        _ip.magic('run %s' % self.fname)
        _ip.run_cell('ip == get_ipython()')
        tt.assert_equals(_ip.user_ns['i'], 5)
Beispiel #8
0
 def test_unicode(self):
     """Check that files in odd encodings are accepted."""
     mydir = os.path.dirname(__file__)
     na = os.path.join(mydir, 'nonascii.py')
     _ip.magic('run "%s"' % na)
     tt.assert_equals(_ip.user_ns['u'], u'Ўт№Ф')
 def test_unicode(self):
     """Check that files in odd encodings are accepted."""
     mydir = os.path.dirname(__file__)
     na = os.path.join(mydir, 'nonascii.py')
     _ip.magic('run "%s"' % na)
     tt.assert_equals(_ip.user_ns['u'], 'Ўт№Ф')