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.list_modules = 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
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"
    project.explicit_namespaces = ["foo.bar", "quick.brown.fox"]

    def return_dummy_list():
        return ["spam", "eggs"]

    project.list_scripts = return_dummy_list
    project.list_packages = return_dummy_list
    project.list_modules = 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 InitPythonDirectoriesTest (unittest.TestCase):

    def greedy(self, generator):
        return [element for element in generator]

    def setUp(self):
        self.project = Project(".")

    @patch("pybuilder.plugins.python.core_plugin.os.listdir")
    @patch("pybuilder.plugins.python.core_plugin.os.path.isfile")
    def test_should_set_list_modules_function_with_project_modules(self, _, source_listdir):
        source_listdir.return_value = ["foo.py", "bar.py", "some-package"]

        init_python_directories(self.project)

        self.assertEquals(
            ['foo', 'bar'],
            self.greedy(self.project.list_modules())
        )

    @patch("pybuilder.plugins.python.core_plugin.os.walk")
    @patch("pybuilder.plugins.python.core_plugin.os.path.exists")
    def test_should_set_list_packages_function_with_project_packages(self, _, walk):
        walk.return_value = [("./src/main/python/pybuilder",
                              ['pluginhelper', 'plugins'],
                              ['execution.py', 'terminal.py', 'execution.pyc', 'scaffolding.py']
                              )]
        self.project.set_property("dir_source_main_python",
                                  "src/main/python")

        init_python_directories(self.project)

        self.assertEquals(
            ['pybuilder.pluginhelper',
             'pybuilder.plugins'],
            self.greedy(self.project.list_packages())
        )

    @patch("pybuilder.plugins.python.core_plugin.os.walk")
    @patch("pybuilder.plugins.python.core_plugin.os.path.exists")
    def test_should_not_cut_off_packages_when_path_ends_with_trailing_slash(self, _, walk):
        walk.return_value = [("./src/main/python/pybuilder",
                              ['pluginhelper', 'plugins'],
                              ['execution.py', 'terminal.py', 'execution.pyc', 'scaffolding.py']
                              )]
        self.project.set_property("dir_source_main_python",
                                  "src/main/python/")

        init_python_directories(self.project)

        self.assertEquals(
            ['pybuilder.pluginhelper',
             'pybuilder.plugins'],
            self.greedy(self.project.list_packages())
        )

    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"))
Example #4
0
class InitPythonDirectoriesTest(unittest.TestCase):
    def greedy(self, generator):
        return [element for element in generator]

    def setUp(self):
        self.project = Project(".")

    @patch("pybuilder.plugins.python.core_plugin.os.listdir")
    @patch("pybuilder.plugins.python.core_plugin.os.path.isfile")
    def test_should_set_list_modules_function_with_project_modules(
            self, _, source_listdir):
        source_listdir.return_value = ["foo.py", "bar.py", "some-package"]

        init_python_directories(self.project)

        self.assertEquals(['foo', 'bar'],
                          self.greedy(self.project.list_modules()))

    @patch("pybuilder.plugins.python.core_plugin.os.walk")
    @patch("pybuilder.plugins.python.core_plugin.os.path.exists")
    def test_should_set_list_packages_function_with_project_packages(
            self, _, walk):
        walk.return_value = [(join(".", "src", "main", "python",
                                   "pybuilder"), ['pluginhelper', 'plugins'], [
                                       'execution.py', 'terminal.py',
                                       'execution.pyc', 'scaffolding.py'
                                   ])]
        self.project.set_property("dir_source_main_python", "src/main/python")

        init_python_directories(self.project)

        self.assertEquals(['pybuilder.pluginhelper', 'pybuilder.plugins'],
                          self.greedy(self.project.list_packages()))

    @patch("pybuilder.plugins.python.core_plugin.os.walk")
    @patch("pybuilder.plugins.python.core_plugin.os.path.exists")
    def test_should_not_cut_off_packages_when_path_ends_with_trailing_slash(
            self, _, walk):
        walk.return_value = [(join(".", "src", "main", "python",
                                   "pybuilder"), ['pluginhelper', 'plugins'], [
                                       'execution.py', 'terminal.py',
                                       'execution.pyc', 'scaffolding.py'
                                   ])]
        self.project.set_property("dir_source_main_python", "src/main/python/")

        init_python_directories(self.project)

        self.assertEquals(['pybuilder.pluginhelper', 'pybuilder.plugins'],
                          self.greedy(self.project.list_packages()))

    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"))
Example #5
0
class InitPythonDirectoriesTest(unittest.TestCase):
    def greedy(self, generator):
        return list(generator)

    def setUp(self):
        self.project = Project(".")

    @patch("pybuilder.plugins.python.core_plugin.listdir")
    @patch("pybuilder.plugins.python.core_plugin.isfile")
    def test_should_set_list_modules_function_with_project_modules(
            self, _, source_listdir):
        source_listdir.return_value = ["foo.py", "bar.py", "some-package"]

        init_python_directories(self.project)

        self.assertEqual(["foo", "bar"],
                         self.greedy(self.project.list_modules()))

    @patch("pybuilder.plugins.python.core_plugin.walk")
    @patch("pybuilder.plugins.python.core_plugin.exists")
    def test_should_set_list_packages_function_with_project_packages(
            self, _, walk):
        self.project.set_property("dir_source_main_python", "src/main/python")

        init_python_directories(self.project)
        src_path = self.project.expand_path("$dir_source_main_python")

        walk.return_value = [(join(src_path,
                                   "pybuilder"), ["pluginhelper", "plugins"],
                              ("__init__.py", "foo.py", "foo.txt")),
                             (join(src_path, "pybuilder",
                                   "pluginhelper"), (), "__init__.py"),
                             (join(src_path, "pybuilder",
                                   "plugins"), (), "__init__.py")]

        self.assertEqual(
            ["pybuilder", "pybuilder.pluginhelper", "pybuilder.plugins"],
            self.greedy(self.project.list_packages()))

    @patch("pybuilder.plugins.python.core_plugin.walk")
    @patch("pybuilder.plugins.python.core_plugin.exists")
    def test_should_not_cut_off_packages_when_path_ends_with_trailing_slash(
            self, _, walk):
        self.project.set_property("dir_source_main_python", "src/main/python/")

        init_python_directories(self.project)
        src_path = self.project.expand_path("$dir_source_main_python")

        walk.return_value = [(join(src_path,
                                   "pybuilder"), ["pluginhelper", "plugins"],
                              ("__init__.py", "foo.py", "foo.txt")),
                             (join(src_path, "pybuilder",
                                   "pluginhelper"), (), "__init__.py"),
                             (join(src_path, "pybuilder",
                                   "plugins"), (), "__init__.py")]

        self.assertEqual(
            ["pybuilder", "pybuilder.pluginhelper", "pybuilder.plugins"],
            self.greedy(self.project.list_packages()))

    def test_should_set_python_sources_property(self):
        init_python_directories(self.project)
        self.assertEqual(
            "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.assertEqual(
            "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.assertEqual("scripts",
                         self.project.get_property(SCRIPTS_TARGET_PROPERTY))

    def test_should_set_dist_property(self):
        init_python_directories(self.project)
        self.assertEqual(
            "$dir_target/dist/.-1.0.dev0",
            self.project.get_property(DISTRIBUTION_PROPERTY, "caboom"))