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 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 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))
Beispiel #4
0
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)
Beispiel #5
0
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 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))