Beispiel #1
0
    def test_run_second(self):
        """Test that running a second file doesn't clobber the first, gh-3547"""
        self.mktmp("avar = 1\n" "def afunc():\n" "  return avar\n")

        with tt.TempFileMixin() as empty:
            empty.mktmp("")

            _ip.magic("run %s" % self.fname)
            _ip.magic("run %s" % empty.fname)
            assert _ip.user_ns["afunc"]() == 1
Beispiel #2
0
    def test_run_second(self):
        """Test that running a second file doesn't clobber the first, gh-3547
        """
        self.mktmp("avar = 1\n" "def afunc():\n" "  return avar\n")

        empty = tt.TempFileMixin()
        empty.mktmp("")

        _ip.magic('run %s' % self.fname)
        _ip.magic('run %s' % empty.fname)
        nt.assert_equal(_ip.user_ns['afunc'](), 1)
    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
        
        with tt.TempFileMixin() as empty:
            empty.mktmp('')
            # On Windows, the filename will have \users in it, so we need to use the
            # repr so that the \u becomes \\u.
            src = ("ip = get_ipython()\n"
                   "for i in range(5):\n"
                   "   try:\n"
                   "       ip.magic(%r)\n"
                   "   except NameError as e:\n"
                   "       print(i)\n"
                   "       break\n" % ('run ' + empty.fname))
            self.mktmp(src)
            _ip.magic('run %s' % self.fname)
            _ip.run_cell('ip == get_ipython()')
            nt.assert_equal(_ip.user_ns['i'], 4)