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


Python Reactor.load_project_module方法代码示例

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


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

示例1: ReactorTest

# 需要导入模块: from pybuilder.reactor import Reactor [as 别名]
# 或者: from pybuilder.reactor.Reactor import load_project_module [as 别名]

#.........这里部分代码省略.........

        self.assertRaises(
            PyBuilderException, self.reactor.verify_project_directory, "spam", "eggs")

        verify(os.path).abspath("spam")
        verify(os.path).exists("spam")
        verify(os.path).isdir("spam")
        verify(os.path).join("spam", "eggs")
        verify(os.path).exists("spam/eggs")
        verify(os.path).isfile("spam/eggs")

    def test_should_return_directory_and_full_path_of_descriptor_when_verifying_project_directory(self):
        when(os.path).abspath("spam").thenReturn("/spam")
        when(os.path).exists("/spam").thenReturn(True)
        when(os.path).isdir("/spam").thenReturn(True)
        when(os.path).join("/spam", "eggs").thenReturn("/spam/eggs")
        when(os.path).exists("/spam/eggs").thenReturn(True)
        when(os.path).isfile("/spam/eggs").thenReturn(True)

        self.assertEquals(
            ("/spam", "/spam/eggs"), self.reactor.verify_project_directory("spam", "eggs"))

        verify(os.path).abspath("spam")
        verify(os.path).exists("/spam")
        verify(os.path).isdir("/spam")
        verify(os.path).join("/spam", "eggs")
        verify(os.path).exists("/spam/eggs")
        verify(os.path).isfile("/spam/eggs")

    def test_should_raise_exception_when_loading_project_module_and_import_raises_exception(self):
        when(imp).load_source("build", "spam").thenRaise(ImportError("spam"))

        self.assertRaises(
            PyBuilderException, self.reactor.load_project_module, "spam")

        verify(imp).load_source("build", "spam")

    def test_should_return_module_when_loading_project_module_and_import_raises_exception(self):
        module = mock()
        when(imp).load_source("build", "spam").thenReturn(module)

        self.assertEquals(module, self.reactor.load_project_module("spam"))

        verify(imp).load_source("build", "spam")

    def test_ensure_project_attributes_are_set_when_instantiating_project(self):
        module = mock(version="version",
                      default_task="default_task",
                      summary="summary",
                      home_page="home_page",
                      description="description",
                      authors="authors",
                      license="license",
                      url="url")

        self.reactor.project = mock()
        self.reactor.project_module = module

        self.reactor.apply_project_attributes()

        self.assertEquals("version", self.reactor.project.version)
        self.assertEquals("default_task", self.reactor.project.default_task)
        self.assertEquals("summary", self.reactor.project.summary)
        self.assertEquals("home_page", self.reactor.project.home_page)
        self.assertEquals("description", self.reactor.project.description)
        self.assertEquals("authors", self.reactor.project.authors)
开发者ID:Ferreiros-lab,项目名称:pybuilder,代码行数:70,代码来源:reactor_tests.py

示例2: ReactorTest

# 需要导入模块: from pybuilder.reactor import Reactor [as 别名]
# 或者: from pybuilder.reactor.Reactor import load_project_module [as 别名]

#.........这里部分代码省略.........
                                                                                              os_path_isfile):
        self.assertRaises(
            PyBuilderException, self.reactor.verify_project_directory, "spam", "eggs")

        os_path_abspath.assert_called_with("spam")
        os_path_exists.assert_has_calls([call("spam"), call("spam/eggs")])
        os_path_isdir.assert_called_with("spam")
        os_path_join.assert_called_with("spam", "eggs")
        os_path_isfile.assert_called_with("spam/eggs")

    @patch("pybuilder.reactor.os.path.isfile", return_value=True)
    @patch("pybuilder.reactor.os.path.join", side_effect=lambda *x: "/".join(x))
    @patch("pybuilder.reactor.os.path.isdir", return_value=True)
    @patch("pybuilder.reactor.os.path.exists", return_value=True)
    @patch("pybuilder.reactor.os.path.abspath", return_value="/spam")
    def test_should_return_directory_and_full_path_of_descriptor_when_verifying_project_directory(self,
                                                                                                  os_path_abspath,
                                                                                                  os_path_exists,
                                                                                                  os_path_isdir,
                                                                                                  os_path_join,
                                                                                                  os_path_isfile):
        self.assertEquals(
            ("/spam", "/spam/eggs"), self.reactor.verify_project_directory("spam", "eggs"))

        os_path_abspath.assert_called_with("spam")
        os_path_exists.assert_has_calls([call("/spam"), call("/spam/eggs")])
        os_path_isdir.assert_called_with("/spam")
        os_path_join.assert_called_with("/spam", "eggs")
        os_path_isfile.assert_called_with("/spam/eggs")

    @patch("pybuilder.reactor.imp.load_source", side_effect=ImportError("spam"))
    def test_should_raise_when_loading_project_module_and_import_raises_exception(self, imp_load_source):
        self.assertRaises(
            PyBuilderException, self.reactor.load_project_module, "spam")

        imp_load_source.assert_called_with("build", "spam")

    @patch("pybuilder.reactor.imp.load_source", return_value=Mock())
    def test_should_return_module_when_loading_project_module_and_import_raises_exception(self, imp_load_source):
        self.assertTrue(imp_load_source.return_value is self.reactor.load_project_module("spam"))

        imp_load_source.assert_called_with("build", "spam")

    def test_ensure_project_attributes_are_set_when_instantiating_project(self):
        module = ModuleType("mock_module")

        module.version = "version"
        module.default_task = "default_task"
        module.summary = "summary"
        module.home_page = "home_page"
        module.description = "description"
        module.authors = "authors"
        module.license = "license"
        module.url = "url"

        self.reactor.project = Mock()
        self.reactor.project_module = module

        self.reactor.apply_project_attributes()

        self.assertEquals("version", self.reactor.project.version)
        self.assertEquals("default_task", self.reactor.project.default_task)
        self.assertEquals("summary", self.reactor.project.summary)
        self.assertEquals("home_page", self.reactor.project.home_page)
        self.assertEquals("description", self.reactor.project.description)
        self.assertEquals("authors", self.reactor.project.authors)
开发者ID:wenlien,项目名称:pybuilder,代码行数:70,代码来源:reactor_tests.py


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