Beispiel #1
0
    def test_running_plugin_no_failure_no_tests(self, read_file_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", False)
        project._plugin_env = {}
        logger = Mock()
        reactor = Mock()
        reactor.python_env_registry = {}
        reactor.python_env_registry["pybuilder"] = pyb_env = Mock()
        reactor.pybuilder_venv = pyb_env
        pyb_env.environ = {}
        pyb_env.executable = ["a/b"]
        execute_mock = pyb_env.execute_command = Mock()

        command_mock.return_value = ['cram']
        find_files_mock.return_value = []
        report_mock.return_value = 'report_file'
        read_file_mock.return_value = ['test failes for file', '# results']
        execute_mock.return_value = 1

        run_cram_tests(project, logger, reactor)

        execute_mock.assert_not_called()
        expected_info_calls = [
            call('Running Cram command line tests'),
        ]
        self.assertEqual(expected_info_calls, logger.info.call_args_list)
    def test_should_raise_error_when_protocol_is_invalid(self):
        logger = Mock()
        reactor = Mock()
        pyb_env = Mock()
        reactor.python_env_registry = {"pybuilder": pyb_env}
        reactor.pybuilder_venv = pyb_env
        downloader = DownloadingPluginLoader(logger)

        self.assertRaises(MissingPluginException, downloader.install_plugin,
                          reactor, PluginDef("some-plugin"))
    def test_should_download_module_from_pypi(self, load):
        logger = Mock()
        reactor = Mock()
        pyb_env = Mock()
        reactor.python_env_registry = {"pybuilder": pyb_env}
        reactor.pybuilder_venv = pyb_env

        pd = PluginDef("pypi:external_plugin")
        pl = DownloadingPluginLoader(logger)
        pl.install_plugin(reactor, pd)

        pyb_env.install_dependencies.assert_called_with(
            [Dependency("external_plugin")], package_type="plugin")
    def test_should_install_plugin_with_vcs_and_version(self):
        logger = Mock()
        reactor = Mock()
        pyb_env = Mock()
        reactor.python_env_registry = {"pybuilder": pyb_env}
        reactor.pybuilder_venv = pyb_env

        pd = PluginDef("vcs:some-plugin URL", "===1.2.3", "module_name")
        downloader = DownloadingPluginLoader(logger)
        downloader.install_plugin(reactor, pd)

        pyb_env.install_dependencies.assert_called_with([pd.dependency],
                                                        package_type="plugin")
    def test_should_install_upgrade_plugin_with_non_exact_version(self):
        logger = Mock()
        reactor = Mock()
        pyb_env = Mock()
        reactor.python_env_registry = {"pybuilder": pyb_env}
        reactor.pybuilder_venv = pyb_env

        pd = PluginDef("pypi:some-plugin", "~=1.2.3")
        downloader = DownloadingPluginLoader(logger)
        downloader.install_plugin(reactor, pd)

        pyb_env.install_dependencies.assert_called_with([pd.dependency],
                                                        package_type="plugin")
    def test_should_check_that_pylint_can_be_executed(self):
        mock_project = Mock(Project)
        mock_logger = Mock(Logger)

        reactor = Mock()
        pyb_env = Mock()
        reactor.python_env_registry = {"pybuilder": pyb_env}
        reactor.pybuilder_venv = pyb_env

        check_pep8_available(mock_project, mock_logger, reactor)

        expected_command_line = ['pep8', ]
        pyb_env.verify_can_execute.assert_called_with(expected_command_line, 'pep8', 'plugin python.pep8')
    def test_should_load_module_after_downloading_with_pypi_when_download_succeeds(
            self, load):
        logger = Mock()
        reactor = Mock()
        pyb_env = Mock()
        reactor.python_env_registry = {"pybuilder": pyb_env}
        reactor.pybuilder_venv = pyb_env

        downloader = DownloadingPluginLoader(logger)
        pd = PluginDef("pypi:external_plugin")
        plugin = downloader.load_plugin(reactor, pd)

        load.assert_called_with("external_plugin", pd.name)
        self.assertEqual(plugin, load.return_value)
    def test_should_check_that_sphinx_quickstart_can_be_executed(self):
        mock_project = Mock(Project)
        mock_logger = Mock(Logger)
        reactor = Mock()
        pyb_env = Mock()
        reactor.python_env_registry = {"pybuilder": pyb_env}
        reactor.pybuilder_venv = pyb_env

        assert_sphinx_quickstart_is_available(mock_project, mock_logger,
                                              reactor)

        pyb_env.verify_can_execute.assert_called_with(
            ["sphinx-quickstart", "--version"], "sphinx-quickstart",
            "plugin python.sphinx")
Beispiel #9
0
    def test_running_plugin_fails(
        self,
        read_file_mock,
        report_mock,
        find_files_mock,
        command_mock,
        tail_mock,
    ):
        project = Project('.')
        project.set_property('verbose', False)
        project.set_property('dir_source_main_python', 'python')
        project.set_property('dir_source_main_scripts', 'scripts')

        logger = Mock()
        reactor = Mock()
        reactor.python_env_registry = {}
        reactor.python_env_registry["pybuilder"] = pyb_env = Mock()
        reactor.pybuilder_venv = pyb_env
        pyb_env.environ = {}
        pyb_env.executable = ["a/b"]
        execute_mock = pyb_env.execute_command = Mock()

        command_mock.return_value = ['cram']
        find_files_mock.return_value = ['test1.cram', 'test2.cram']
        report_mock.return_value = 'report_file'
        read_file_mock.return_value = ['test failes for file', '# results']
        execute_mock.return_value = 1
        tail_mock.return_value = "tail data"

        self.assertRaises(BuildFailedException, run_cram_tests, project,
                          logger, reactor)
        execute_mock.assert_called_once_with(
            ['a/b', 'cram', 'test1.cram', 'test2.cram'],
            'report_file',
            error_file_name='report_file',
            env={
                'PYTHONPATH': np(jp(project.basedir, 'python')) + pathsep,
                'PATH': np(jp(project.basedir, 'scripts')) + pathsep
            })
        expected_info_calls = [
            call('Running Cram command line tests'),
        ]
        expected_error_calls = [
            call(
                'Cram tests failed! See report_file for full details:\ntail data'
            ),
        ]
        self.assertEqual(expected_info_calls, logger.info.call_args_list)
        self.assertEqual(expected_error_calls, logger.error.call_args_list)
    def test_should_import_plugin_when_requiring_plugin_and_plugin_is_found_as_third_party(
            self, load):
        logger = Mock()
        reactor = Mock()
        pyb_env = Mock()
        reactor.python_env_registry = {"pybuilder": pyb_env}
        reactor.pybuilder_venv = pyb_env
        load.return_value = Mock()

        downloader = DownloadingPluginLoader(logger)

        self.assertEqual(load.return_value,
                         downloader.load_plugin(reactor, PluginDef("spam")))
        pyb_env.install_dependencies.assert_not_called()
        self.assertEqual(pyb_env.install_dependencies.call_count, 0)
Beispiel #11
0
    def test_should_check_that_pymetrics_can_be_executed(self):
        mock_project = Mock(Project)
        mock_logger = Mock(Logger)

        reactor = Mock()
        reactor.python_env_registry = {}
        reactor.python_env_registry["pybuilder"] = pyb_env = Mock()
        pyb_env.environ = {}
        verify_mock = pyb_env.verify_can_execute = Mock()
        reactor.pybuilder_venv = pyb_env

        check_pymetrics_available(mock_project, mock_logger, reactor)

        verify_mock.assert_called_with(["pymetrics", "--nosql", "--nocsv"],
                                       "pymetrics", "plugin python.pymetrics")
    def test_should_check_that_sphinx_can_be_executed(self):
        mock_project = Mock(Project)
        mock_logger = Mock(Logger)
        reactor = Mock()
        pyb_env = Mock()
        reactor.python_env_registry = {"pybuilder": pyb_env}
        reactor.pybuilder_venv = pyb_env

        assert_sphinx_is_available(mock_project, mock_logger, reactor)

        pyb_env.verify_can_execute.assert_has_calls([
            call(["sphinx-build", "--version"], "sphinx-build",
                 "plugin python.sphinx"),
            call(["sphinx-apidoc", "--version"], "sphinx-apidoc",
                 "plugin python.sphinx")
        ])
    def test_should_not_load_module_twice_after_downloading_when_pypi_download_fails(
            self, load):
        logger = Mock()
        reactor = Mock()
        pyb_env = Mock()
        reactor.python_env_registry = {"pybuilder": pyb_env}
        reactor.pybuilder_venv = pyb_env

        pyb_env.install_dependencies.side_effect = MissingPluginException(
            "PyPI Install Boom")
        load.side_effect = MissingPluginException("PyPI Load Boom")
        downloader = DownloadingPluginLoader(logger)
        pd = PluginDef("pypi:external_plugin")
        self.assertRaises(MissingPluginException, downloader.load_plugin,
                          Mock(), pd)

        self.assertEqual(load.call_count, 1)
Beispiel #14
0
    def test_running_plugin_cram_from_target(self, read_file_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)
        project._plugin_env = {}
        logger = Mock()

        reactor = Mock()
        reactor.python_env_registry = {}
        reactor.python_env_registry["pybuilder"] = pyb_env = Mock()
        reactor.pybuilder_venv = pyb_env
        pyb_env.environ = {}
        pyb_env.executable = ["a/b"]
        execute_mock = pyb_env.execute_command = Mock()

        command_mock.return_value = ['cram']
        find_files_mock.return_value = ['test1.cram', 'test2.cram']
        report_mock.return_value = 'report_file'
        read_file_mock.return_value = ['test failes for file', '# results']
        execute_mock.return_value = 0

        run_cram_tests(project, logger, reactor)
        execute_mock.assert_called_once_with(
            ['a/b', 'cram', 'test1.cram', 'test2.cram'],
            'report_file',
            error_file_name='report_file',
            env={
                'PYTHONPATH': np(jp(project.basedir, 'python')) + pathsep,
                'PATH': np(jp(project.basedir, 'python/scripts')) + pathsep
            })
        expected_info_calls = [
            call('Running Cram command line tests'),
            call('Cram tests were fine'),
            call('results'),
        ]
        self.assertEqual(expected_info_calls, logger.info.call_args_list)