本文整理汇总了Python中setuptools.sandbox方法的典型用法代码示例。如果您正苦于以下问题:Python setuptools.sandbox方法的具体用法?Python setuptools.sandbox怎么用?Python setuptools.sandbox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类setuptools
的用法示例。
在下文中一共展示了setuptools.sandbox方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _no_sandbox
# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def _no_sandbox(function):
def __no_sandbox(*args, **kw):
try:
from setuptools.sandbox import DirectorySandbox
if not hasattr(DirectorySandbox, '_old'):
def violation(*args):
pass
DirectorySandbox._old = DirectorySandbox._violation
DirectorySandbox._violation = violation
patched = True
else:
patched = False
except ImportError:
patched = False
try:
return function(*args, **kw)
finally:
if patched:
DirectorySandbox._violation = DirectorySandbox._old
del DirectorySandbox._old
return __no_sandbox
示例2: test_unpickleable_exception_when_hiding_setuptools
# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_unpickleable_exception_when_hiding_setuptools(self):
"""
As revealed in #440, an infinite recursion can occur if an unpickleable
exception while setuptools is hidden. Ensure this doesn't happen.
"""
class ExceptionUnderTest(Exception):
"""
An unpickleable exception (not in globals).
"""
with pytest.raises(setuptools.sandbox.UnpickleableException) as caught:
with setuptools.sandbox.save_modules():
setuptools.sandbox.hide_setuptools()
raise ExceptionUnderTest()
msg, = caught.value.args
assert msg == 'ExceptionUnderTest()'
示例3: _rename_path
# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def _rename_path(path):
new_name = path + '.OLD.%s' % time.time()
log.warn('Renaming %s into %s', path, new_name)
try:
from setuptools.sandbox import DirectorySandbox
def _violation(*args):
pass
DirectorySandbox._violation = _violation
except ImportError:
pass
os.rename(path, new_name)
return new_name
示例4: test_devnull
# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_devnull(self, tmpdir):
with setuptools.sandbox.DirectorySandbox(str(tmpdir)):
self._file_writer(os.devnull)
示例5: test_setup_py_with_BOM
# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_setup_py_with_BOM(self):
"""
It should be possible to execute a setup.py with a Byte Order Mark
"""
target = pkg_resources.resource_filename(
__name__,
'script-with-bom.py')
namespace = types.ModuleType('namespace')
setuptools.sandbox._execfile(target, vars(namespace))
assert namespace.result == 'passed'
示例6: test_setup_py_with_CRLF
# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_setup_py_with_CRLF(self, tmpdir):
setup_py = tmpdir / 'setup.py'
with setup_py.open('wb') as stream:
stream.write(b'"degenerate script"\r\n')
setuptools.sandbox._execfile(str(setup_py), globals())
示例7: test_exception_trapped
# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_exception_trapped(self):
with setuptools.sandbox.ExceptionSaver():
raise ValueError("details")
示例8: test_exception_resumed
# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_exception_resumed(self):
with setuptools.sandbox.ExceptionSaver() as saved_exc:
raise ValueError("details")
with pytest.raises(ValueError) as caught:
saved_exc.resume()
assert isinstance(caught.value, ValueError)
assert str(caught.value) == 'details'
示例9: test_no_exception_passes_quietly
# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_no_exception_passes_quietly(self):
with setuptools.sandbox.ExceptionSaver() as saved_exc:
pass
saved_exc.resume()
示例10: test_unpickleable_exception
# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_unpickleable_exception(self):
class CantPickleThis(Exception):
"This Exception is unpickleable because it's not in globals"
def __repr__(self):
return 'CantPickleThis%r' % (self.args,)
with setuptools.sandbox.ExceptionSaver() as saved_exc:
raise CantPickleThis('detail')
with pytest.raises(setuptools.sandbox.UnpickleableException) as caught:
saved_exc.resume()
assert str(caught.value) == "CantPickleThis('detail',)"
示例11: test_sandbox_violation_raised_hiding_setuptools
# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_sandbox_violation_raised_hiding_setuptools(self, tmpdir):
"""
When in a sandbox with setuptools hidden, a SandboxViolation
should reflect a proper exception and not be wrapped in
an UnpickleableException.
"""
def write_file():
"Trigger a SandboxViolation by writing outside the sandbox"
with open('/etc/foo', 'w'):
pass
with pytest.raises(setuptools.sandbox.SandboxViolation) as caught:
with setuptools.sandbox.save_modules():
setuptools.sandbox.hide_setuptools()
with setuptools.sandbox.DirectorySandbox(str(tmpdir)):
write_file()
cmd, args, kwargs = caught.value.args
assert cmd == 'open'
assert args == ('/etc/foo', 'w')
assert kwargs == {}
msg = str(caught.value)
assert 'open' in msg
assert "('/etc/foo', 'w')" in msg
示例12: user_install_setup_context
# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def user_install_setup_context(self, *args, **kwargs):
"""
Wrap sandbox.setup_context to patch easy_install in that context to
appear as user-installed.
"""
with self.orig_context(*args, **kwargs):
import setuptools.command.easy_install as ei
ei.__file__ = site.USER_SITE
yield
示例13: test_setup_requires_honors_fetch_params
# 需要导入模块: import setuptools [as 别名]
# 或者: from setuptools import sandbox [as 别名]
def test_setup_requires_honors_fetch_params(self, mock_index, monkeypatch):
"""
When easy_install installs a source distribution which specifies
setup_requires, it should honor the fetch parameters (such as
index-url, and find-links).
"""
monkeypatch.setenv(str('PIP_RETRIES'), str('0'))
monkeypatch.setenv(str('PIP_TIMEOUT'), str('0'))
with contexts.quiet():
# create an sdist that has a build-time dependency.
with TestSetupRequires.create_sdist() as dist_file:
with contexts.tempdir() as temp_install_dir:
with contexts.environment(PYTHONPATH=temp_install_dir):
ei_params = [
'--index-url', mock_index.url,
'--exclude-scripts',
'--install-dir', temp_install_dir,
dist_file,
]
with sandbox.save_argv(['easy_install']):
# attempt to install the dist. It should
# fail because it doesn't exist.
with pytest.raises(SystemExit):
easy_install_pkg.main(ei_params)
# there should have been one requests to the server
assert [r.path for r in mock_index.requests] == ['/does-not-exist/']