Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
test_develop.py114 linesDownload Raw Back to tests
1"""develop tests"""2 3import os4import platform5import subprocess6import sys7 8import pytest9 10from setuptools._path import paths_on_pythonpath11 12from . import contexts, namespaces13 14SETUP_PY = """\15from setuptools import setup16 17setup(name='foo',18    packages=['foo'],19)20"""21 22INIT_PY = """print "foo"23"""24 25 26@pytest.fixture27def temp_user(monkeypatch):28    with contexts.tempdir() as user_base:29        with contexts.tempdir() as user_site:30            monkeypatch.setattr('site.USER_BASE', user_base)31            monkeypatch.setattr('site.USER_SITE', user_site)32            yield33 34 35@pytest.fixture36def test_env(tmpdir, temp_user):37    target = tmpdir38    foo = target.mkdir('foo')39    setup = target / 'setup.py'40    if setup.isfile():41        raise ValueError(dir(target))42    with setup.open('w') as f:43        f.write(SETUP_PY)44    init = foo / '__init__.py'45    with init.open('w') as f:46        f.write(INIT_PY)47    with target.as_cwd():48        yield target49 50 51class TestNamespaces:52    @staticmethod53    def install_develop(src_dir, target):54        develop_cmd = [55            sys.executable,56            'setup.py',57            'develop',58            '--install-dir',59            str(target),60        ]61        with src_dir.as_cwd():62            with paths_on_pythonpath([str(target)]):63                subprocess.check_call(develop_cmd)64 65    @pytest.mark.xfail(reason="pkg_resources has been removed")66    @pytest.mark.skipif(67        bool(os.environ.get("APPVEYOR")),68        reason="https://github.com/pypa/setuptools/issues/851",69    )70    @pytest.mark.skipif(71        platform.python_implementation() == 'PyPy',72        reason="https://github.com/pypa/setuptools/issues/1202",73    )74    @pytest.mark.uses_network75    def test_namespace_package_importable(self, tmpdir):76        """77        Installing two packages sharing the same namespace, one installed78        naturally using pip or `--single-version-externally-managed`79        and the other installed using `develop` should leave the namespace80        in tact and both packages reachable by import.81        """82        pkg_A = namespaces.build_namespace_package(tmpdir, 'myns.pkgA')83        pkg_B = namespaces.build_namespace_package(tmpdir, 'myns.pkgB')84        target = tmpdir / 'packages'85        # use pip to install to the target directory86        install_cmd = [87            sys.executable,88            '-m',89            'pip',90            'install',91            str(pkg_A),92            '-t',93            str(target),94        ]95        subprocess.check_call(install_cmd)96        self.install_develop(pkg_B, target)97        namespaces.make_site_dir(target)98        try_import = [99            sys.executable,100            '-c',101            'import myns.pkgA; import myns.pkgB',102        ]103        with paths_on_pythonpath([str(target)]):104            subprocess.check_call(try_import)105 106        # additionally ensure that pkg_resources import works107        pkg_resources_imp = [108            sys.executable,109            '-c',110            'import pkg_resources',111        ]112        with paths_on_pythonpath([str(target)]):113            subprocess.check_call(pkg_resources_imp)114 
codekingpro/portable-devtools · Team Ai