'Regression test for Distribute issue #318
Ensure that a package with setup_requires can be installed when
setuptools is installed in the user site-packages without causing a
SandboxViolation.'

def test_setup_requires(self):

    test_setup_attrs = {'name': 'test_pkg', 'version': '0.0', 'setup_requires': ['foobar'], 'dependency_links': [os.path.abspath(self.dir)]}
    test_pkg = os.path.join(self.dir, 'test_pkg')
    test_setup_py = os.path.join(test_pkg, 'setup.py')
    os.mkdir(test_pkg)
    f = open(test_setup_py, 'w')
    f.write(textwrap.dedent(('                                                import    setuptools\n                                                setuptools.setup(**%r)\n                                ' % test_setup_attrs)))
    f.close()
    foobar_path = os.path.join(self.dir, 'foobar-0.1.tar.gz')
    make_trivial_sdist(foobar_path, textwrap.dedent("                                                                import    setuptools\n                                                                setuptools.setup(\n                                                                                name='foobar',\n                                                                                version='0.1'\n                                                                )\n                                                "))
    old_stdout = sys.stdout
    old_stderr = sys.stderr
    sys.stdout = StringIO()
    sys.stderr = StringIO()
    try:
        with reset_setup_stop_context():
            run_setup(test_setup_py, ['install'])
    except SandboxViolation:
        self.fail('Installation    caused    SandboxViolation')
    finally:
        sys.stdout = old_stdout
        sys.stderr = old_stderr
