def test_lintcontext_passed_filtered_config(self, mocker): linters = mock_LINTERS(mocker, [create_mock_for_class(Linter)]) config = get_config() section_name = 'job_linter:{}'.format(list(linters.keys())[0]) config[section_name]['k'] = 'v' lint_context_mock = mocker.patch('jenkins_job_linter.LintContext') lint_job_xml(mocker.Mock(), 'job_name', mocker.sentinel.tree, config) lint_context_config = lint_context_mock.call_args[0][0] assert 'v' == lint_context_config['k']
def test_disable_linters_overlapping_linter_prefixes(self, mocker): linters = { 'do': create_mock_for_class(Linter), 'dont': create_mock_for_class(Linter), } mocker.patch('jenkins_job_linter.LINTERS', linters) mocker.patch('jenkins_job_linter.config.LINTERS', linters) config = get_config() config['job_linter']['disable_linters'] = 'dont,another' lint_job_xml(mocker.Mock(), 'job_name', mocker.Mock(), config) assert 1 == linters['do'].call_count assert 0 == linters['dont'].call_count
def test_disable_linters_config(self, mocker): linters = { 'disable_me': create_mock_for_class(Linter), 'not_me': create_mock_for_class(Linter), } mocker.patch('jenkins_job_linter.LINTERS', linters) mocker.patch('jenkins_job_linter.config.LINTERS', linters) config = get_config() config['job_linter']['disable_linters'] = 'disable_me' lint_job_xml(mocker.Mock(), 'job_name', mocker.Mock(), config) assert 0 == linters['disable_me'].call_count assert 1 == linters['not_me'].call_count
def test_all_linters_called_with_tree_and_run_ctx(self, mocker): linter_mocks = [create_mock_for_class(Linter) for _ in range(3)] mock_LINTERS(mocker, linter_mocks) lint_context_mock = mocker.patch('jenkins_job_linter.LintContext') run_ctx = mocker.Mock() lint_job_xml(run_ctx, 'job_name', mocker.sentinel.tree, get_config()) for linter_mock in linter_mocks: assert linter_mock.call_count == 1 assert linter_mock.call_args == mocker.call( lint_context_mock.return_value) for call_args in lint_context_mock.call_args_list: assert mocker.call(mocker.ANY, run_ctx, mocker.sentinel.tree) == call_args
def test_linters_can_return_text(self, mocker): mock_LINTERS(mocker, [ create_mock_for_class( Linter, check_result=LintResult.FAIL, check_msg='msg') ]) assert lint_job_xml(mocker.Mock(), 'job_name', mocker.sentinel.tree, get_config()) is False
def test_result_aggregation(self, mocker, expected, results): linter_mocks = [] for result in results: mock = create_mock_for_class(Linter, check_result=result) linter_mocks.append(mock) mock_LINTERS(mocker, linter_mocks) assert lint_job_xml(mocker.Mock(), 'job_name', mocker.sentinel.tree, get_config()) is expected