Exemplo n.º 1
0
    def test_publish_review_remove_ok_label(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)
        sha = 'abc123'
        config = {'OK_LABEL': 'No lint'}

        review = Review(self.repo, self.pr, config)
        sha = 'abc123'
        review.publish_review(problems, sha)

        assert self.pr.remove_label.called, 'Label should be removed'
        assert self.pr.create_review.called, 'Review should be added'
        eq_(1, self.pr.create_review.call_count)

        self.pr.remove_label.assert_called_with(config['OK_LABEL'])
        assert_review(
            self.pr.create_review.call_args,
            errors,
            sha)
Exemplo n.º 2
0
    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'
Exemplo n.º 3
0
    def test_process_files_three_files(self):
        self.tool.process_files(self.fixtures)

        eq_([], self.problems.all(self.fixtures[0]))

        fname = self.fixtures[1]
        problems = self.problems.all(fname)
        eq_(2, len(problems))

        msg = ("Warning: String literals must use "
               "double quotation marks in strict JSON")
        expected = Comment(fname, 2, 2, msg)
        eq_(expected, problems[0])

        msg = ("Warning: JSON does not allow identifiers "
               "to be used as strings: u'three'\n"
               "Warning: Strict JSON does not allow a final comma "
               "in an object (dictionary) literal")
        expected = Comment(fname, 3, 3, msg)
        eq_(expected, problems[1])

        fname = self.fixtures[2]
        problems = self.problems.all(fname)
        eq_(1, len(problems))

        msg = "Error: Unknown identifier: u'bleugh'"
        expected = Comment(fname, 1, 1, msg)
        eq_(expected, problems[0])
Exemplo n.º 4
0
    def test_filter_existing__removes_duplicates(self, http):
        fixture_data = load_fixture('comments_current.json')
        response = Response()
        response._content = fixture_data
        http.return_value = response

        gh = Github()
        problems = Problems()
        review = Review(gh, 2)
        filename_1 = "Routing/Filter/AssetCompressor.php"
        filename_2 = "View/Helper/AssetCompressHelper.php"

        problems.add(filename_1, 87, 'A pithy remark')
        problems.add(filename_1, 87, 'Something different')
        problems.add(filename_2, 88, 'I <3 it')
        problems.add(filename_2, 89, 'Not such a good comment')

        review.load_comments()
        review.remove_existing(problems)

        res = problems.all(filename_1)
        eq_(1, len(res))
        expected = Comment(filename_1, 87, 87, 'Something different')
        eq_(res[0], expected)

        res = problems.all(filename_2)
        eq_(1, len(res))
        expected = Comment(filename_2, 88, 88, 'I <3 it')
        eq_(res[0], expected)
Exemplo n.º 5
0
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        self.assertEqual(3, len(problems))

        fname = self.fixtures[1]
        expected = Comment(
            fname,
            3,
            3,
            'a is referenced but not assigned.\nDouble quote to prevent '
            'globbing and word splitting.')
        self.assertEqual(expected, problems[0])

        expected = Comment(
            fname,
            4,
            4,
            'BASE appears unused. Verify it or export it.\n'
            'Use $(..) instead of legacy \`..\`.')
        self.assertEqual(expected, problems[1])

        expected = Comment(
            fname,
            6,
            6,
            ("The order of the 2>&1 and the redirect matters. "
             "The 2>&1 has to be last."))
        self.assertEqual(expected, problems[2])
Exemplo n.º 6
0
    def test_filter_existing__removes_duplicates(self):
        fixture_data = load_fixture('comments_current.json')
        self.pr.review_comments.return_value = [
            GhIssueComment(f) for f in json.loads(fixture_data)
        ]
        problems = Problems()
        review = Review(self.repo, self.pr, self.config)
        filename_1 = "Routing/Filter/AssetCompressor.php"
        filename_2 = "View/Helper/AssetCompressHelper.php"

        problems.add(filename_1, 87, 'A pithy remark')
        problems.add(filename_1, 87, 'Something different')
        problems.add(filename_2, 88, 'I <3 it')
        problems.add(filename_2, 89, 'Not such a good comment')

        review.load_comments()
        review.remove_existing(problems)

        res = problems.all(filename_1)
        eq_(1, len(res))
        expected = Comment(filename_1, 87, 87,
                           'A pithy remark\nSomething different')
        eq_(res[0], expected)

        res = problems.all(filename_2)
        eq_(1, len(res))
        expected = Comment(filename_2, 88, 88, 'I <3 it')
        eq_(res[0], expected)
