Skip to content

Commit

Permalink
Merge 0541972 into 5ea20cc
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Wolf committed Jul 23, 2015
2 parents 5ea20cc + 0541972 commit 097dd8c
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


@init
def init_test_source_directory(project):
def initialize_integrationtest_plugin(project):
project.set_property_if_unset(
"dir_source_integrationtest_python", "src/integrationtest/python")
project.set_property_if_unset("integrationtest_file_glob", "*_tests.py")
Expand Down
4 changes: 4 additions & 0 deletions src/main/python/pybuilder/plugins/python/snakefood_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def check_snakefood_available(logger):
assert_can_execute(("sfood", "-h"), "sfood", "plugin python.snakefood")
logger.debug("snakefood has been found")


@before("render_snakefood_report")
def check_graphviz_available(logger):

logger.debug("Checking availability of graphviz")
assert_can_execute(("dot", "-V"), "graphviz", "plugin python.snakefood")
logger.debug("graphviz has been found")
Expand Down
38 changes: 38 additions & 0 deletions src/unittest/python/plugins/python/coverage_plugin_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from unittest import TestCase
from pybuilder.core import Project
from pybuilder.plugins.python.coverage_plugin import (
init_coverage_properties
)


class CoveragePluginTests(TestCase):

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

def test_should_leave_user_specified_properties_when_initializing_plugin(self):

expected_properties = {
"coverage_threshold_warn": 120,
"coverage_break_build": False,
"coverage_reload_modules": False,
"coverage_exceptions": ["foo"],
"coverage_fork": True
}

for property_name, property_value in expected_properties.items():
self.project.set_property(property_name, property_value)

init_coverage_properties(self.project)

for property_name, property_value in expected_properties.items():
self.assertEquals(
self.project.get_property("coverage_threshold_warn"), 120)
self.assertEquals(
self.project.get_property("coverage_break_build"), False)
self.assertEquals(
self.project.get_property("coverage_reload_modules"), False)
self.assertEquals(
self.project.get_property("coverage_exceptions"), ["foo"])
self.assertEquals(
self.project.get_property("coverage_fork"), True)
52 changes: 44 additions & 8 deletions src/unittest/python/plugins/python/distutils_plugin_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,43 @@
default,
render_manifest_file,
build_scripts_string,
render_setup_script)
render_setup_script,
initialize_distutils_plugin)


class InstallDependenciesTest(unittest.TestCase):

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

def test_should_leave_user_specified_properties_when_initializing_plugin(self):

expected_properties = {
"distutils_commands": ["foo", "bar"],
"distutils_issue8876_workaround_enabled": True,
"distutils_classifiers": [
"Development Status :: 3 - Beta",
"Programming Language :: Rust"
],
"distutils_use_setuptools": False
}

for property_name, property_value in expected_properties.items():
self.project.set_property(property_name, property_value)

initialize_distutils_plugin(self.project)

for property_name, property_value in expected_properties.items():
self.assertEquals(
self.project.get_property("distutils_commands"), ["foo", "bar"])
self.assertEquals(
self.project.get_property("distutils_issue8876_workaround_enabled"), True)
self.assertEquals(
self.project.get_property("distutils_classifiers"), ["Development Status :: 3 - Beta",
"Programming Language :: Rust"])
self.assertEquals(
self.project.get_property("distutils_use_setuptools"), False)

def test_should_return_empty_string_when_no_dependency_is_given(self):
self.assertEqual("", build_install_dependencies_string(self.project))

