def test_ensure_project_properties_are_logged_when_calling_log_project_properties(self): project = Project("spam") project.set_property("spam", "spam") project.set_property("eggs", "eggs") self.reactor.project = project self.reactor.log_project_properties() verify(self.logger).debug("Project properties: %s", contains("basedir : spam")) verify(self.logger).debug("Project properties: %s", contains("eggs : eggs")) verify(self.logger).debug("Project properties: %s", contains("spam : spam"))
class InitPythonDirectoriesTest (unittest.TestCase): def setUp(self): self.project = Project(".") def test_should_set_python_sources_property(self): init_python_directories(self.project) self.assertEquals("src/main/python", self.project.get_property(PYTHON_SOURCES_PROPERTY, "caboom")) def test_should_set_scripts_sources_property(self): init_python_directories(self.project) self.assertEquals("src/main/scripts", self.project.get_property(SCRIPTS_SOURCES_PROPERTY, "caboom")) def test_should_set_dist_scripts_property(self): init_python_directories(self.project) self.assertEquals(None, self.project.get_property(SCRIPTS_TARGET_PROPERTY, "caboom")) def test_should_set_dist_property(self): init_python_directories(self.project) self.assertEquals("$dir_target/dist/.-1.0-SNAPSHOT", self.project.get_property(DISTRIBUTION_PROPERTY, "caboom"))
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_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)
class InstallRuntimeDependenciesTest(unittest.TestCase): def setUp(self): self.project = Project("unittest", ".") self.project.set_property("dir_install_logs", "any_directory") self.logger = mock(Logger) when(pythonbuilder.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.depends_on("spam") self.project.depends_on("eggs") install_runtime_dependencies(self.logger, self.project) verify(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command("pip install spam", any_value() , shell=True) verify(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command("pip install eggs", any_value() , shell=True)
class ProjectManifestTests (unittest.TestCase): def setUp (self): self.project = Project(basedir="/imaginary", name="Unittest") def test_should_raise_exception_when_given_glob_pattern_is_none (self): self.assertRaises(ValueError, self.project._manifest_include, None) def test_should_raise_exception_when_given_glob_pattern_is_empty_string (self): self.assertRaises(ValueError, self.project._manifest_include, " \n") def test_should_add_filename_to_list_of_included_files (self): self.project._manifest_include("spam") self.assertEquals(["spam"], self.project.manifest_included_files) def test_should_add_filenames_in_correct_order_to_list_of_included_files (self): self.project._manifest_include("spam") self.project._manifest_include("egg") self.project._manifest_include("yadt") self.assertEquals(["spam", "egg", "yadt"], self.project.manifest_included_files)
def prepare_build(self, property_overrides={}, project_directory=".", project_descriptor="build.py"): Reactor._current_instance = self project_directory, project_descriptor =\ self.verify_project_directory(project_directory, project_descriptor) self.logger.debug("Loading project module from %s", project_descriptor) self.project = Project(basedir=project_directory) self.project_module = self.load_project_module(project_descriptor) self.apply_project_attributes() self.override_properties(property_overrides) self.logger.debug("Have loaded plugins %s", ", ".join(self._plugins)) self.collect_tasks_and_actions_and_initializers(self.project_module) self.execution_manager.resolve_dependencies()
class DependencyLinksTest(unittest.TestCase): def setUp(self): self.project = Project(".") def test_should_return_empty_string_when_no_link_dependency_is_given(self): self.assertEqual("", build_dependency_links_string(self.project)) def test_should_return_dependency_link(self): self.project.depends_on("pyassert", url="https://github.com/downloads/halimath/pyassert/pyassert-0.2.2.tar.gz") self.assertEqual( 'dependency_links = [ "https://github.com/downloads/halimath/pyassert/pyassert-0.2.2.tar.gz" ],',\ build_dependency_links_string(self.project)) def test_should_return_dependency_links(self): self.project.depends_on("pyassert1", url="https://github.com/downloads/halimath/pyassert/pyassert1-0.2.2.tar.gz") self.project.depends_on("pyassert2", url="https://github.com/downloads/halimath/pyassert/pyassert2-0.2.2.tar.gz") self.assertEqual( 'dependency_links = [ "https://github.com/downloads/halimath/pyassert/pyassert1-0.2.2.tar.gz", "https://github.com/downloads/halimath/pyassert/pyassert2-0.2.2.tar.gz" ],' ,\ build_dependency_links_string(self.project))
def setUp(self): self.project = Project("unittest", ".") self.project.set_property("dir_install_logs", "any_directory") self.logger = mock(Logger) when(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command(any_value(), any_value(), shell=True).thenReturn(0)
class Reactor(object): _current_instance = None @staticmethod def current_instance(): return Reactor._current_instance def __init__(self, logger, execution_manager, plugin_loader=None): self.logger = logger self.execution_manager = execution_manager if not plugin_loader: self.plugin_loader = BuiltinPluginLoader(self.logger) else: self.plugin_loader = plugin_loader self._plugins = [] self.project = None def require_plugin(self, plugin): if plugin not in self._plugins: try: self._plugins.append(plugin) self.import_plugin(plugin) except: self._plugins.remove(plugin) raise def get_plugins(self): return self._plugins def get_tasks(self): return self.execution_manager.tasks def validate_project(self): validation_messages = self.project.validate() if len(validation_messages) > 0: raise ProjectValidationFailedException(validation_messages) def prepare_build(self, property_overrides={}, project_directory=".", project_descriptor="build.py"): Reactor._current_instance = self project_directory, project_descriptor =\ self.verify_project_directory(project_directory, project_descriptor) self.logger.debug("Loading project module from %s", project_descriptor) self.project = Project(basedir=project_directory) self.project_module = self.load_project_module(project_descriptor) self.apply_project_attributes() self.override_properties(property_overrides) self.logger.debug("Have loaded plugins %s", ", ".join(self._plugins)) self.collect_tasks_and_actions_and_initializers(self.project_module) self.execution_manager.resolve_dependencies() def build(self, tasks=[], environments=[]): Reactor._current_instance = self if environments: self.logger.info("Activated environments: %s", ", ".join(environments)) self.execution_manager.execute_initializers(environments, logger=self.logger, project=self.project) self.log_project_properties() self.validate_project() tasks = as_list(tasks) if not len(tasks): if self.project.default_task: tasks += as_list(self.project.default_task) else: raise PythonbuilderException("No default task given.") execution_plan = self.execution_manager.build_execution_plan(tasks) self.logger.debug("Execution plan is %s", ", ".join([task.name for task in execution_plan])) self.logger.info("Building %s version %s", self.project.name, self.project.version) self.logger.info("Executing build in %s", self.project.basedir) self.logger.info("Going to execute task%s %s", "s" if len(tasks) != 1 else "", ", ".join(tasks)) task_execution_summaries =\ self.execution_manager.execute_execution_plan(execution_plan, logger=self.logger, project=self.project, reactor=self) return BuildSummary(self.project, task_execution_summaries) def execute_task(self, task_name): execution_plan = self.execution_manager.build_execution_plan(task_name) self.execution_manager.execute_execution_plan(execution_plan, logger=self.logger, project=self.project, reactor=self) def override_properties(self, property_overrides): for property_override in property_overrides: self.project.set_property(property_override, property_overrides[property_override]) def log_project_properties(self): formatted = "" for key in sorted(self.project.properties): formatted += "\n%40s : %s" % (key, self.project.get_property(key)) self.logger.debug("Project properties: %s", formatted) def import_plugin(self, plugin): self.logger.debug("Loading plugin '%s'", plugin) plugin_module = self.plugin_loader.load_plugin(self.project, plugin) self.collect_tasks_and_actions_and_initializers(plugin_module) def collect_tasks_and_actions_and_initializers(self, project_module): for name in dir(project_module): candidate = getattr(project_module, name) if hasattr(candidate, NAME_ATTRIBUTE): name = getattr(candidate, NAME_ATTRIBUTE) elif hasattr(candidate, "__name__"): name = candidate.__name__ description = getattr(candidate, DESCRIPTION_ATTRIBUTE) if hasattr(candidate, DESCRIPTION_ATTRIBUTE) else "" if hasattr(candidate, TASK_ATTRIBUTE) and getattr(candidate, TASK_ATTRIBUTE): dependencies = getattr(candidate, DEPENDS_ATTRIBUTE) if hasattr(candidate, DEPENDS_ATTRIBUTE) else None self.logger.debug("Found task %s", name) self.execution_manager.register_task(Task(name, candidate, dependencies, description)) elif hasattr(candidate, ACTION_ATTRIBUTE) and getattr(candidate, ACTION_ATTRIBUTE): before = getattr(candidate, BEFORE_ATTRIBUTE) if hasattr(candidate, BEFORE_ATTRIBUTE) else None after = getattr(candidate, AFTER_ATTRIBUTE) if hasattr(candidate, AFTER_ATTRIBUTE) else None only_once = getattr(candidate, ONLY_ONCE_ATTRIBUTE) if hasattr(candidate, ONLY_ONCE_ATTRIBUTE) else False self.logger.debug("Found action %s", name) self.execution_manager.register_action(Action(name, candidate, before, after, description, only_once)) elif hasattr(candidate, INITIALIZER_ATTRIBUTE) and getattr(candidate, INITIALIZER_ATTRIBUTE): environments = [] if hasattr(candidate, ENVIRONMENTS_ATTRIBUTE): environments = getattr(candidate, ENVIRONMENTS_ATTRIBUTE) self.execution_manager.register_initializer(Initializer(name, candidate, environments, description)) def apply_project_attributes(self): self.propagate_property("name") self.propagate_property("version") self.propagate_property("default_task") self.propagate_property("summary") self.propagate_property("home_page") self.propagate_property("description") self.propagate_property("authors") self.propagate_property("license") self.propagate_property("url") def propagate_property(self, property): if hasattr(self.project_module, property): value = getattr(self.project_module, property) setattr(self.project, property, value) def load_project_module(self, project_descriptor): try: return imp.load_source("build", project_descriptor) except ImportError as e: raise PythonbuilderException("Error importing project descriptor %s: %s" % (project_descriptor, e)) def verify_project_directory(self, project_directory, project_descriptor): project_directory = os.path.abspath(project_directory) if not os.path.exists(project_directory): raise PythonbuilderException("Project directory does not exist: %s", project_directory) if not os.path.isdir(project_directory): raise PythonbuilderException("Project directory is not a directory: %s", project_directory) project_descriptor_full_path = os.path.join(project_directory, project_descriptor) if not os.path.exists(project_descriptor_full_path): raise PythonbuilderException("Project directory does not contain descriptor file: %s", project_descriptor_full_path) if not os.path.isfile(project_descriptor_full_path): raise PythonbuilderException("Project descriptor is not a file: %s", project_descriptor_full_path) return project_directory, project_descriptor_full_path
def setUp (self): self.project = Project(basedir="/imaginary", name="Unittest")
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)) self.assertEquals("spam", self.project.dependencies[0].name) self.assertEquals("0.7", self.project.dependencies[0].version)
class ProjectValidationTest (unittest.TestCase): def setUp (self): self.project = Project(basedir="/imaginary", name="Unittest") def test_should_validate_empty_project (self): validation_messages = self.project.validate() assert_that(validation_messages).is_empty() def test_should_not_validate_project_with_duplicate_dependency_but_different_versions (self): self.project.depends_on('spam', version='1') self.project.depends_on('spam', version='2') validation_messages = self.project.validate() assert_that(validation_messages).contains("Runtime dependency 'spam' has been defined multiple times.") def test_should_not_validate_project_with_duplicate_dependency_when_version_is_given_for_one (self): self.project.depends_on('spam') self.project.depends_on('spam', version='2') validation_messages = self.project.validate() assert_that(validation_messages).contains("Runtime dependency 'spam' has been defined multiple times.") def test_should_not_validate_project_with_duplicate_dependency_when_urls_are_different (self): self.project.depends_on('spam', url='y') self.project.depends_on('spam', url='x') validation_messages = self.project.validate() assert_that(validation_messages).contains("Runtime dependency 'spam' has been defined multiple times.") def test_should_not_validate_project_with_duplicate_dependency_when_url_is_given_for_one (self): self.project.depends_on('spam') self.project.depends_on('spam', url='x') validation_messages = self.project.validate() assert_that(validation_messages).contains("Runtime dependency 'spam' has been defined multiple times.") def test_should_not_validate_project_with_duplicate_dependency_for_more_than_two_times (self): self.project.depends_on('spam', version='1') self.project.depends_on('spam', version='2') self.project.depends_on('spam', version='3') validation_messages = self.project.validate() assert_that(validation_messages).contains("Runtime dependency 'spam' has been defined multiple times.") assert_that(len(validation_messages)).equals(1) def test_should_not_validate_project_with_duplicate_build_dependency_but_different_versions (self): self.project.build_depends_on('spam', version='1') self.project.build_depends_on('spam', version='2') validation_messages = self.project.validate() assert_that(validation_messages).contains("Build dependency 'spam' has been defined multiple times.") def test_should_not_validate_project_with_duplicate_build_dependency_when_version_is_given_for_one (self): self.project.build_depends_on('spam') self.project.build_depends_on('spam', version='2') validation_messages = self.project.validate() assert_that(validation_messages).contains("Build dependency 'spam' has been defined multiple times.") def test_should_not_validate_project_with_duplicate_build_dependency_when_urls_are_different (self): self.project.build_depends_on('spam', url='y') self.project.build_depends_on('spam', url='x') validation_messages = self.project.validate() assert_that(validation_messages).contains("Build dependency 'spam' has been defined multiple times.") def test_should_not_validate_project_with_duplicate_build_dependency_when_url_is_given_for_one (self): self.project.build_depends_on('spam') self.project.build_depends_on('spam', url='x') validation_messages = self.project.validate() assert_that(validation_messages).contains("Build dependency 'spam' has been defined multiple times.") def test_should_not_validate_project_with_duplicate_build_dependency_for_more_than_two_times (self): self.project.build_depends_on('spam', version='1') self.project.build_depends_on('spam', version='2') self.project.build_depends_on('spam', version='3') validation_messages = self.project.validate() assert_that(validation_messages).contains("Build dependency 'spam' has been defined multiple times.") assert_that(len(validation_messages)).equals(1) def test_should_not_validate_project_with_runtime_dependency_being_also_given_as_build_dependency (self): self.project.depends_on('spam') self.project.build_depends_on('spam') validation_messages = self.project.validate() assert_that(validation_messages).contains("Runtime dependency 'spam' has also been given as build dependency.") assert_that(len(validation_messages)).equals(1)
class ProjectDataFilesTests (unittest.TestCase): def setUp (self): self.project = Project(basedir="/imaginary", name="Unittest") def test_should_return_empty_list_for_property_files_to_install (self): self.assertEquals([], self.project.files_to_install) def test_should_return_file_to_install (self): self.project.install_file("destination", "filename") self.assertEquals([("destination", ["filename"])], self.project.files_to_install) def test_should_raise_exception_when_no_destination_given (self): self.assertRaises(ValueError, self.project.install_file, None, "Hello world.") def test_should_raise_exception_when_no_filename_given (self): self.assertRaises(ValueError, self.project.install_file, "destination", None) def test_should_raise_exception_when_filename_empty (self): self.assertRaises(ValueError, self.project.install_file, "destination", "\t \n") def test_should_return_files_to_install_into_same_destination (self): self.project.install_file("destination", "filename1") self.project.install_file("destination", "filename2") self.assertEquals([("destination", ["filename1", "filename2"])], self.project.files_to_install) def test_should_return_files_to_install_into_different_destinations (self): self.project.install_file("destination_a", "filename_a_1") self.project.install_file("destination_a", "filename_a_2") self.project.install_file("destination_b", "filename_b") self.assertEquals([("destination_a", ["filename_a_1", "filename_a_2"]), ("destination_b", ["filename_b"])], self.project.files_to_install) def test_should_return_files_to_install_into_different_destinations_and_add_them_to_manifest (self): self.project.install_file("destination_a", "somepackage1/filename1") self.project.install_file("destination_a", "somepackage2/filename2") self.project.install_file("destination_b", "somepackage3/filename3") self.assertEquals([("destination_a", ["somepackage1/filename1", "somepackage2/filename2"]), ("destination_b", ["somepackage3/filename3"])], self.project.files_to_install) self.assertEquals(["somepackage1/filename1", "somepackage2/filename2", "somepackage3/filename3"], self.project.manifest_included_files)
def create_project(): project = Project("/") project.build_depends_on("testingframework") project.depends_on("sometool") project.depends_on("pyassert", url="https://github.com/downloads/halimath/pyassert/pyassert-0.2.2.tar.gz") project.name = "Spam and Eggs" project.version = "1.2.3" project.summary = "This is a simple integration-test for distutils plugin." project.description = "As you might have guessed we have nothing to say here." project.authors = [Author("Udo Juettner", "*****@*****.**"), Author("Michael Gruber", "*****@*****.**")] project.license = "WTFPL" project.url = "http://github.com/pybuilder/pybuilder" def return_dummy_list(): return ["spam", "eggs"] project.list_scripts = return_dummy_list project.list_packages = return_dummy_list project.set_property("distutils_classifiers", ["Development Status :: 5 - Beta", "Environment :: Console"]) project.install_file("dir", "file1") project.install_file("dir", "file2") project.include_file("spam", "eggs") return project
class InstallDependenciesTest(unittest.TestCase): def setUp(self): self.project = Project(".") def test_should_return_empty_string_when_no_dependency_is_given(self): self.assertEqual("", build_install_dependencies_string(self.project)) def test_should_return_single_dependency_string(self): self.project.depends_on("spam") self.assertEqual('install_requires = [ "spam" ],', build_install_dependencies_string(self.project)) def test_should_return_single_dependency_string_with_version(self): self.project.depends_on("spam", "0.7") self.assertEqual('install_requires = [ "spam>=0.7" ],', build_install_dependencies_string(self.project)) def test_should_return_multiple_dependencies_string_with_versions(self): self.project.depends_on("spam", "0.7") self.project.depends_on("eggs") self.assertEqual('install_requires = [ "eggs", "spam>=0.7" ],', build_install_dependencies_string(self.project)) def test_should_not_insert_url_dependency_into_install_requires(self): self.project.depends_on("spam") self.project.depends_on("pyassert", url="https://github.com/downloads/halimath/pyassert/pyassert-0.2.2.tar.gz") self.assertEqual('install_requires = [ "spam" ],', build_install_dependencies_string(self.project)) def test_should_not_insert_default_version_operator_when_project_contains_operator_in_version(self): self.project.depends_on("spam", "==0.7") self.assertEqual('install_requires = [ "spam==0.7" ],', build_install_dependencies_string(self.project))
class BuildPackageDataStringTest(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) self.project = Project('.') def test_should_return_empty_package_data_string_when_no_files_to_include_given(self): self.assertEqual('', build_package_data_string(self.project)) def test_should_return_package_data_string_when_including_file(self): self.project.include_file("spam", "egg") self.assertEqual("package_data = {'spam': ['egg']},", build_package_data_string(self.project)) def test_should_return_package_data_string_when_including_three_files(self): self.project.include_file("spam", "egg") self.project.include_file("ham", "eggs") self.project.include_file("monty", "python") self.assertEqual("package_data = {'ham': ['eggs'], 'monty': ['python'], "\ "'spam': ['egg']},", build_package_data_string(self.project)) def test_should_return_package_data_string_with_keys_in_alphabetical_order(self): self.project.include_file("b", "beta") self.project.include_file("m", "Mu") self.project.include_file("e", "epsilon") self.project.include_file("k", "Kappa") self.project.include_file("p", "psi") self.project.include_file("z", "Zeta") self.project.include_file("i", "Iota") self.project.include_file("a", "alpha") self.project.include_file("d", "delta") self.project.include_file("t", "theta") self.project.include_file("l", "lambda") self.project.include_file("x", "chi") self.assertEqual("package_data = {'a': ['alpha'], 'b': ['beta'], 'd': ['delta'], "\ "'e': ['epsilon'], 'i': ['Iota'], 'k': ['Kappa'], 'l': ['lambda'], "\ "'m': ['Mu'], 'p': ['psi'], 't': ['theta'], 'x': ['chi'], "\ "'z': ['Zeta']},", build_package_data_string(self.project))
class InstallDependencyTest(unittest.TestCase): def setUp(self): self.project = Project("unittest", ".") self.project.set_property("dir_install_logs", "any_directory") self.logger = mock(Logger) when(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command(any_value(), any_value(), shell=True).thenReturn(0) def tearDown(self): unstub() def test_should_install_dependency_without_version(self): dependency = Dependency("spam") install_dependency(self.logger, self.project, dependency) verify(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command("pip install spam", any_value() , shell=True) def test_should_install_dependency_using_custom_index_url(self): self.project.set_property("install_dependencies_index_url", "some_index_url") dependency = Dependency("spam") install_dependency(self.logger, self.project, dependency) verify(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command( "pip install --index-url some_index_url spam", any_value() , shell=True) def test_should_not_use_extra_index_url_when_index_url_is_not_set(self): self.project.set_property("install_dependencies_extra_index_url", "some_index_url") dependency = Dependency("spam") install_dependency(self.logger, self.project, dependency) verify(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command( "pip install spam", any_value() , shell=True) def test_should_not_use_index_and_extra_index_url_when_index_and_extra_index_url_are_set(self): self.project.set_property("install_dependencies_index_url", "some_index_url") self.project.set_property("install_dependencies_extra_index_url", "some_extra_index_url") dependency = Dependency("spam") install_dependency(self.logger, self.project, dependency) verify(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command( "pip install --index-url some_index_url --extra-index-url some_extra_index_url spam", any_value() , shell=True) def test_should_use_mirrors_to_install_dependency(self): self.project.set_property("install_dependencies_use_mirrors", True) dependency = Dependency("spam") install_dependency(self.logger, self.project, dependency) verify(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command( "pip install --use-mirrors spam", any_value() , shell=True) def test_should_upgrade_dependencies(self): self.project.set_property("install_dependencies_upgrade", True) dependency = Dependency("spam") install_dependency(self.logger, self.project, dependency) verify(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command( "pip install --upgrade spam", any_value() , shell=True) def test_should_install_dependency_with_version(self): dependency = Dependency("spam", "0.1.2") install_dependency(self.logger, self.project, dependency) verify(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command("pip install spam>=0.1.2", any_value() , shell=True) def test_should_install_dependency_with_version_and_operator(self): dependency = Dependency("spam", "==0.1.2") install_dependency(self.logger, self.project, dependency) verify(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command("pip install spam==0.1.2", any_value() , shell=True) def test_should_install_dependency_with_url(self): dependency = Dependency("spam", url="some_url") install_dependency(self.logger, self.project, dependency) verify(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command("pip install some_url", any_value() , shell=True) def test_should_install_dependency_with_url_even_if_version_is_given(self): dependency = Dependency("spam", version="0.1.2", url="some_url") install_dependency(self.logger, self.project, dependency) verify(pythonbuilder.plugins.python.install_dependencies_plugin).execute_command("pip install some_url", any_value() , shell=True)
def setUp(self): self.project = Project(".")
def setUp(self): unittest.TestCase.setUp(self) self.project = Project(".")
class BuildDataFilesStringTest(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) self.project = Project(".") def test_should_return_empty_data_files_string(self): self.assertEqual("", build_data_files_string(self.project)) def test_should_return_data_files_string_including_several_files(self): self.project.install_file("bin", "activate") self.project.install_file("bin", "command-stub") self.project.install_file("bin", "rsync") self.project.install_file("bin", "ssh") self.assertEqual("data_files = [('bin', ['activate', 'command-stub', 'rsync', 'ssh'])],",\ build_data_files_string(self.project)) def test_should_return_data_files_string_with_files_to_be_installed_in_several_destinations(self): self.project.install_file("/usr/bin", "pyb") self.project.install_file("/etc", "pyb.cfg") self.project.install_file("data", "pyb.dat") self.project.install_file("data", "howto.txt") self.assertEqual("data_files = [('/usr/bin', ['pyb']), ('/etc', ['pyb.cfg']),"\ " ('data', ['pyb.dat', 'howto.txt'])],",\ build_data_files_string(self.project))