test_sandbox.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:setuptools 作者: pypa 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号