Expand Down Expand Up @@ -119,7 +148,8 @@ def test_should_ignore_comments_with_leading_space_from_requirements(self, mock_
def test_should_ignore_editable_urls_from_requirements(self, mock_open):
mock_open.return_value = MagicMock(spec=TYPE_FILE)
handle = mock_open.return_value.__enter__.return_value
handle.readlines.return_value = ["foo", "-e git+https://github.com/someuser/someproject.git#egg=some_package"]
handle.readlines.return_value = [
"foo", "-e git+https://github.com/someuser/someproject.git#egg=some_package"]
self.project.depends_on_requirements("requirements.txt")

self.assertEqual(
Expand All @@ -129,7 +159,8 @@ def test_should_ignore_editable_urls_from_requirements(self, mock_open):
def test_should_ignore_expanded_editable_urls_from_requirements(self, mock_open):
mock_open.return_value = MagicMock(spec=TYPE_FILE)
handle = mock_open.return_value.__enter__.return_value
handle.readlines.return_value = ["foo", "--editable git+https://github.com/someuser/someproject.git#egg=some_package"]
handle.readlines.return_value = [
"foo", "--editable git+https://github.com/someuser/someproject.git#egg=some_package"]
self.project.depends_on_requirements("requirements.txt")

self.assertEqual(
Expand Down Expand Up @@ -194,7 +225,8 @@ def test_should_use_editable_urls_from_requirements_combined_with_url_dependenci
handle = mock_open.return_value.__enter__.return_value
handle.readlines.return_value = [
"-e svn+https://github.com/someuser/someproject#egg=some_package"]
self.project.depends_on("jedi", url="git+https://github.com/davidhalter/jedi")
self.project.depends_on(
"jedi", url="git+https://github.com/davidhalter/jedi")
self.project.depends_on_requirements("requirements.txt")

self.assertEqual(
Expand Down Expand Up @@ -294,14 +326,16 @@ def setUp(self):
self.project = create_project()

def test_should_remove_hardlink_capabilities_when_workaround_is_enabled(self):
self.project.set_property("distutils_issue8876_workaround_enabled", True)
self.project.set_property(
"distutils_issue8876_workaround_enabled", True)

actual_setup_script = render_setup_script(self.project)

self.assertTrue("import os\ndel os.link\n" in actual_setup_script)

def test_should_not_remove_hardlink_capabilities_when_workaround_is_disabled(self):
self.project.set_property("distutils_issue8876_workaround_enabled", False)
self.project.set_property(
"distutils_issue8876_workaround_enabled", False)

actual_setup_script = render_setup_script(self.project)

Expand All @@ -310,7 +344,8 @@ def test_should_not_remove_hardlink_capabilities_when_workaround_is_disabled(sel
def test_should_render_build_scripts_properly_when_dir_scripts_is_provided(self):
self.project.set_property("dir_dist_scripts", 'scripts')
actual_build_script = build_scripts_string(self.project)
self.assertEquals("['scripts/spam', 'scripts/eggs']", actual_build_script)
self.assertEquals(
"['scripts/spam', 'scripts/eggs']", actual_build_script)

def test_should_render_setup_file(self):
actual_setup_script = render_setup_script(self.project)
Expand Down Expand Up @@ -365,7 +400,8 @@ def test_should_render_runtime_dependencies_when_requirements_file_used(self, mo

actual_setup_script = render_setup_script(self.project)

self.assertTrue('install_requires = [ "sometool", "foo", "bar" ],' in actual_setup_script)
self.assertTrue(
'install_requires = [ "sometool", "foo", "bar" ],' in actual_setup_script)


class RenderManifestFileTest(unittest.TestCase):
Expand Down
35 changes: 35 additions & 0 deletions src/unittest/python/plugins/python/flake8_plugin_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from unittest import TestCase
from pybuilder.core import Project
from mock import Mock
from pybuilder.plugins.python.flake8_plugin import initialize_flake8_plugin


class FlakePluginInitializationTests(TestCase):

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

def test_should_set_dependency(self):
mock_project = Mock(Project)
initialize_flake8_plugin(mock_project)
mock_project.build_depends_on.assert_called_with('flake8')

def test_should_leave_user_specified_properties_when_initializing_plugin(self):

expected_properties = {
"flake8_break_build": False,
"flake8_max_line_length": 120,
"flake8_exclude_patterns": None,
"flake8_include_test_sources": False,
"flake8_include_scripts": False
}
for property_name, property_value in expected_properties.items():
self.project.set_property(property_name, property_value)

initialize_flake8_plugin(self.project)

for property_name, property_value in expected_properties.items():
self.assertEquals(

self.project.get_property(property_name),
property_value)
37 changes: 34 additions & 3 deletions src/unittest/python/plugins/python/integrationtest_plugin_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,46 @@
from mock import patch

from pybuilder.core import Project
from pybuilder.plugins.python.integrationtest_plugin import (TaskPoolProgress,
add_additional_environment_keys,
ConsumingQueue)
from pybuilder.plugins.python.integrationtest_plugin import (
TaskPoolProgress,
add_additional_environment_keys,
ConsumingQueue,
initialize_integrationtest_plugin
)


class TaskPoolProgressTests(unittest.TestCase):

def setUp(self):
self.progress = TaskPoolProgress(42, 8)
self.project = Project("basedir")

def test_should_leave_user_specified_properties_when_initializing_plugin(self):

expected_properties = {
"dir_source_integrationtest_python": "foo/bar/python",
"integrationtest_file_glob": "*foo.py",
"integrationtest_file_suffix": True,
"integrationtest_additional_environment": {"env3": "foo"},
"integrationtest_inherit_environment": True,
"integrationtest_always_verbose": True
}
for property_name, property_value in expected_properties.items():
self.project.set_property(property_name, property_value)

initialize_integrationtest_plugin(self.project)

for property_name, property_value in expected_properties.items():
self.assertEquals(
self.project.get_property("dir_source_integrationtest_python"), "foo/bar/python")
self.assertEquals(
self.project.get_property("integrationtest_file_glob"), "*foo.py")
self.assertEquals(
self.project.get_property("integrationtest_file_suffix"), True)
self.assertEquals(
self.project.get_property("integrationtest_additional_environment"), {"env3": "foo"}),
self.assertEquals(
self.project.get_property("integrationtest_always_verbose"), True)

def test_should_create_new_progress(self):
self.assertEqual(self.progress.workers_count, 8)
Expand Down
11 changes: 10 additions & 1 deletion src/unittest/python/plugins/python/pep8_plugin_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
# limitations under the License.

from unittest import TestCase
from pybuilder.core import Project
from mock import Mock, patch
from logging import Logger

from pybuilder.plugins.python.pep8_plugin import check_pep8_available
from pybuilder.plugins.python.pep8_plugin import (
check_pep8_available,
init_pep8_properties
)


class CheckPep8AvailableTests(TestCase):
Expand All @@ -34,3 +38,8 @@ def test_should_check_that_pylint_can_be_executed(self, mock_assert_can_execute)

expected_command_line = ('pep8',)
mock_assert_can_execute.assert_called_with(expected_command_line, 'pep8', 'plugin python.pep8')

def test_should_set_dependency(self):
mock_project = Mock(Project)
init_pep8_properties(mock_project)
mock_project.build_depends_on.assert_called_with('pep8')
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class InitTestSourceDirectoryTests(TestCase):

@patch('pybuilder.plugins.python.pyfix_plugin_impl.execute_tests_matching')
def test_should_set_pyfix_dependencey(self, mock_execute_tests_matching):
def test_should_set_pyfix_dependency(self, mock_execute_tests_matching):

mock_project = Mock(Project)

Expand Down
58 changes: 58 additions & 0 deletions src/unittest/python/plugins/python/snakefood_plugin_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from unittest import TestCase
from mock import Mock, patch
from logging import Logger
from pybuilder.core import Project
from pybuilder.plugins.python.snakefood_plugin import (
depend_on_snakefood,
check_snakefood_available,
check_graphviz_available,
generate_graph,
generate_pdf
)


class CheckSnakeFoodAvailableTests(TestCase):

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

def test_should_set_dependency(self):
mock_project = Mock(Project)
depend_on_snakefood(mock_project)
mock_project.build_depends_on.assert_called_with('snakefood')

@patch('pybuilder.plugins.python.snakefood_plugin.assert_can_execute')
def test_should_check_that_snakefood_is_available(self, mock_execute_command):

mock_logger = Mock(Logger)

check_snakefood_available(mock_logger)

mock_execute_command.assert_called_with(
("sfood", "-h"), "sfood", "plugin python.snakefood")

@patch('pybuilder.plugins.python.snakefood_plugin.assert_can_execute')
def test_should_check_that_graphviz_is_available(self, mock_execute_command):

mock_logger = Mock(Logger)

check_graphviz_available(mock_logger)

mock_execute_command.assert_called_with(
('dot', '-V'), 'graphviz', 'plugin python.snakefood')

@patch('pybuilder.plugins.python.snakefood_plugin.execute_command')
def test_should_call_generate_graph(self, mock_execute_command):
report_file = "foo"
graph_file = "bar.dot"
generate_graph(report_file, graph_file)
mock_execute_command.assert_called_with(
["sfood-graph", report_file], graph_file)

@patch('pybuilder.plugins.python.snakefood_plugin.execute_command')
def test_should_call_generate_pdf(self, mock_execute_command):
pdf_file = "foo.pdf"
graph_file = "bar.dot"
generate_pdf(graph_file, pdf_file)
mock_execute_command.assert_called_with(
["dot", "-Tpdf", graph_file], pdf_file)
24 changes: 15 additions & 9 deletions src/unittest/python/plugins/python/sphinx_plugin_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
assert_sphinx_quickstart_is_available,
get_sphinx_build_command,
get_sphinx_quickstart_command,
initialize_sphinx_plugin
)
initialize_sphinx_plugin)


class CheckSphinxAvailableTests(TestCase):
Expand Down Expand Up @@ -91,13 +90,20 @@ def test_should_set_default_values_when_initializing_plugin(self):
self.project.set_property("sphinx_project_name", "foo")
self.project.set_property("sphinx_project_version", "1.0")

self.assertEquals(self.project.get_property("sphinx_source_dir"), "docs")
self.assertEquals(self.project.get_property("sphinx_output_dir"), "docs/_build/")
self.assertEquals(self.project.get_property("sphinx_config_path"), "docs")
self.assertEquals(self.project.get_property("sphinx_doc_author"), 'John Doe, Jane Doe')
self.assertEquals(self.project.get_property("sphinx_doc_builder"), "html")
self.assertEquals(self.project.get_property("sphinx_project_name"), "foo")
self.assertEquals(self.project.get_property("sphinx_project_version"), "1.0")
self.assertEquals(
self.project.get_property("sphinx_source_dir"), "docs")
self.assertEquals(
self.project.get_property("sphinx_output_dir"), "docs/_build/")
self.assertEquals(
self.project.get_property("sphinx_config_path"), "docs")
self.assertEquals(
self.project.get_property("sphinx_doc_author"), 'John Doe, Jane Doe')
self.assertEquals(
self.project.get_property("sphinx_doc_builder"), "html")
self.assertEquals(
self.project.get_property("sphinx_project_name"), "foo")
self.assertEquals(
self.project.get_property("sphinx_project_version"), "1.0")


class SphinxBuildCommandTests(TestCase):
Expand Down

0 comments on commit 097dd8c

Please sign in to comment.