def teardown_environment():
"""Restore things that were remembered by the setup_environment function
"""
(oldenv, os.name, sys.platform, path.get_home_dir, IPython.__file__, old_wd) = oldstuff
os.chdir(old_wd)
reload(path)
for key in list(env):
if key not in oldenv:
del env[key]
env.update(oldenv)
if hasattr(sys, 'frozen'):
del sys.frozen
# Build decorator that uses the setup_environment/setup_environment
python类__file__()的实例源码
def setup_environment():
"""Setup testenvironment for some functions that are tested
in this module. In particular this functions stores attributes
and other things that we need to stub in some test functions.
This needs to be done on a function level and not module level because
each testfunction needs a pristine environment.
"""
global oldstuff, platformstuff
oldstuff = (env.copy(), os.name, sys.platform, path.get_home_dir, IPython.__file__, os.getcwd())
def test_get_home_dir_1():
"""Testcase for py2exe logic, un-compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py"))
home_dir = path.get_home_dir()
nt.assert_equal(home_dir, unfrozen)
def test_get_home_dir_2():
"""Testcase for py2exe logic, compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower()
home_dir = path.get_home_dir(True)
nt.assert_equal(home_dir, unfrozen)
def get_ipython_package_dir():
"""Get the base directory where IPython itself is installed."""
ipdir = os.path.dirname(IPython.__file__)
return py3compat.cast_unicode(ipdir, fs_encoding)
def setup_environment():
"""Setup testenvironment for some functions that are tested
in this module. In particular this functions stores attributes
and other things that we need to stub in some test functions.
This needs to be done on a function level and not module level because
each testfunction needs a pristine environment.
"""
global oldstuff, platformstuff
oldstuff = (env.copy(), os.name, sys.platform, path.get_home_dir, IPython.__file__, os.getcwd())
def teardown_environment():
"""Restore things that were remembered by the setup_environment function
"""
(oldenv, os.name, sys.platform, path.get_home_dir, IPython.__file__, old_wd) = oldstuff
os.chdir(old_wd)
reload(path)
for key in list(env):
if key not in oldenv:
del env[key]
env.update(oldenv)
if hasattr(sys, 'frozen'):
del sys.frozen
# Build decorator that uses the setup_environment/setup_environment
def test_get_home_dir_1():
"""Testcase for py2exe logic, un-compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py"))
home_dir = path.get_home_dir()
nt.assert_equal(home_dir, unfrozen)
def test_get_home_dir_2():
"""Testcase for py2exe logic, compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower()
home_dir = path.get_home_dir(True)
nt.assert_equal(home_dir, unfrozen)
def get_ipython_package_dir():
"""Get the base directory where IPython itself is installed."""
ipdir = os.path.dirname(IPython.__file__)
return py3compat.cast_unicode(ipdir, fs_encoding)
def setup_environment():
"""Setup testenvironment for some functions that are tested
in this module. In particular this functions stores attributes
and other things that we need to stub in some test functions.
This needs to be done on a function level and not module level because
each testfunction needs a pristine environment.
"""
global oldstuff, platformstuff
oldstuff = (env.copy(), os.name, sys.platform, path.get_home_dir, IPython.__file__, os.getcwd())
def teardown_environment():
"""Restore things that were remembered by the setup_environment function
"""
(oldenv, os.name, sys.platform, path.get_home_dir, IPython.__file__, old_wd) = oldstuff
os.chdir(old_wd)
reload(path)
for key in list(env):
if key not in oldenv:
del env[key]
env.update(oldenv)
if hasattr(sys, 'frozen'):
del sys.frozen
# Build decorator that uses the setup_environment/setup_environment
def test_get_home_dir_1():
"""Testcase for py2exe logic, un-compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py"))
home_dir = path.get_home_dir()
nt.assert_equal(home_dir, unfrozen)
def test_get_home_dir_2():
"""Testcase for py2exe logic, compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower()
home_dir = path.get_home_dir(True)
nt.assert_equal(home_dir, unfrozen)
def get_ipython_package_dir():
"""Get the base directory where IPython itself is installed."""
ipdir = os.path.dirname(IPython.__file__)
return py3compat.cast_unicode(ipdir, fs_encoding)
def setup_environment():
"""Setup testenvironment for some functions that are tested
in this module. In particular this functions stores attributes
and other things that we need to stub in some test functions.
This needs to be done on a function level and not module level because
each testfunction needs a pristine environment.
"""
global oldstuff, platformstuff
oldstuff = (env.copy(), os.name, sys.platform, path.get_home_dir, IPython.__file__, os.getcwd())
def teardown_environment():
"""Restore things that were remembered by the setup_environment function
"""
(oldenv, os.name, sys.platform, path.get_home_dir, IPython.__file__, old_wd) = oldstuff
os.chdir(old_wd)
reload(path)
for key in list(env):
if key not in oldenv:
del env[key]
env.update(oldenv)
if hasattr(sys, 'frozen'):
del sys.frozen
# Build decorator that uses the setup_environment/setup_environment
def test_get_home_dir_1():
"""Testcase for py2exe logic, un-compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py"))
home_dir = path.get_home_dir()
nt.assert_equal(home_dir, unfrozen)
def test_get_home_dir_2():
"""Testcase for py2exe logic, compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower()
home_dir = path.get_home_dir(True)
nt.assert_equal(home_dir, unfrozen)
def get_ipython_package_dir():
"""Get the base directory where IPython itself is installed."""
ipdir = os.path.dirname(IPython.__file__)
return py3compat.cast_unicode(ipdir, fs_encoding)