def test_publish_comment_threshold_checks(self, http): fixture_data = load_fixture('comments_current.json') response = Response() response._content = fixture_data http.return_value = response gh = Github() problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( (filename_1, 117, 'Something bad'), (filename_1, 119, 'Something bad'), ) problems.add_many(errors) problems.set_changes([1]) sha = 'abc123' review = Review(gh, 3) review.publish_summary = Mock() review.publish(problems, sha, 1) assert review.publish_summary.called, 'Should have been called.'
def test_publish_summary(self): problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( Comment(filename_1, 117, 117, 'Something bad'), Comment(filename_1, 119, 119, 'Something bad'), ) problems.add_many(errors) problems.set_changes([1]) review = Review(self.repo, self.pr) review.publish_summary(problems) assert self.pr.create_comment.called eq_(1, self.pr.create_comment.call_count) msg = """There are 2 errors: * Console/Command/Task/AssetBuildTask.php, line 117 - Something bad * Console/Command/Task/AssetBuildTask.php, line 119 - Something bad """ self.pr.create_comment.assert_called_with(msg)
def test_publish_problems_remove_ok_label(self): problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( (filename_1, 117, 'Something bad'), (filename_1, 119, 'Something bad'), ) problems.add_many(errors) sha = 'abc123' config = {'OK_LABEL': 'No lint'} review = Review(self.repo, self.pr, config) sha = 'abc123' review.publish_problems(problems, sha) assert self.pr.remove_label.called, 'Label should be removed' assert self.pr.create_review_comment.called, 'Comments should be added' eq_(2, self.pr.create_review_comment.call_count) self.pr.remove_label.assert_called_with(config['OK_LABEL']) assert_review_comments_created( self.pr.create_review_comment.call_args_list, errors, sha)
def test_publish_review_comment_threshold_checks(self): fixture = load_fixture('comments_current.json') self.pr.review_comments.return_value = [ GhIssueComment(f, self.session) for f in json.loads(fixture) ] problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( Comment(filename_1, 117, 117, 'Something bad'), Comment(filename_1, 119, 119, 'Something bad'), ) problems.add_many(errors) problems.set_changes([1]) sha = 'abc123' tst_config = build_review_config(fixer_ini, {'SUMMARY_THRESHOLD': 1}) review = Review(self.repo, self.pr, tst_config) with patch('lintreview.review.Review.publish_summary') as pub_sum_mock: review.publish_review(problems, sha) self.assertTrue(pub_sum_mock.called)
def test_publish__join_issue_comments(self): problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( IssueComment('First'), Comment(filename_1, 119, 119, 'Something bad'), IssueComment('Second'), ) problems.add_many(errors) sha = 'abc123' review = Review(self.repo, self.pr, self.config) review.publish_pull_review(problems, sha) assert self.pr.create_review.called eq_(1, self.pr.create_review.call_count) assert_review( self.pr.create_review.call_args, [errors[1]], sha, body='First\n\nSecond')
def test_publish_checkrun(self): self.repo.create_checkrun = Mock() config = build_review_config(fixer_ini, {'PULLREQUEST_STATUS': True}) problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( Comment(filename_1, 117, 8, 'Something bad'), Comment(filename_1, 119, 9, 'Something worse'), ) problems.add_many(errors) run_id = 42 review = Review(self.repo, self.pr, config) review.publish_checkrun(problems, run_id) assert self.repo.update_checkrun.called eq_(1, self.repo.update_checkrun.call_count) assert_checkrun( self.repo.update_checkrun.call_args, errors, run_id) assert self.repo.create_status.called is False, 'no status required'
def test_publish_review_no_count_change(self, pub_status_mock, _): fixture = load_fixture('comments_current.json') self.pr.review_comments.return_value = [ GhIssueComment(f, self.session) for f in json.loads(fixture) ] problems = Problems() # Match the line/positions in comments_current.json filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( Comment(filename_1, 40, 40, '2. Something bad'), Comment(filename_1, 87, 87, '1. Something bad'), Comment(filename_1, 89, 89, '2. Something bad'), ) problems.add_many(errors) problems.set_changes([1]) sha = 'abc123' tst_config = build_review_config(fixer_ini, {'SUMMARY_THRESHOLD': 1}) review = Review(self.repo, self.pr, tst_config) review.publish_review(problems, sha) # Ensure publish_status(True) means the status=failed pub_status_mock.assert_called_with(True)
def test_publish_checkrun__has_errors_force_success_status(self): self.repo.create_checkrun = Mock() tst_config = build_review_config(fixer_ini, {'PULLREQUEST_STATUS': False}) self.assertEqual('success', tst_config.failed_review_status(), 'config object changed') review = Review(self.repo, self.pr, tst_config) problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( Comment(filename_1, 117, 8, 'Something bad'), Comment(filename_1, 119, 9, 'Something worse'), ) problems.add_many(errors) run_id = 42 review.publish_checkrun(problems, run_id) assert self.repo.create_status.called is False, 'no status required' checkrun = self.repo.update_checkrun.call_args[0][1] self.assertEqual('success', checkrun['conclusion']) assert len(checkrun['output']['annotations']) > 0
def test_publish_problems(self): gh = Mock() problems = Problems() filename_1 = 'Console/Command/Task/AssetBuildTask.php' errors = ( (filename_1, 117, 'Something bad'), (filename_1, 119, 'Something bad'), ) problems.add_many(errors) sha = 'abc123' review = Review(gh, 3) review.publish_problems(problems, sha) assert gh.pull_requests.comments.create.called eq_(2, gh.pull_requests.comments.create.call_count) calls = gh.pull_requests.comments.create.call_args_list expected = call( 3, { 'commit_id': sha, 'path': errors[0][0], 'position': errors[0][1], 'body': errors[0][2] }) eq_(calls[0], expected) expected = call( 3, { 'commit_id': sha, 'path': errors[1][0], 'position': errors[1][1], 'body': errors[1][2] }) eq_(calls[1], expected)
def setUp(self): self.problems = Problems() self.tool = Flake8(self.problems, {}, root_dir)
def setUp(self): self.problems = Problems() self.tool = Rubocop(self.problems)
def setUp(self): self.problems = Problems() self.tool = Jscs(self.problems)
def setUp(self): self.problems = Problems() self.tool = Ansible(self.problems, {}, root_dir)
def setUp(self): self.problems = Problems()
def setUp(self): self.problems = Problems() self.tool = Jsonlint(self.problems, {}, root_dir)
def setUp(self): self.problems = Problems() self.tool = Rubocop(self.problems, {}, root_dir)
def setUp(self): self.fixture_data = create_commits(self.fixture) self.problems = Problems() self.tool = Commitcheck(self.problems)
def setUp(self): self.problems = Problems() config = {'config': 'tests/fixtures/goodcheck/goodcheck.yml'} self.tool = Goodcheck(self.problems, config, root_dir)
def test_add__with_base_path_no_trailing_slash(self): problems = Problems('/some/path') problems.add('/some/path/file.py', 10, 'Not good') eq_([], problems.all('/some/path/file.py')) eq_(1, len(problems.all('file.py'))) eq_(1, len(problems))
def setUp(self): self.problems = Problems() self.tool = Jshint(self.problems, base_path=root_dir)
def test_has_changes(self): problems = Problems(changes=None) self.assertFalse(problems.has_changes()) problems = Problems(changes=[1]) assert problems.has_changes()
def setUp(self): self.problems = Problems() self.tool = Shellcheck(self.problems)
def setUp(self): self.fixture_data = Resource.loads(self.fixture) self.problems = Problems() self.tool = Commitcheck(self.problems)
def setUp(self): self.problems = Problems() self.tool = Shellcheck(self.problems, {}, root_dir)
def setUp(self): self.problems = Problems() self.tool = Yamllint(self.problems)
def setUp(self): self.problems = Problems() self.tool = Remarklint(self.problems, {}, root_dir)
def setUp(self): self.problems = Problems() self.tool = Phpcs(self.problems, base_path=root_dir)
def setUp(self): self.problems = Problems() config = {'config': 'tests/fixtures/checkstyle/config.xml'} self.tool = Checkstyle(self.problems, config, root_dir)
def setUp(self): self.problems = Problems() self.tool = Mypy(self.problems, {}, root_dir)
def setUp(self): self.problems = Problems() options = {'config': 'tests/fixtures/eslint/recommended_config.json'} self.tool = Eslint(self.problems, options)