Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
test_namespaces.py80 linesDownload Raw Back to tests
1import subprocess2import sys3 4from setuptools._path import paths_on_pythonpath5 6from . import namespaces7 8 9class TestNamespaces:10    def test_mixed_site_and_non_site(self, tmpdir):11        """12        Installing two packages sharing the same namespace, one installed13        to a site dir and the other installed just to a path on PYTHONPATH14        should leave the namespace in tact and both packages reachable by15        import.16        """17        pkg_A = namespaces.build_namespace_package(tmpdir, 'myns.pkgA')18        pkg_B = namespaces.build_namespace_package(tmpdir, 'myns.pkgB')19        site_packages = tmpdir / 'site-packages'20        path_packages = tmpdir / 'path-packages'21        targets = site_packages, path_packages22        # use pip to install to the target directory23        install_cmd = [24            sys.executable,25            '-m',26            'pip.__main__',27            'install',28            str(pkg_A),29            '-t',30            str(site_packages),31        ]32        subprocess.check_call(install_cmd)33        namespaces.make_site_dir(site_packages)34        install_cmd = [35            sys.executable,36            '-m',37            'pip.__main__',38            'install',39            str(pkg_B),40            '-t',41            str(path_packages),42        ]43        subprocess.check_call(install_cmd)44        try_import = [45            sys.executable,46            '-c',47            'import myns.pkgA; import myns.pkgB',48        ]49        with paths_on_pythonpath(map(str, targets)):50            subprocess.check_call(try_import)51 52    def test_namespace_package_installed_and_cwd(self, tmpdir):53        """54        Installing a namespace packages but also having it in the current55        working directory, only one version should take precedence.56        """57        pkg_A = namespaces.build_namespace_package(tmpdir, 'myns.pkgA')58        target = tmpdir / 'packages'59        # use pip to install to the target directory60        install_cmd = [61            sys.executable,62            '-m',63            'pip.__main__',64            'install',65            str(pkg_A),66            '-t',67            str(target),68        ]69        subprocess.check_call(install_cmd)70        namespaces.make_site_dir(target)71 72        # ensure that package imports73        pkg_resources_imp = [74            sys.executable,75            '-c',76            'import myns.pkgA',77        ]78        with paths_on_pythonpath([str(target)]):79            subprocess.check_call(pkg_resources_imp, cwd=str(pkg_A))80 
codekingpro/portable-devtools · Team Ai