當前位置: 首頁>>代碼示例>>Python>>正文


Python Reactor.verify_project_directory方法代碼示例

本文整理匯總了Python中pybuilder.reactor.Reactor.verify_project_directory方法的典型用法代碼示例。如果您正苦於以下問題:Python Reactor.verify_project_directory方法的具體用法?Python Reactor.verify_project_directory怎麽用?Python Reactor.verify_project_directory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pybuilder.reactor.Reactor的用法示例。


在下文中一共展示了Reactor.verify_project_directory方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ReactorTest

# 需要導入模塊: from pybuilder.reactor import Reactor [as 別名]
# 或者: from pybuilder.reactor.Reactor import verify_project_directory [as 別名]

#.........這裏部分代碼省略.........
        module.task = init

        self.reactor.collect_tasks_and_actions_and_initializers(module)

        verify(self.execution_manager).register_initializer(any(Initializer))

    def test_should_collect_single_initializer_with_environments(self):
        def init():
            pass

        setattr(init, INITIALIZER_ATTRIBUTE, True)
        setattr(init, ENVIRONMENTS_ATTRIBUTE, ["any_environment"])

        module = mock()
        module.task = init

        class ExecutionManagerMock(object):
            def register_initializer(self, initializer):
                self.initializer = initializer

        execution_manager_mock = ExecutionManagerMock()
        self.reactor.execution_manager = execution_manager_mock

        self.reactor.collect_tasks_and_actions_and_initializers(module)

        self.assertEquals(
            execution_manager_mock.initializer.environments, ["any_environment"])

    def test_should_raise_exception_when_verifying_project_directory_and_directory_does_not_exist(self):
        when(os.path).abspath("spam").thenReturn("spam")
        when(os.path).exists("spam").thenReturn(False)

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

        verify(os.path).abspath("spam")
        verify(os.path).exists("spam")

    def test_should_raise_exception_when_verifying_project_directory_and_directory_is_not_a_directory(self):
        when(os.path).abspath("spam").thenReturn("spam")
        when(os.path).exists("spam").thenReturn(True)
        when(os.path).isdir("spam").thenReturn(False)

        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")

    def test_should_raise_exception_when_verifying_project_directory_and_build_descriptor_does_not_exist(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(False)

        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")
開發者ID:Ferreiros-lab,項目名稱:pybuilder,代碼行數:69,代碼來源:reactor_tests.py

示例2: ReactorTest

# 需要導入模塊: from pybuilder.reactor import Reactor [as 別名]
# 或者: from pybuilder.reactor.Reactor import verify_project_directory [as 別名]

#.........這裏部分代碼省略.........
                        len(self.execution_manager.register_initializer.call_args[0]) == 1)

    def test_should_collect_single_initializer_with_environments(self):
        def init():
            pass

        setattr(init, INITIALIZER_ATTRIBUTE, True)
        setattr(init, ENVIRONMENTS_ATTRIBUTE, ["any_environment"])

        module = ModuleType("mock_module")
        module.task = init

        class ExecutionManagerMock(object):
            def register_initializer(self, initializer):
                self.initializer = initializer

            def register_late_task_dependencies(self, dependencies):
                pass

        execution_manager_mock = ExecutionManagerMock()
        self.reactor.execution_manager = execution_manager_mock

        self.reactor.collect_tasks_and_actions_and_initializers(module)

        self.assertEquals(
            execution_manager_mock.initializer.environments, ["any_environment"])

    @patch("pybuilder.reactor.os.path.exists", return_value=False)
    @patch("pybuilder.reactor.os.path.abspath", return_value="spam")
    def test_should_raise_when_verifying_project_directory_and_directory_does_not_exist(self,
                                                                                        os_path_abspath,
                                                                                        os_path_exists):
        self.assertRaises(
            PyBuilderException, self.reactor.verify_project_directory, "spam", "eggs")

        os_path_abspath.assert_called_with("spam")
        os_path_exists.assert_called_with("spam")

    @patch("pybuilder.reactor.os.path.isdir", return_value=False)
    @patch("pybuilder.reactor.os.path.exists", return_value=True)
    @patch("pybuilder.reactor.os.path.abspath", return_value="spam")
    def test_should_raise_when_verifying_project_directory_and_directory_is_not_a_directory(self,
                                                                                            os_path_abspath,
                                                                                            os_path_exists,
                                                                                            os_path_isdir):
        self.assertRaises(
            PyBuilderException, self.reactor.verify_project_directory, "spam", "eggs")

        os_path_abspath.assert_called_with("spam")
        os_path_exists.assert_called_with("spam")
        os_path_isdir.assert_called_with("spam")

    @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", side_effect=lambda x: True if x == "spam" else False)
    @patch("pybuilder.reactor.os.path.abspath", return_value="spam")
    def test_should_raise_when_verifying_project_directory_and_build_descriptor_does_not_exist(self,
                                                                                               os_path_abspath,
                                                                                               os_path_exists,
                                                                                               os_path_isdir,
                                                                                               os_path_join):
        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")])
開發者ID:wenlien,項目名稱:pybuilder,代碼行數:70,代碼來源:reactor_tests.py


注:本文中的pybuilder.reactor.Reactor.verify_project_directory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。