当前位置: 首页>>代码示例>>Python>>正文


Python pkg1.pkg2方法代码示例

本文整理汇总了Python中pkg1.pkg2方法的典型用法代码示例。如果您正苦于以下问题:Python pkg1.pkg2方法的具体用法?Python pkg1.pkg2怎么用?Python pkg1.pkg2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pkg1的用法示例。


在下文中一共展示了pkg1.pkg2方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_two_levels_deep

# 需要导入模块: import pkg1 [as 别名]
# 或者: from pkg1 import pkg2 [as 别名]
def test_two_levels_deep(self):
        """
        Test nested namespace packages
        Create namespace packages in the following tree :
            site-packages-1/pkg1/pkg2
            site-packages-2/pkg1/pkg2
        Check both are in the _namespace_packages dict and that their __path__
        is correct
        """
        sys.path.append(os.path.join(self._tmpdir, "site-pkgs2"))
        os.makedirs(os.path.join(self._tmpdir, "site-pkgs", "pkg1", "pkg2"))
        os.makedirs(os.path.join(self._tmpdir, "site-pkgs2", "pkg1", "pkg2"))
        ns_str = "__import__('pkg_resources').declare_namespace(__name__)\n"
        for site in ["site-pkgs", "site-pkgs2"]:
            pkg1_init = open(os.path.join(self._tmpdir, site,
                             "pkg1", "__init__.py"), "w")
            pkg1_init.write(ns_str)
            pkg1_init.close()
            pkg2_init = open(os.path.join(self._tmpdir, site,
                             "pkg1", "pkg2", "__init__.py"), "w")
            pkg2_init.write(ns_str)
            pkg2_init.close()
        import pkg1
        self._assertIn("pkg1", pkg_resources._namespace_packages.keys())
        try:
            import pkg1.pkg2
        except ImportError:
            self.fail("Setuptools tried to import the parent namespace package")
        # check the _namespace_packages dict
        self._assertIn("pkg1.pkg2", pkg_resources._namespace_packages.keys())
        self.assertEqual(pkg_resources._namespace_packages["pkg1"], ["pkg1.pkg2"])
        # check the __path__ attribute contains both paths
        self.assertEqual(pkg1.pkg2.__path__, [
            os.path.join(self._tmpdir, "site-pkgs", "pkg1", "pkg2"),
            os.path.join(self._tmpdir, "site-pkgs2", "pkg1", "pkg2")]) 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:37,代码来源:test_resources.py

示例2: test_two_levels_deep

# 需要导入模块: import pkg1 [as 别名]
# 或者: from pkg1 import pkg2 [as 别名]
def test_two_levels_deep(self):
        """
        Test nested namespace packages
        Create namespace packages in the following tree :
            site-packages-1/pkg1/pkg2
            site-packages-2/pkg1/pkg2
        Check both are in the _namespace_packages dict and that their __path__
        is correct
        """
        sys.path.append(os.path.join(self._tmpdir, "site-pkgs2"))
        os.makedirs(os.path.join(self._tmpdir, "site-pkgs", "pkg1", "pkg2"))
        os.makedirs(os.path.join(self._tmpdir, "site-pkgs2", "pkg1", "pkg2"))
        ns_str = "__import__('pkg_resources').declare_namespace(__name__)\n"
        for site in ["site-pkgs", "site-pkgs2"]:
            pkg1_init = open(os.path.join(self._tmpdir, site,
                             "pkg1", "__init__.py"), "w")
            pkg1_init.write(ns_str)
            pkg1_init.close()
            pkg2_init = open(os.path.join(self._tmpdir, site,
                             "pkg1", "pkg2", "__init__.py"), "w")
            pkg2_init.write(ns_str)
            pkg2_init.close()
        import pkg1
        assert "pkg1" in pkg_resources._namespace_packages
        # attempt to import pkg2 from site-pkgs2
        import pkg1.pkg2
        # check the _namespace_packages dict
        assert "pkg1.pkg2" in pkg_resources._namespace_packages
        assert pkg_resources._namespace_packages["pkg1"] == ["pkg1.pkg2"]
        # check the __path__ attribute contains both paths
        expected = [
            os.path.join(self._tmpdir, "site-pkgs", "pkg1", "pkg2"),
            os.path.join(self._tmpdir, "site-pkgs2", "pkg1", "pkg2"),
        ]
        assert pkg1.pkg2.__path__ == expected 
