本文整理汇总了Python中pybuilder.core.Project类的典型用法代码示例。如果您正苦于以下问题:Python Project类的具体用法?Python Project怎么用?Python Project使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Project类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_should_write_pycharm_file
def test_should_write_pycharm_file(self, os, mock_open):
project = Project('basedir', name='pybuilder')
project.set_property('dir_source_main_python', 'src/main/python')
mock_open.return_value = MagicMock(spec=TYPE_FILE)
os.path.join.side_effect = lambda first, second: first + '/' + second
pycharm_generate(project, Mock())
mock_open.assert_called_with('basedir/.idea/pybuilder.iml', 'w')
metadata_file = mock_open.return_value.__enter__.return_value
metadata_file.write.assert_called_with("""<?xml version="1.0" encoding="UTF-8"?>
<!-- This file has been generated by the PyBuilder PyCharm Plugin -->
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/python" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="myDocStringFormat" value="Plain" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="Unittests" />
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
""")
示例2: RunSonarAnalysisTest
class RunSonarAnalysisTest(TestCase):
def setUp(self):
self.project = Project("any-project")
self.project.version = "0.0.1"
self.project.set_property("sonarqube_project_key", "project_key")
self.project.set_property("sonarqube_project_name", "project_name")
self.project.set_property("dir_source_main_python", "src/main/python")
self.project.set_property("dir_target", "target")
self.project.set_property("dir_reports", "target/reports")
def test_should_build_sonar_runner_for_project(self):
self.assertEqual(
build_sonar_runner(self.project).as_string,
"sonar-runner -Dsonar.projectKey=project_key "
"-Dsonar.projectName=project_name "
"-Dsonar.projectVersion=0.0.1 "
"-Dsonar.sources=src/main/python "
"-Dsonar.python.coverage.reportPath=target/reports/coverage*.xml")
@patch("pybuilder.plugins.python.sonarqube_plugin.SonarCommandBuilder.run")
def test_should_break_build_when_sonar_runner_fails(self, run_sonar_command):
run_sonar_command.return_value = Mock(exit_code=1)
self.assertRaises(BuildFailedException, run_sonar_analysis, self.project, Mock())
@patch("pybuilder.plugins.python.sonarqube_plugin.SonarCommandBuilder.run")
def test_should_not_break_build_when_sonar_runner_succeeds(self, run_sonar_command):
run_sonar_command.return_value = Mock(exit_code=0)
run_sonar_analysis(self.project, Mock())
示例3: ProjectPackageDataTests
class ProjectPackageDataTests(unittest.TestCase):
def setUp(self):
self.project = Project(basedir="/imaginary", name="Unittest")
def test_should_raise_exception_when_package_name_not_given(self):
self.assertRaises(ValueError, self.project.include_file, None, "spam")
def test_should_raise_exception_when_filename_not_given(self):
self.assertRaises(
ValueError, self.project.include_file, "my_package", None)
def test_should_raise_exception_when_package_name_is_empty_string(self):
self.assertRaises(
ValueError, self.project.include_file, " \n", "spam")
def test_should_raise_exception_when_filename_is_empty_string(self):
self.assertRaises(
ValueError, self.project.include_file, "eggs", "\t \n")
def test_should_raise_exception_when_package_path_not_given(self):
self.assertRaises(ValueError, self.project.include_directory, None, "spam")
def test_should_raise_exception_when_package_path_is_empty_string(self):
self.assertRaises(ValueError, self.project.include_directory, "\t \n", "spam")
def test_should_raise_exception_when_patterns_list_not_given(self):
self.assertRaises(ValueError, self.project.include_directory, "spam", None)
def test_should_raise_exception_when_patterns_list_is_empty_list(self):
self.assertRaises(ValueError, self.project.include_directory, "spam", ["\t \n"])
def test_should_package_data_dictionary_is_empty(self):
self.assertEquals({}, self.project.package_data)
def test_should_add_filename_to_list_of_included_files_for_package_spam(self):
self.project.include_file("spam", "eggs")
self.assertEquals({"spam": ["eggs"]}, self.project.package_data)
def test_should_add_two_filenames_to_list_of_included_files_for_package_spam(self):
self.project.include_file("spam", "eggs")
self.project.include_file("spam", "ham")
self.assertEquals({"spam": ["eggs", "ham"]}, self.project.package_data)
def test_should_add_two_filenames_to_list_of_included_files_for_two_different_packages(self):
self.project.include_file("spam", "eggs")
self.project.include_file("monty", "ham")
self.assertEquals(
{"monty": ["ham"], "spam": ["eggs"]}, self.project.package_data)
def test_should_add_two_filenames_to_list_of_included_files_and_to_manifest(self):
self.project.include_file("spam", "eggs")
self.project.include_file("monty", "ham")
self.assertEquals(
{"monty": ["ham"], "spam": ["eggs"]}, self.project.package_data)
self.assertEquals(
["spam/eggs", "monty/ham"], self.project.manifest_included_files)
示例4: test_should_break_build_when_warnings_and_set
def test_should_break_build_when_warnings_and_set(self, execute_tool, warnings):
project = Project(".")
init_pylint(project)
project.set_property("pylint_break_build", True)
with self.assertRaises(BuildFailedException):
execute_pylint(project, Mock(Logger))
示例5: PythonPathTests
class PythonPathTests(TestCase):
def setUp(self):
self.project = Project('/path/to/project')
self.project.set_property('dir_source_unittest_python', 'unittest')
self.project.set_property('dir_source_main_python', 'src')
def test_should_register_source_paths(self):
system_path = ['some/python/path']
_register_test_and_source_path_and_return_test_dir(self.project, system_path)
self.assertTrue('/path/to/project/unittest' in system_path)
self.assertTrue('/path/to/project/src' in system_path)
def test_should_put_project_sources_before_other_sources(self):
system_path = ['irrelevant/sources']
_register_test_and_source_path_and_return_test_dir(self.project, system_path)
test_sources_index_in_path = system_path.index('/path/to/project/unittest')
main_sources_index_in_path = system_path.index('/path/to/project/src')
irrelevant_sources_index_in_path = system_path.index('irrelevant/sources')
self.assertTrue(test_sources_index_in_path < irrelevant_sources_index_in_path and
main_sources_index_in_path < irrelevant_sources_index_in_path)
示例6: test_initialize_sets_variables_correctly
def test_initialize_sets_variables_correctly(self):
project = Project(".")
initialize_plugin(project)
self.assertEqual(project.get_property("lambda_file_access_control"), "bucket-owner-full-control")
self.assertEqual(project.get_property("bucket_prefix"), "")
self.assertEqual(project.get_property("template_file_access_control"), "bucket-owner-full-control")
self.assertEqual(project.get_property("template_key_prefix"), "")
示例7: SonarCommandBuilderTests
class SonarCommandBuilderTests(TestCase):
def setUp(self):
self.project = Project("any-project")
self.project.set_property("any-property-name", "any-property-value")
self.sonar_builder = SonarCommandBuilder("sonar", self.project)
def test_should_set_sonar_key_to_specific_value(self):
self.sonar_builder.set_sonar_key("anySonarKey").to("anyValue")
self.assertEqual(
self.sonar_builder.as_string,
"sonar -DanySonarKey=anyValue")
def test_should_set_sonar_key_to_two_specific_values(self):
self.sonar_builder.set_sonar_key("anySonarKey").to("anyValue").set_sonar_key("other").to("otherValue")
self.assertEqual(
self.sonar_builder.as_string,
"sonar -DanySonarKey=anyValue -Dother=otherValue")
def test_should_set_sonar_key_to_property_value(self):
self.sonar_builder.set_sonar_key("anySonarKey").to_property_value("any-property-name")
self.assertEqual(self.sonar_builder.as_string, "sonar -DanySonarKey=any-property-value")
示例8: PythonPathTests
class PythonPathTests(TestCase):
def setUp(self):
self.project = Project("/path/to/project")
self.project.set_property("dir_source_unittest_python", "unittest")
self.project.set_property("dir_source_main_python", "src")
def test_should_register_source_paths(self):
system_path = ["some/python/path"]
_register_test_and_source_path_and_return_test_dir(self.project, system_path)
self.assertTrue("/path/to/project/unittest" in system_path)
self.assertTrue("/path/to/project/src" in system_path)
def test_should_put_project_sources_before_other_sources(self):
system_path = ["irrelevant/sources"]
_register_test_and_source_path_and_return_test_dir(self.project, system_path)
test_sources_index_in_path = system_path.index("/path/to/project/unittest")
main_sources_index_in_path = system_path.index("/path/to/project/src")
irrelevant_sources_index_in_path = system_path.index("irrelevant/sources")
self.assertTrue(
test_sources_index_in_path < irrelevant_sources_index_in_path
and main_sources_index_in_path < irrelevant_sources_index_in_path
)
示例9: InstallBuildDependenciesTest
class InstallBuildDependenciesTest(unittest.TestCase):
def setUp(self):
self.project = Project("unittest", ".")
self.project.set_property("dir_install_logs", "any_directory")
self.logger = mock(Logger)
when(
pybuilder.plugins.python.install_dependencies_plugin).execute_command(any_value(), any_value(),
shell=True).thenReturn(0)
def tearDown(self):
unstub()
def test_should_install_multiple_dependencies(self):
self.project.build_depends_on("spam")
self.project.build_depends_on("eggs")
install_build_dependencies(self.logger, self.project)
verify(
pybuilder.plugins.python.install_dependencies_plugin).execute_command("pip install 'spam'",
any_value(), shell=True)
verify(
pybuilder.plugins.python.install_dependencies_plugin).execute_command("pip install 'eggs'",
any_value(), shell=True)
示例10: test_should_run_pylint_with_custom_options
def test_should_run_pylint_with_custom_options(self, execute_tool):
project = Project(".")
init_pylint(project)
project.set_property("pylint_options", ["--test", "-f", "--x=y"])
execute_pylint(project, Mock(Logger))
execute_tool.assert_called_with(project, "pylint", ["pylint", "--test", "-f", "--x=y"], True)
示例11: test_should_delegate_to_project_get_property_when_attribute_is_not_defined
def test_should_delegate_to_project_get_property_when_attribute_is_not_defined(self):
project_mock = Project(".")
project_mock.has_property = Mock(return_value=True)
project_mock.get_property = Mock(return_value="eggs")
self.assertEquals("eggs", ProjectDictWrapper(project_mock, Mock())["spam"])
project_mock.get_property.assert_called_with("spam")
示例12: test_find_files
def test_find_files(self, discover_mock):
project = Project('.')
project.set_property('dir_source_cmdlinetest', '/any/dir')
project.set_property('cram_test_file_glob', '*.t')
expected = ['/any/dir/test.cram']
discover_mock.return_value = expected
received = _find_files(project)
self.assertEquals(expected, received)
discover_mock.assert_called_once_with('/any/dir', '*.t')
示例13: test_running_plugin_failure_no_tests
def test_running_plugin_failure_no_tests(self,
execute_mock,
read_file_mock,
os_mock,
report_mock,
find_files_mock,
command_mock
):
project = Project('.')
project.set_property('verbose', True)
project.set_property('dir_source_main_python', 'python')
project.set_property('dir_source_main_scripts', 'scripts')
project.set_property("cram_fail_if_no_tests", True)
logger = Mock()
command_mock.return_value = ['cram']
find_files_mock.return_value = []
report_mock.return_value = 'report_file'
os_mock.copy.return_value = {}
read_file_mock.return_value = ['test failes for file', '# results']
execute_mock.return_value = 1
self.assertRaises(
BuildFailedException, run_cram_tests, project, logger)
execute_mock.assert_not_called()
expected_info_calls = [call('Running Cram command line tests'),
]
self.assertEquals(expected_info_calls, logger.info.call_args_list)
示例14: test_running_plugin_cram_from_target
def test_running_plugin_cram_from_target(self,
execute_mock,
read_file_mock,
os_mock,
report_mock,
find_files_mock,
command_mock
):
project = Project('.')
project.set_property('cram_run_test_from_target', True)
project.set_property('dir_dist', 'python')
project.set_property('dir_dist_scripts', 'scripts')
project.set_property('verbose', False)
logger = Mock()
command_mock.return_value = ['cram']
find_files_mock.return_value = ['test1.cram', 'test2.cram']
report_mock.return_value = 'report_file'
os_mock.copy.return_value = {}
read_file_mock.return_value = ['test failes for file', '# results']
execute_mock.return_value = 0
run_cram_tests(project, logger)
execute_mock.assert_called_once_with(
['cram', 'test1.cram', 'test2.cram'], 'report_file',
error_file_name='report_file',
env={'PYTHONPATH': './python:', 'PATH': './python/scripts:'}
)
expected_info_calls = [call('Running Cram command line tests'),
call('Cram tests were fine'),
call('results'),
]
self.assertEquals(expected_info_calls, logger.info.call_args_list)
示例15: test_should_run_pytddmon
def test_should_run_pytddmon(self, subprocess):
subprocess.check_output.side_effect = lambda *args, **kwargs: ' '.join(a for a in args)
project = Project('/path/to/project', name='pybuilder')
project.set_property('dir_source_main_python', 'path/to/source')
project.set_property(
'dir_source_unittest_python', 'src/unittest/python')
pytddmon_plugin.pytddmon(project, Mock())
subprocess.Popen.assert_called_with(
['which python', 'which pytddmon.py', '--no-pulse'], shell=False, cwd='src/unittest/python', env=ANY)