Exemplo n.º 7
0
    def test_publish_review_no_count_change(self):
        fixture = load_fixture('comments_current.json')
        self.pr.review_comments.return_value = [
            GhIssueComment(f) 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'

        config = build_review_config(fixer_ini, {'SUMMARY_THRESHOLD': 1})
        review = Review(self.repo, self.pr, config)
        review.publish_summary = Mock()
        review.publish_status = Mock()

        review.publish_review(problems, sha)
        # Ensure publish_status(True) means the status=failed
        review.publish_status.assert_called_with(True)
Exemplo n.º 8
0
    def test_publish_summary(self):
        problems = Problems()

        filename_1 = 'Console/Command/Task/AssetBuildTask.php'
        errors = (
            IssueComment('Terrible things'),
            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, self.config)
        review.publish_summary(problems)

        assert self.pr.create_comment.called
        eq_(1, self.pr.create_comment.call_count)

        msg = """There are 3 errors:

* Terrible things
* 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)
Exemplo n.º 9
0
 def test_error_count(self):
     errors = [
         Comment('some/file.py', 10, 10, 'Thing is wrong'),
         Comment('some/file.py', 12, 12, 'Not good'),
     ]
     self.problems.add_many(errors)
     assert 2 == len(self.problems)
     assert 2 == self.problems.error_count()
Exemplo n.º 10
0
 def test_process_files__one_file_fail(self):
     filename = self.fixtures[1]
     self.tool.process_files([filename])
     expected_problems = [
         Comment(filename, 2, 2, 'ERROR:foo not in autoload module layout'),
         Comment(filename, 3, 3, 'ERROR:trailing whitespace found'),
     ]
     problems = sorted(self.problems.all(filename), key=attrgetter('line'))
     self.assertEqual(expected_problems, problems)
Exemplo n.º 11
0
 def test_add_many(self):
     errors = [
         Comment('some/file.py', 10, 10, 'Thing is wrong'),
         Comment('some/file.py', 12, 12, 'Not good'),
     ]
     self.problems.add_many(errors)
     result = self.problems.all('some/file.py')
     eq_(2, len(result))
     eq_(errors, result)
Exemplo n.º 12
0
    def test_process_files__multiple_error(self):
        self.tool.process_files([self.fixtures[2]])
        problems = self.problems.all(self.fixtures[2])
        eq_(6, len(problems))

        fname = self.fixtures[2]
        expected = Comment(fname, 9, 9, "Missing semicolon.")
        eq_(expected, problems[2])

        expected = Comment(fname, 5, 5, "'go' is not defined.")
        eq_(expected, problems[4])
Exemplo n.º 13
0
 def test_process_files__one_file_fail(self):
     self.tool.process_files([self.fixtures[1]])
     problems = self.problems.all(self.fixtures[1])
     self.assertEqual(2, len(problems))
     fname = self.fixtures[1]
     expected = Comment(fname, 3, 3,
                        'Pipe chain should start with a raw value.')
     self.assertEqual(expected, problems[0])
     expected = Comment(fname, 1, 1,
                        'Modules should have a @moduledoc tag.')
     self.assertEqual(expected, problems[1])
Exemplo n.º 14
0
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(6, len(problems))

        fname = self.fixtures[1]
        expected = Comment(fname, 2, 2, 'E401 multiple imports on one line')
        eq_(expected, problems[0])

        expected = Comment(fname, 11, 11, "W603 '<>' is deprecated, use '!='")
        eq_(expected, problems[5])
Exemplo n.º 15
0
    def test_process_files__multiple_error(self):
        self.tool.process_files([self.fixtures[2]])
        problems = self.problems.all(self.fixtures[2])
        eq_(6, len(problems))

        fname = self.fixtures[2]
        expected = Comment(fname, 4, 4, "Implied global 'go'")
        eq_(expected, problems[3])

        expected = Comment(fname, 6, 6, "Implied global 'go'")
        eq_(expected, problems[4])
Exemplo n.º 16
0
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures.has_errors])
        problems = self.problems.all(self.fixtures.has_errors)
        self.assertEqual(2, len(problems))

        fname = self.fixtures.has_errors
        self.assertEqual([
            Comment(fname, 6, 6, 'E1601 print statement used'),
            Comment(fname, 11, 11,
                    'W1638 range built-in referenced when not iterating')
        ], problems)
Exemplo n.º 17
0
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(8, len(problems))

        fname = self.fixtures[1]
        expected = Comment(fname, 2, 2, "W402 're' imported but unused")
        eq_(expected, problems[0])

        expected = Comment(fname, 11, 11, "W603 '<>' is deprecated, use '!='")
        eq_(expected, problems[7])
Exemplo n.º 18
0
    def test_process_files_fail(self):
        file_has_errors = self.fixtures[1]
        self.tool.process_files([file_has_errors])
        problems = self.problems.all(file_has_errors)
        self.assertEqual(2, len(problems))

        expected = Comment(file_has_errors, 1, 1,
                           'Redundant "toString()" call in string template')
        self.assertEqual(expected, problems[0])
        expected = Comment(file_has_errors, 2, 2, 'Redundant curly braces')
        self.assertEqual(expected, problems[1])
Exemplo n.º 19
0
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(8, len(problems))

        fname = self.fixtures[1]
        expected = Comment(fname, 1, 1,
                           'Illegal space before opening round brace')
        eq_(expected, problems[0])

        expected = Comment(fname, 7, 7, 'Expected indentation of 4 characters')
        eq_(expected, problems[6])
Exemplo n.º 20
0
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(4, len(problems))

        fname = self.fixtures[1]
        expected = Comment(fname, 1, 1,
                           'Missing name in function declaration.')
        eq_(expected, problems[0])

        expected = Comment(fname, 6, 6, "Use '===' to compare with 'null'.")
        eq_(expected, problems[2])
Exemplo n.º 21
0
    def test_process_files__fail(self):
        self.tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        eq_(3, len(problems))

        msg = ("The key 'middle' is not sorted alphabetically")
        expected = Comment(FILE_WITH_ERRORS, 11, 11, msg)
        eq_(expected, problems[0])

        msg = ("Spaces before function parens are disallowed")
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        eq_(expected, problems[1])
Exemplo n.º 22
0
    def test_process_files_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(5, len(problems))

        fname = self.fixtures[1]
        expected = Comment(fname, 2, 2,
                           'foo is defined but never used (no-unused-vars)')
        eq_(expected, problems[0])

        expected = Comment(fname, 4, 4, '"alert" is not defined. (no-undef)')
        eq_(expected, problems[4])
Exemplo n.º 23
0
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(3, len(problems))

        fname = self.fixtures[1]
        expected = Comment(fname, 1, 1,
                           'Missing name in function declaration.')
        eq_(expected, problems[0])

        expected = Comment(fname, 4, 4, "Missing semicolon.")
        eq_(expected, problems[1])
Exemplo n.º 24
0
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(12, len(problems))

        fname = self.fixtures[1]
        expected = Comment(fname, 7, 7, 'PHP version not specified')
        eq_(expected, problems[0])

        expected = Comment(
            fname, 16, 16,
            "Line indented incorrectly; expected at least 4 spaces, found 1")
        eq_(expected, problems[11])
Exemplo n.º 25
0
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(2, len(problems))

        fname = self.fixtures[1]
        expected = Comment(fname, 1, 1, "Don't use IDs in selectors.")
        eq_(expected, problems[0])

        expected = Comment(fname, 2, 2,
                           "Using width with padding can"
                           " sometimes make elements larger than you expect.")
        eq_(expected, problems[1])
Exemplo n.º 26
0
    def test_process_files_fail(self):
        self.tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        eq_(2, len(problems))

        msg = ("'foo' is assigned a value but never used. (no-unused-vars)\n"
               "'bar' is not defined. (no-undef)")
        expected = Comment(FILE_WITH_ERRORS, 2, 2, msg)
        eq_(expected, problems[0])

        msg = ("'alert' is not defined. (no-undef)")
        expected = Comment(FILE_WITH_ERRORS, 4, 4, msg)
        eq_(expected, problems[1])
Exemplo n.º 27
0
 def test_add_many(self):
     errors = [
         ('some/file.py', 10, 'Thing is wrong'),
         ('some/file.py', 12, 'Not good'),
     ]
     self.problems.add_many(errors)
     result = self.problems.all('some/file.py')
     eq_(2, len(result))
     expected = [
         Comment(errors[0][0], errors[0][1], errors[0][1], errors[0][2]),
         Comment(errors[1][0], errors[1][1], errors[1][1], errors[1][2]),
     ]
     eq_(expected, result)
Exemplo n.º 28
0
    def test_process_files_two_files(self):
        self.tool.process_files(self.fixtures)

        eq_([], self.problems.all(self.fixtures[0]))

        problems = self.problems.all(self.fixtures[1])
        eq_(6, len(problems))
        expected = Comment(self.fixtures[1], 2, 2,
                           'E401 multiple imports on one line')
        eq_(expected, problems[0])

        expected = Comment(self.fixtures[1], 11, 11,
                           "W603 '<>' is deprecated, use '!='")
        eq_(expected, problems[5])
Exemplo n.º 29
0
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        self.assertEqual(3, len(problems))

        fname = self.fixtures[1]
        expected = Comment(fname, 14, 14,
                           'Opening brace should be on a new line')
        self.assertEqual(expected, problems[0])

        expected = Comment(
            fname, 16, 16,
            "Spaces must be used to indent lines; tabs are not allowed")
        self.assertEqual(expected, problems[2])
Exemplo n.º 30
0
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(6, len(problems))

        fname = self.fixtures[1]
        msg = ("F401 're' imported but unused\n"
               "F401 'os' imported but unused\n"
               "E401 multiple imports on one line")
        expected = Comment(fname, 2, 2, msg)
        eq_(expected, problems[0])

        expected = Comment(fname, 11, 11, "W603 '<>' is deprecated, use '!='")
        eq_(expected, problems[5])