开发者ID:loremIpsum1771,项目名称:chalktalk_docs,代码行数:37,代码来源:test_resources.py

示例3: test_two_levels_deep

# 需要导入模块: import pkg1 [as 别名]
# 或者: from pkg1 import pkg2 [as 别名]
def test_two_levels_deep(self):
        """
        Test nested namespace packages
        Create namespace packages in the following tree :
            site-packages-1/pkg1/pkg2
            site-packages-2/pkg1/pkg2
        Check both are in the _namespace_packages dict and that their __path__
        is correct
        """
        sys.path.append(os.path.join(self._tmpdir, "site-pkgs2"))
        os.makedirs(os.path.join(self._tmpdir, "site-pkgs", "pkg1", "pkg2"))
        os.makedirs(os.path.join(self._tmpdir, "site-pkgs2", "pkg1", "pkg2"))
        ns_str = "__import__('pkg_resources').declare_namespace(__name__)\n"
        for site in ["site-pkgs", "site-pkgs2"]:
            pkg1_init = open(os.path.join(self._tmpdir, site,
                             "pkg1", "__init__.py"), "w")
            pkg1_init.write(ns_str)
            pkg1_init.close()
            pkg2_init = open(os.path.join(self._tmpdir, site,
                             "pkg1", "pkg2", "__init__.py"), "w")
            pkg2_init.write(ns_str)
            pkg2_init.close()
        import pkg1
        self._assertIn("pkg1", pkg_resources._namespace_packages.keys())
        try:
            import pkg1.pkg2
        except ImportError:
            self.fail("Setuptools tried to import the parent namespace package")
        # check the _namespace_packages dict
        self._assertIn("pkg1.pkg2", pkg_resources._namespace_packages.keys())
        self.assertEqual(pkg_resources._namespace_packages["pkg1"], ["pkg1.pkg2"])
        # check the __path__ attribute contains both paths
        self.assertEqual(pkg1.pkg2.__path__, [
                os.path.join(self._tmpdir, "site-pkgs", "pkg1", "pkg2"),
                os.path.join(self._tmpdir, "site-pkgs2", "pkg1", "pkg2") ]) 
开发者ID:pbrf,项目名称:dymo-m10-python,代码行数:37,代码来源:test_resources.py

示例4: test_two_levels_deep

# 需要导入模块: import pkg1 [as 别名]
# 或者: from pkg1 import pkg2 [as 别名]
def test_two_levels_deep(self, symlinked_tmpdir):
        """
        Test nested namespace packages
        Create namespace packages in the following tree :
            site-packages-1/pkg1/pkg2
            site-packages-2/pkg1/pkg2
        Check both are in the _namespace_packages dict and that their __path__
        is correct
        """
        real_tmpdir = symlinked_tmpdir.realpath()
        tmpdir = symlinked_tmpdir
        sys.path.append(str(tmpdir / 'site-pkgs2'))
        site_dirs = tmpdir / 'site-pkgs', tmpdir / 'site-pkgs2'
        for site in site_dirs:
            pkg1 = site / 'pkg1'
            pkg2 = pkg1 / 'pkg2'
            pkg2.ensure_dir()
            (pkg1 / '__init__.py').write_text(self.ns_str, encoding='utf-8')
            (pkg2 / '__init__.py').write_text(self.ns_str, encoding='utf-8')
        import pkg1
        assert "pkg1" in pkg_resources._namespace_packages
        # attempt to import pkg2 from site-pkgs2
        import pkg1.pkg2
        # check the _namespace_packages dict
        assert "pkg1.pkg2" in pkg_resources._namespace_packages
        assert pkg_resources._namespace_packages["pkg1"] == ["pkg1.pkg2"]
        # check the __path__ attribute contains both paths
        expected = [
            str(real_tmpdir / "site-pkgs" / "pkg1" / "pkg2"),
            str(real_tmpdir / "site-pkgs2" / "pkg1" / "pkg2"),
        ]
        assert pkg1.pkg2.__path__ == expected 
开发者ID:pypa,项目名称:pkg_resources,代码行数:34,代码来源:test_resources.py


注:本文中的pkg1.pkg2方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。