本文整理汇总了Python中pybuilder.core.Project.expand_path方法的典型用法代码示例。如果您正苦于以下问题:Python Project.expand_path方法的具体用法?Python Project.expand_path怎么用?Python Project.expand_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybuilder.core.Project
的用法示例。
在下文中一共展示了Project.expand_path方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProjectTest
# 需要导入模块: from pybuilder.core import Project [as 别名]
# 或者: from pybuilder.core.Project import expand_path [as 别名]
class ProjectTest (unittest.TestCase):
def setUp(self):
self.project = Project(basedir="/imaginary", name="Unittest")
def test_should_pick_directory_name_for_project_name_when_name_is_not_given(self):
try:
when(os.path).basename("/imaginary").thenReturn("imaginary")
project = Project(basedir="/imaginary")
self.assertEquals("imaginary", project.name)
verify(os.path).basename("/imaginary")
finally:
unstub()
def test_get_property_should_return_default_value_when_property_is_not_set(self):
self.assertEquals("spam", self.project.get_property("spam", "spam"))
def test_get_property_should_return_property_value_when_property_is_set(self):
self.project.set_property("spam", "eggs")
self.assertEquals("eggs", self.project.get_property("spam", "spam"))
def test_has_property_should_return_false_when_property_is_not_set(self):
self.assertFalse(self.project.has_property("spam"))
def test_has_property_should_return_true_when_property_is_set(self):
self.project.set_property("spam", "eggs")
self.assertTrue(self.project.has_property("spam"))
def test_set_property_if_unset_should_set_property_when_property_is_not_set(self):
self.project.set_property_if_unset("spam", "spam")
self.assertEquals("spam", self.project.get_property("spam"))
def test_set_property_if_unset_should_not_set_property_when_property_is_already_set(self):
self.project.set_property("spam", "eggs")
self.project.set_property_if_unset("spam", "spam")
self.assertEquals("eggs", self.project.get_property("spam"))
def test_expand_should_raise_exception_when_property_is_not_set(self):
self.assertRaises(
MissingPropertyException, self.project.expand, "$spam")
def test_expand_should_return_expanded_string_when_property_is_set(self):
self.project.set_property("spam", "eggs")
self.assertEquals("eggs", self.project.expand("$spam"))
def test_expand_should_return_expanded_string_when_two_properties_are_found_and_set(self):
self.project.set_property("spam", "spam")
self.project.set_property("eggs", "eggs")
self.assertEquals(
"spam and eggs", self.project.expand("$spam and $eggs"))
def test_expand_should_expand_property_with_value_being_an_property_expression(self):
self.project.set_property("spam", "spam")
self.project.set_property("eggs", "$spam")
self.assertEquals("spam", self.project.expand("$eggs"))
def test_expand_should_raise_exception_when_first_expansion_leads_to_property_reference_and_property_is_undefined(self):
self.project.set_property("eggs", "$spam")
self.assertRaises(
MissingPropertyException, self.project.expand, "$eggs")
def test_expand_path_should_return_expanded_path(self):
self.project.set_property("spam", "spam")
self.project.set_property("eggs", "eggs")
self.assertEquals(os.path.join("/imaginary", "spam", "eggs"),
self.project.expand_path("$spam/$eggs"))
def test_expand_path_should_return_expanded_path_and_additional_parts_when_additional_parts_are_given(self):
self.project.set_property("spam", "spam")
self.project.set_property("eggs", "eggs")
self.assertEquals(
os.path.join("/imaginary", "spam", "eggs", "foo", "bar"),
self.project.expand_path("$spam/$eggs", "foo", "bar"))
def test_should_raise_exception_when_getting_mandatory_propert_and_property_is_not_found(self):
self.assertRaises(MissingPropertyException,
self.project.get_mandatory_property, "i_dont_exist")
def test_should_return_property_value_when_getting_mandatory_propert_and_property_exists(self):
self.project.set_property("spam", "spam")
self.assertEquals("spam", self.project.get_mandatory_property("spam"))
def test_should_add_runtime_dependency_with_name_only(self):
self.project.depends_on("spam")
self.assertEquals(1, len(self.project.dependencies))
self.assertEquals("spam", self.project.dependencies[0].name)
self.assertEquals(None, self.project.dependencies[0].version)
def test_should_add_dependency_with_name_and_version(self):
self.project.depends_on("spam", "0.7")
self.assertEquals(1, len(self.project.dependencies))
self.assertEquals("spam", self.project.dependencies[0].name)
self.assertEquals("0.7", self.project.dependencies[0].version)
def test_should_add_dependency_with_name_and_version_only_once(self):
self.project.depends_on("spam", "0.7")
self.project.depends_on("spam", "0.7")
self.assertEquals(1, len(self.project.dependencies))
#.........这里部分代码省略.........
示例2: PdocPluginTests
# 需要导入模块: from pybuilder.core import Project [as 别名]
# 或者: from pybuilder.core.Project import expand_path [as 别名]
class PdocPluginTests(unittest.TestCase):
def setUp(self):
self.logger = Mock()
self.project = Project(".")
self.project.set_property("dir_target", "dir_target_value")
self.project.set_property("dir_source_main_python", "dir_source_main_python_value")
self.project.set_property("dir_reports", "dir_reports_value")
@patch("pybuilder.plugins.python.pdoc_plugin.os.mkdir")
@patch("pybuilder.plugins.python.pdoc_plugin.os.path.exists")
@patch("pybuilder.plugins.python.pdoc_plugin.assert_can_execute")
@patch("pybuilder.plugins.python.pdoc_plugin.execute_command")
def test_pdoc_prepare_works(self, exec_command, assert_can_exec, os_path_exists, os_mkdir):
pdoc_init(self.project)
os_path_exists.return_value = False
pdoc_prepare(self.project, self.logger)
self.assertEquals(os_mkdir.call_count, 1)
os_path_exists.return_value = True
pdoc_prepare(self.project, self.logger)
self.assertEquals(os_mkdir.call_count, 1)
self.assertEquals(assert_can_exec.call_count, 2)
@patch("pybuilder.plugins.python.pdoc_plugin.os.mkdir")
@patch("pybuilder.plugins.python.pdoc_plugin.os.path.exists")
@patch("pybuilder.plugins.python.pdoc_plugin.assert_can_execute")
@patch("pybuilder.plugins.python.pdoc_plugin.execute_command")
def test_pdoc_requires_module_name(self, exec_command, assert_can_exec, os_path_exists, os_mkdir):
pdoc_init(self.project)
self.assertRaises(BuildFailedException, pdoc_compile_docs, self.project, self.logger)
@patch("pybuilder.plugins.python.pdoc_plugin.os.mkdir")
@patch("pybuilder.plugins.python.pdoc_plugin.os.path.exists")
@patch("pybuilder.plugins.python.pdoc_plugin.assert_can_execute")
@patch("pybuilder.plugins.python.pdoc_plugin.execute_command")
def test_pdoc_html_adds_html_dir(self, exec_command, assert_can_exec, os_path_exists, os_mkdir):
pdoc_init(self.project)
self.project.set_property("pdoc_module_name", "pdoc_module_name_value")
self.project.set_property("pdoc_command_args", [])
pdoc_compile_docs(self.project, self.logger)
exec_command.assert_called_with(['pdoc', "pdoc_module_name_value"],
cwd=self.project.expand_path("$dir_target", "pdocs"),
env={
'PYTHONPATH': self.project.expand_path("$dir_source_main_python"),
'PATH': os.environ['PATH']
},
outfile_name=self.project.expand_path('$dir_reports', 'pdoc'))
self.project.set_property("pdoc_command_args", ["--html"])
pdoc_compile_docs(self.project, self.logger)
exec_command.assert_called_with(['pdoc', "--html", "--html-dir",
self.project.expand_path('$dir_target', 'pdocs'),
"pdoc_module_name_value"],
cwd=self.project.expand_path("$dir_target", "pdocs"),
env={
'PYTHONPATH': self.project.expand_path("$dir_source_main_python"),
'PATH': os.environ['PATH']
},
outfile_name=self.project.expand_path('$dir_reports', 'pdoc')
)