Exemple #1
0
    def test_available_vars(self):
        """
        Assert some globals are available:
            sys, __name__, __file__
        """
        script = """
#encoding: utf-8
sys
__name__
__file__
"""
        dummy_pathenv = ipyenv.PathEnvironment([])
        with ipyenv.RWFreeNamedTempFile(source=script) as tempf:
            ipyenv._execute_file(tempf, dummy_pathenv, load_module=False)
    def test_available_vars(self):
        """
        Assert some globals are available:
            sys, __name__, __file__
        """
        script = """
#encoding: utf-8
sys
__name__
__file__
"""
        dummy_pathenv = ipyenv.PathEnvironment([])
        with ipyenv.RWFreeNamedTempFile(source=script) as tempf:
            ipyenv._execute_file(tempf, dummy_pathenv, load_module=False)
Exemple #3
0
    def test_globals_isolated(self):
        """
        Global variables are isolated.
        Alse for avoiding a regression:
            In the past implementation, `execfile`/py2 relays to `exec`/py3
            when NameError raised by the deprecation of `execfile` in py3,
            which makes a confision in the case NameError raised in the
            execution context of `execfile`. 
        """
        outer_var = 'my var'
        script = """
# encoding: utf-8
print(outer_var)
        """
        dummy_pathenv = ipyenv.PathEnvironment([])
        with ipyenv.RWFreeNamedTempFile(source=script) as tempf:
            with self.assertRaises(NameError):
                ipyenv._execute_file(tempf, dummy_pathenv, load_module=False)
    def test_globals_isolated(self):
        """
        Global variables are isolated.
        Alse for avoiding a regression:
            In the past implementation, `execfile`/py2 relays to `exec`/py3
            when NameError raised by the deprecation of `execfile` in py3,
            which makes a confision in the case NameError raised in the
            execution context of `execfile`. 
        """
        outer_var = "my var"
        script = """
# encoding: utf-8
print(outer_var)
        """
        dummy_pathenv = ipyenv.PathEnvironment([])
        with ipyenv.RWFreeNamedTempFile(source=script) as tempf:
            with self.assertRaises(NameError):
                ipyenv._execute_file(tempf, dummy_pathenv, load_module=False)