本文整理匯總了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)
示例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)