Example #1
0
class TestSwiftlint(TestCase):
    def setUp(self):
        self.problems = Problems()
        options = {}
        self.tool = Swiftlint(self.problems, options, root_dir)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.swift'))
        self.assertTrue(self.tool.match_file('dir/name/test.swift'))

    @requires_image('swiftlint')
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @requires_image('swiftlint')
    def test_process_files_pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        eq_([], self.problems.all(FILE_WITH_NO_ERRORS))

    @requires_image('swiftlint')
    def test_process_files_fail(self):
        self.tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        eq_(1, len(problems))

        msg = ("Colons should be next to the identifier when specifying "
               "a type and next to the key in dictionary literals.")
        expected = [Comment(FILE_WITH_ERRORS, 2, 2, msg)]
        eq_(expected, problems)
Example #2
0
class TestFoodcritic(TestCase):
    needs_critic = skipIf(critic_missing, 'Missing foodcritic, cannot run')

    fixtures = [
        'tests/fixtures/foodcritic/noerrors',
        'tests/fixtures/foodcritic/errors',
    ]

    def setUp(self):
        self.problems = Problems()

    @needs_critic
    def test_process_cookbook_pass(self):
        self.tool = Foodcritic(self.problems, None, self.fixtures[0])
        self.tool.process_files(None)
        eq_([], self.problems.all())

    @needs_critic
    def test_process_cookbook_fail(self):
        self.tool = Foodcritic(self.problems, None, self.fixtures[1])
        self.tool.process_files(None)
        problems = self.problems.all()
        eq_(5, len(problems))

        expected = Comment(
            'tests/fixtures/foodcritic/errors/recipes/apache2.rb', 1, 1,
            'FC007: Ensure recipe dependencies are reflected in cookbook '
            'metadata')
        eq_(expected, problems[1])
Example #3
0
class TestSwiftlint(TestCase):

    needs_swiftlint = skipIf(swiftlint_missing, 'Needs swiftlint to run')

    def setUp(self):
        self.problems = Problems()
        options = {}
        self.tool = Swiftlint(self.problems, options)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.swift'))
        self.assertTrue(self.tool.match_file('dir/name/test.swift'))

    @needs_swiftlint
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @needs_swiftlint
    def test_process_files_pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        eq_([], self.problems.all(FILE_WITH_NO_ERRORS))

    @needs_swiftlint
    def test_process_files_fail(self):
        self.tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        eq_(1, len(problems))

        msg = ("Colons should be next to the identifier when specifying "
               "a type and next to the key in dictionary literals.")
        expected = [Comment(FILE_WITH_ERRORS, 2, 2, msg)]
        eq_(expected, problems)
Example #4
0
class TestFlake8(TestCase):

    fixtures = [
        'tests/fixtures/pep8/no_errors.py',
        'tests/fixtures/pep8/has_errors.py',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Flake8(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('test.js'))
        self.assertFalse(self.tool.match_file('dir/name/test.js'))
        self.assertTrue(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('dir/name/test.py'))

    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[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, "F401 're' imported but unused")
        eq_(expected, problems[1])

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

    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_(8, len(problems))

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

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

    def test_config_options_and_process_file(self):
        options = {
            'ignore': 'F4,W603'
        }
        self.tool = Flake8(self.problems, options)
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(6, len(problems))
        for p in problems:
            self.assertFalse('F4' in p)
            self.assertFalse('W603' in p)
Example #5
0
class TestEslint(TestCase):

    needs_eslint = skipIf(eslint_missing, 'Needs eslint to run')

    def setUp(self):
        self.problems = Problems()
        options = {'config': 'tests/fixtures/eslint/recommended_config.json'}
        self.tool = Eslint(self.problems, options)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('dir/name/test.js'))

    @needs_eslint
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @needs_eslint
    def test_process_files_pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        eq_([], self.problems.all(FILE_WITH_NO_ERRORS))

    @needs_eslint
    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 defined 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])

    @needs_eslint
    def test_process_files_with_no_config(self):
        tool = Eslint(self.problems, options={})
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        eq_(0, len(problems), 'With no config file there should be no errors.')

    @needs_eslint
    def test_process_files_with_config(self):
        options = {'config': 'tests/fixtures/eslint/config.json'}
        tool = Eslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all(FILE_WITH_ERRORS)

        msg = ("'foo' is defined but never used (no-unused-vars)\n"
               "'bar' is not defined. (no-undef)\n"
               "Missing semicolon. (semi)")
        expected = [Comment(FILE_WITH_ERRORS, 2, 2, msg)]
        eq_(expected, problems)
class TestFoodcritic(TestCase):
    needs_critic = skipIf(critic_missing, 'Missing foodcritic, cannot run')

    fixtures = [
        'tests/fixtures/foodcritic/noerrors',
        'tests/fixtures/foodcritic/errors',
    ]

    def setUp(self):
        self.problems = Problems()

    @needs_critic
    def test_process_cookbook_pass(self):
        self.tool = Foodcritic(self.problems, None, self.fixtures[0])
        self.tool.process_files(None)
        eq_([], self.problems.all())

    @needs_critic
    def test_process_cookbook_fail(self):
        self.tool = Foodcritic(self.problems, None, self.fixtures[1])
        self.tool.process_files(None)
        problems = self.problems.all()
        eq_(5, len(problems))

        expected = Comment(
            'tests/fixtures/foodcritic/errors/recipes/apache2.rb', 1, 1,
            'FC007: Ensure recipe dependencies are reflected in cookbook '
            'metadata')
        eq_(expected, problems[1])
Example #7
0
class TestPhpmd(TestCase):

    fixtures = [
        'tests/fixtures/phpmd/no_errors.php',
        'tests/fixtures/phpmd/has_errors.php',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Phpmd(self.problems, base_path=root_dir)

    def test_match_file(self):
        self.assertTrue(self.tool.match_file('test.php'))
        self.assertTrue(self.tool.match_file('dir/name/test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertFalse(self.tool.match_file('test.js'))

    @requires_image('php')
    def test_check_dependencies(self):
        assert self.tool.check_dependencies()

    @requires_image('php')
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        assert len(self.problems) == 0

    @requires_image('php')
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])

        errors = self.problems.all(self.fixtures[1])
        assert len(errors) == 1

        error = errors[0]
        assert 7 == error.line
        assert 'CyclomaticComplexity:' in error.body
        assert 'The method tooComplex()' in error.body
        assert 'See: http://phpmd.org/' in error.body

    @requires_image('php')
    def test_process_files__two_files(self):
        self.tool.process_files(self.fixtures)

        errors = self.problems.all(self.fixtures[0])
        assert len(errors) == 0

        errors = self.problems.all(self.fixtures[1])
        assert len(errors) == 1

    @requires_image('php')
    def test_process_files__invalid_ruleset(self):
        tool = Phpmd(self.problems, {'ruleset': 'garbage'}, base_path=root_dir)
        tool.process_files(self.fixtures)

        errors = self.problems.all()
        assert len(errors) == 1
        assert 'PHPMD configuration output the following error:' in errors[
            0].body
        assert 'Cannot find specified rule-set "garbage"' in errors[0].body
Example #8
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)
Example #9
0
    def test_filter_existing__removes_duplicates(self):
        fixture_data = load_fixture('comments_current.json')
        self.pr.review_comments.return_value = map(
            lambda f: GhIssueComment(f),
            json.loads(fixture_data))
        problems = Problems()
        review = Review(self.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)
Example #10
0
    def test_filter_existing__removes_duplicates(self):
        fixture_data = load_fixture('comments_current.json')
        self.pr.review_comments.return_value = [
            GhIssueComment(f, self.session) 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)
        self.assertEqual(1, len(res))
        expected = Comment(filename_1,
                           87,
                           87,
                           'A pithy remark\nSomething different')
        self.assertEqual(res[0], expected)

        res = problems.all(filename_2)
        self.assertEqual(1, len(res))
        expected = Comment(filename_2, 88, 88, 'I <3 it')
        self.assertEqual(res[0], expected)
Example #11
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)
Example #12
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)
Example #13
0
class TestSwiftlint(TestCase):

    def setUp(self):
        self.problems = Problems()
        options = {}
        self.tool = Swiftlint(self.problems, options, root_dir)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.swift'))
        self.assertTrue(self.tool.match_file('dir/name/test.swift'))

    @requires_image('swiftlint')
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @requires_image('swiftlint')
    def test_process_files_pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        self.assertEqual([], self.problems.all(FILE_WITH_NO_ERRORS))

    @requires_image('swiftlint')
    def test_process_files_fail(self):
        self.tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        self.assertEqual(1, len(problems))

        msg = ("Colons should be next to the identifier when specifying "
               "a type and next to the key in dictionary literals.")
        expected = [Comment(FILE_WITH_ERRORS, 2, 2, msg)]
        self.assertEqual(expected, problems)
Example #14
0
class TestFlake8(TestCase):

    fixtures = [
        'tests/fixtures/pep8/no_errors.py',
        'tests/fixtures/pep8/has_errors.py',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Flake8(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('test.js'))
        self.assertFalse(self.tool.match_file('dir/name/test.js'))
        self.assertTrue(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('dir/name/test.py'))

    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[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, "F401 're' imported but unused")
        eq_(expected, problems[1])

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

    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_(8, len(problems))

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

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

    def test_config_options_and_process_file(self):
        options = {
            'ignore': 'F4,W603'
        }
        self.tool = Flake8(self.problems, options)
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(6, len(problems))
        for p in problems:
            self.assertFalse('F4' in p.body)
            self.assertFalse('W603' in p.body)
Example #15
0
class TestJscs(TestCase):

    fixtures = [
        'tests/fixtures/jscs/no_errors.js',
        'tests/fixtures/jscs/has_errors.js',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Jscs(self.problems, {}, root_dir)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('dir/name/test.js'))

    @requires_image('nodejs')
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @requires_image('nodejs')
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[0]))

    @requires_image('nodejs')
    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])

    @requires_image('nodejs')
    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_(8, len(problems))

    @requires_image('nodejs')
    def test_process_files_with_config(self):
        config = {'preset': 'airbnb'}
        tool = Jscs(self.problems, config, root_dir)
        tool.process_files([self.fixtures[0]])

        problems = self.problems.all(self.fixtures[0])

        eq_(1, len(problems))
Example #16
0
class TestPep8(TestCase):

    fixtures = [
        'tests/fixtures/pep8/no_errors.py',
        'tests/fixtures/pep8/has_errors.py',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Pep8(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('test.js'))
        self.assertFalse(self.tool.match_file('dir/name/test.js'))
        self.assertTrue(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('dir/name/test.py'))

    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[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])

    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 = (self.fixtures[1], 11, 11,
                    "W603 '<>' is deprecated, use '!='")
        eq_(expected, problems[5])

    def test_config_options_and_process_file(self):
        options = {'ignore': 'E2,W603'}
        self.tool = Pep8(self.problems, options)
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(4, len(problems))
        for p in problems:
            self.assertFalse('E2' in p)
            self.assertFalse('W603' in p)
Example #17
0
class TestYamllint(TestCase):

    fixtures = [
        'tests/fixtures/yamllint/no_errors.yaml',
        'tests/fixtures/yamllint/has_errors.yaml',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Yamllint(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('test.js'))
        self.assertFalse(self.tool.match_file('dir/name/test.js'))
        self.assertTrue(self.tool.match_file('test.yaml'))
        self.assertTrue(self.tool.match_file('dir/name/test.yaml'))
        self.assertTrue(self.tool.match_file('test.yml'))
        self.assertTrue(self.tool.match_file('dir/name/test.yml'))

    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[0]))

    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(5, len(problems))

        fname = self.fixtures[1]

        msg = "[warning] missing starting space in comment (comments)"
        expected = Comment(fname, 1, 1, msg)
        eq_(expected, problems[0])

        msg = ("[warning] missing document start \"---\" (document-start)\n"
               "[error] too many spaces inside braces (braces)")
        expected = Comment(fname, 2, 2, msg)
        eq_(expected, problems[1])

    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_(5, len(problems))

        fname = self.fixtures[1]

        msg = "[warning] missing starting space in comment (comments)"
        expected = Comment(fname, 1, 1, msg)
        eq_(expected, problems[0])

        msg = ("[warning] missing document start \"---\" (document-start)\n"
               "[error] too many spaces inside braces (braces)")
        expected = Comment(fname, 2, 2, msg)
        eq_(expected, problems[1])
Example #18
0
class TestPep8(TestCase):

    fixtures = [
        'tests/fixtures/pep8/no_errors.py',
        'tests/fixtures/pep8/has_errors.py',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Pep8(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('test.js'))
        self.assertFalse(self.tool.match_file('dir/name/test.js'))
        self.assertTrue(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('dir/name/test.py'))

    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[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])

    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])

    def test_config_options_and_process_file(self):
        options = {
            'ignore': 'E2,W603'
        }
        self.tool = Pep8(self.problems, options)
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(4, len(problems))
        for p in problems:
            self.assertFalse('E2' in p.body)
            self.assertFalse('W603' in p.body)
Example #19
0
class TestEslint(TestCase):

    needs_eslint = skipIf(eslint_missing, 'Needs eslint to run')

    fixtures = [
        'tests/fixtures/eslint/no_errors.js',
        'tests/fixtures/eslint/has_errors.js'
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Eslint(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('dir/name/test.js'))

    @needs_eslint
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @needs_eslint
    def test_process_files_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[0]))

    @needs_eslint
    def test_process_files_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(2, len(problems))

        fname = self.fixtures[1]
        msg = ("foo is defined but never used (no-unused-vars)\n"
               '"bar" is not defined. (no-undef)\n'
               'Missing semicolon. (semi)')
        expected = Comment(fname, 2, 2, msg)
        eq_(expected, problems[0])

        msg = ('Unexpected alert. (no-alert)\n'
               '"alert" is not defined. (no-undef)')
        expected = Comment(fname, 4, 4, msg)
        eq_(expected, problems[1])

    @needs_eslint
    def test_process_files_with_config(self):
        config = {
            'config': 'tests/fixtures/eslint/config.json'
        }
        tool = Eslint(self.problems, config)
        tool.process_files([self.fixtures[1]])

        problems = self.problems.all(self.fixtures[1])

        eq_(2, len(problems), 'Config file should lower error count.')
Example #20
0
class TestCommitCheck(TestCase):

    fixture = load_fixture('commits.json')

    def setUp(self):
        self.fixture_data = create_commits(self.fixture)
        self.problems = Problems()
        self.tool = Commitcheck(self.problems)

    def test_execute_commits__no_pattern(self):
        self.tool.options['pattern'] = ''
        self.tool.execute_commits(self.fixture_data)
        self.assertEqual(0, len(self.problems),
                         'Empty pattern does not find issues')

    def test_execute_commits__broken_regex(self):
        self.tool.options['pattern'] = '(.*'
        self.tool.execute_commits(self.fixture_data)
        self.assertEqual(0, len(self.problems),
                         'Empty pattern does not find issues')

    def test_execute_commits__match(self):
        self.tool.options['pattern'] = '\w+'
        self.tool.execute_commits(self.fixture_data)
        self.assertEqual(0, len(self.problems), 'Commits that do match are ok')

        self.tool.options['pattern'] = 'bugs?'
        self.tool.execute_commits(self.fixture_data)
        self.assertEqual(0, len(self.problems), 'Commits that do match are ok')

    def test_execute_commits__no_match(self):
        self.tool.options['pattern'] = '\d+'
        self.tool.execute_commits(self.fixture_data)
        self.assertEqual(1, len(self.problems),
                         'Commits that do not match cause errors')
        msg = ('The following commits had issues. '
               'The pattern \d+ was not found in:\n'
               '* 6dcb09b5b57875f334f61aebed695e2e4193db5e\n')
        expected = IssueComment(msg)
        self.assertEqual(expected, self.problems.all()[0])

    def test_execute_commits__custom_message(self):
        self.tool.options['pattern'] = '\d+'
        self.tool.options['message'] = 'You are bad.'
        self.tool.execute_commits(self.fixture_data)
        self.assertEqual(1, len(self.problems),
                         'Commits that do not match cause errors')
        msg = ('You are bad. The pattern \d+ was not found in:\n'
               '* 6dcb09b5b57875f334f61aebed695e2e4193db5e\n')
        expected = IssueComment(msg)
        self.assertEqual(expected, self.problems.all()[0])

    def test_execute_commits__ignore_author_email(self):
        self.tool.author = '*****@*****.**'
        self.tool.options['pattern'] = '\d+'
        self.tool.execute_commits(self.fixture_data)
        self.assertEqual(0, len(self.problems))
Example #21
0
class TestRubocop(TestCase):
    needs_rubocop = skipIf(rubocop_missing, 'Missing rubocop, cannot run')

    fixtures = [
        'tests/fixtures/rubocop/no_errors.rb',
        'tests/fixtures/rubocop/has_errors.rb',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Rubocop(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertTrue(self.tool.match_file('test.rb'))
        self.assertTrue(self.tool.match_file('dir/name/test.rb'))

    @needs_rubocop
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[0]))

    @needs_rubocop
    def test_process_files__one_file_fail(self):
        linty_filename = abspath(self.fixtures[1])
        self.tool.process_files([linty_filename])

        problems = self.problems.all(linty_filename)
        expected = Comment(linty_filename, 4, 4,
                           'C: Trailing whitespace detected.')
        eq_(expected, problems[1])

    @needs_rubocop
    def test_process_files_two_files(self):
        self.tool.process_files(self.fixtures)

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

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

    @needs_rubocop
    def test_process_files_one_file_fail_display_cop_names(self):
        options = {
            'display_cop_names': 'True',
        }
        self.tool = Rubocop(self.problems, options)
        linty_filename = abspath(self.fixtures[1])
        self.tool.process_files([linty_filename])

        problems = self.problems.all(linty_filename)
        expected = Comment(
            linty_filename, 4, 4,
            'C: Style/TrailingWhitespace: Trailing whitespace detected.')
        eq_(expected, problems[1])
Example #22
0
class TestJcs(TestCase):

    needs_jscs = skipIf(jscs_missing, "Needs jscs to run")

    fixtures = ["tests/fixtures/jscs/no_errors.js", "tests/fixtures/jscs/has_errors.js"]

    def setUp(self):
        self.problems = Problems()
        self.tool = Jscs(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file("test.php"))
        self.assertFalse(self.tool.match_file("dir/name/test.py"))
        self.assertFalse(self.tool.match_file("test.py"))
        self.assertTrue(self.tool.match_file("test.js"))
        self.assertTrue(self.tool.match_file("dir/name/test.js"))

    @needs_jscs
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @needs_jscs
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[0]))

    @needs_jscs
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        eq_(9, 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[7])

    @needs_jscs
    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_(9, len(problems))

    @needs_jscs
    def test_process_files_with_config(self):
        config = {"preset": "airbnb"}
        tool = Jscs(self.problems, config)
        tool.process_files([self.fixtures[0]])

        problems = self.problems.all(self.fixtures[0])

        eq_(1, len(problems))
Example #23
0
class TestRubocop(TestCase):
    needs_rubocop = skipIf(rubocop_missing, 'Missing rubocop, cannot run')

    fixtures = [
        'tests/fixtures/rubocop/no_errors.rb',
        'tests/fixtures/rubocop/has_errors.rb',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Rubocop(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertTrue(self.tool.match_file('test.rb'))
        self.assertTrue(self.tool.match_file('dir/name/test.rb'))

    @needs_rubocop
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[0]))

    @needs_rubocop
    def test_process_files__one_file_fail(self):
        linty_filename = abspath(self.fixtures[1])
        self.tool.process_files([linty_filename])

        problems = self.problems.all(linty_filename)
        expected = Comment(linty_filename, 4, 4,
                           'C: Trailing whitespace detected.')
        eq_(expected, problems[5])

    @needs_rubocop
    def test_process_files_two_files(self):
        self.tool.process_files(self.fixtures)

        linty_filename = abspath(self.fixtures[1])
        eq_(6, len(self.problems.all(linty_filename)))

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

    @needs_rubocop
    def test_process_files_one_file_fail_display_cop_names(self):
        options = {
            'display_cop_names': 'True',
        }
        self.tool = Rubocop(self.problems, options)
        linty_filename = abspath(self.fixtures[1])
        self.tool.process_files([linty_filename])

        problems = self.problems.all(linty_filename)
        expected = Comment(linty_filename, 3, 3,
                           'C: Metrics/LineLength: Line is too long. [82/80]')
        eq_(expected, problems[4])
Example #24
0
class TestSwiftlint(TestCase):

    def setUp(self):
        self.problems = Problems()
        options = {}
        self.tool = Swiftlint(self.problems, options, root_dir)

    def test_version(self):
        assert self.tool.version != ''

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.swift'))
        self.assertTrue(self.tool.match_file('dir/name/test.swift'))

    @requires_image('swiftlint')
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @requires_image('swiftlint')
    def test_process_files_pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        self.assertEqual([], self.problems.all(FILE_WITH_NO_ERRORS))

    @requires_image('swiftlint')
    def test_process_files_fail(self):
        self.tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        self.assertEqual(1, len(problems))

        msg = ("Colons should be next to the identifier when specifying "
               "a type and next to the key in dictionary literals.")
        expected = [Comment(FILE_WITH_ERRORS, 2, 2, msg)]
        self.assertEqual(expected, problems)

    @requires_image('swiftlint')
    def test_process_files_config_error(self):
        path = os.path.join(root_dir, 'tests', 'fixtures', 'swiftlint', 'bad_config')
        self.tool = Swiftlint(self.problems, {}, path)
        self.tool.process_files(['has_errors.swift'])
        problems = self.problems.all()
        self.assertEqual(2, len(problems))

        msg = (
            "Your `swiftlint` configuration generated warnings:"
            "\n"
            "```\n"
            "Invalid configuration for 'empty_count'. Falling back to default.\n"
            "```"
        )
        assert problems[0].body == msg
        assert "Colons should be next to the identifier" in problems[1].body
        assert problems[1].line == 2
Example #25
0
class TestPuppet(TestCase):

    fixtures = [
        'tests/fixtures/puppet/no_errors.pp',
        'tests/fixtures/puppet/has_errors.pp',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Puppet(self.problems, {}, root_dir)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertTrue(self.tool.match_file('test.pp'))
        self.assertTrue(self.tool.match_file('dir/name/test.pp'))

    @requires_image('ruby2')
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[0]))

    @requires_image('ruby2')
    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'))
        eq_(expected_problems, problems)

    @requires_image('ruby2')
    def test_process_files_two_files(self):
        self.tool.process_files(self.fixtures)

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

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

    @requires_image('ruby2')
    def test_process_files__with_config(self):
        config = {
            'config': 'tests/fixtures/puppet/puppetlint.rc'
        }
        tool = Puppet(self.problems, config)
        tool.process_files([self.fixtures[1]])

        eq_([], self.problems.all(self.fixtures[1]),
            'Config file should cause no errors on has_errors.pp')
Example #26
0
class TestEslint(TestCase):

    needs_eslint = skipIf(eslint_missing, 'Needs eslint to run')

    fixtures = [
        'tests/fixtures/eslint/no_errors.js',
        'tests/fixtures/eslint/has_errors.js'
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Eslint(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('dir/name/test.js'))

    @needs_eslint
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @needs_eslint
    def test_process_files_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[0]))

    @needs_eslint
    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])

    @needs_eslint
    def test_process_files_with_config(self):
        config = {'config': 'tests/fixtures/eslint/config.json'}
        tool = Eslint(self.problems, config)
        tool.process_files([self.fixtures[1]])

        problems = self.problems.all(self.fixtures[1])

        eq_(4, len(problems), 'Config file should lower error count.')
Example #27
0
class TestPy3k(TestCase):

    needs_py2 = skipIf(not_python2, 'Cannot run in python3')

    class fixtures:
        no_errors = 'tests/fixtures/py3k/no_errors.py'
        has_errors = 'tests/fixtures/py3k/has_errors.py'

    def setUp(self):
        self.problems = Problems()
        self.tool = Py3k(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('test.js'))
        self.assertFalse(self.tool.match_file('dir/name/test.js'))
        self.assertTrue(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('dir/name/test.py'))

    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures.no_errors])
        eq_([], self.problems.all(self.fixtures.no_errors))

    @needs_py2
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures.has_errors])
        problems = self.problems.all(self.fixtures.has_errors)
        eq_(2, len(problems))

        fname = self.fixtures.has_errors
        eq_([
            Comment(fname, 6, 6, 'E1601 print statement used'),
            Comment(fname, 11, 11,
                    'W1638 range built-in referenced when not iterating')
        ], problems)

    @needs_py2
    def test_process_files_two_files(self):
        self.tool.process_files([self.fixtures.no_errors,
                                 self.fixtures.has_errors])

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

        problems = self.problems.all(self.fixtures.has_errors)
        eq_(2, len(problems))

        fname = self.fixtures.has_errors
        eq_([
            Comment(fname, 6, 6, 'E1601 print statement used'),
            Comment(fname, 11, 11,
                    'W1638 range built-in referenced when not iterating')
        ], problems)
Example #28
0
class TestPy3k(TestCase):

    needs_py2 = skipIf(not_python2, 'Cannot run in python3')

    class fixtures:
        no_errors = 'tests/fixtures/py3k/no_errors.py'
        has_errors = 'tests/fixtures/py3k/has_errors.py'

    def setUp(self):
        self.problems = Problems()
        self.tool = Py3k(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('test.js'))
        self.assertFalse(self.tool.match_file('dir/name/test.js'))
        self.assertTrue(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('dir/name/test.py'))

    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures.no_errors])
        eq_([], self.problems.all(self.fixtures.no_errors))

    @needs_py2
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures.has_errors])
        problems = self.problems.all(self.fixtures.has_errors)
        eq_(2, len(problems))

        fname = self.fixtures.has_errors
        eq_([
            Comment(fname, 6, 6, 'E1601 print statement used'),
            Comment(fname, 11, 11,
                    'W1638 range built-in referenced when not iterating')
        ], problems)

    @needs_py2
    def test_process_files_two_files(self):
        self.tool.process_files(
            [self.fixtures.no_errors, self.fixtures.has_errors])

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

        problems = self.problems.all(self.fixtures.has_errors)
        eq_(2, len(problems))

        fname = self.fixtures.has_errors
        eq_([
            Comment(fname, 6, 6, 'E1601 print statement used'),
            Comment(fname, 11, 11,
                    'W1638 range built-in referenced when not iterating')
        ], problems)
Example #29
0
class TestRubocop(TestCase):
    needs_rubocop = skipIf(rubocop_missing, "Missing rubocop, cannot run")

    fixtures = ["tests/fixtures/rubocop/no_errors.rb", "tests/fixtures/rubocop/has_errors.rb"]

    def setUp(self):
        self.problems = Problems()
        self.tool = Rubocop(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file("test.py"))
        self.assertFalse(self.tool.match_file("dir/name/test.py"))
        self.assertTrue(self.tool.match_file("test.rb"))
        self.assertTrue(self.tool.match_file("dir/name/test.rb"))

    @needs_rubocop
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[0]))

    @needs_rubocop
    def test_process_files__one_file_fail(self):
        linty_filename = abspath(self.fixtures[1])
        self.tool.process_files([linty_filename])

        problems = self.problems.all(linty_filename)
        expected = Comment(linty_filename, 4, 4, "C: Trailing whitespace detected.")
        eq_(expected, problems[1])

    @needs_rubocop
    def test_process_files_two_files(self):
        self.tool.process_files(self.fixtures)

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

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

    @needs_rubocop
    def test_process_files_one_file_fail_display_cop_names(self):
        options = {"display_cop_names": "True"}
        self.tool = Rubocop(self.problems, options)
        linty_filename = abspath(self.fixtures[1])
        self.tool.process_files([linty_filename])

        problems = self.problems.all(linty_filename)
        expected = Comment(linty_filename, 4, 4, "C: Style/TrailingWhitespace: Trailing whitespace detected.")
        eq_(expected, problems[1])
Example #30
0
class TestCredo(TestCase):

    fixtures = [
        'tests/fixtures/credo/no_errors.ex',
        'tests/fixtures/credo/has_errors.ex',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Credo(self.problems, {}, root_dir)

    def test_version(self):
        assert self.tool.version != ''

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('test.js'))
        self.assertFalse(self.tool.match_file('dir/name/test.js'))
        self.assertTrue(self.tool.match_file('test.ex'))
        self.assertTrue(self.tool.match_file('test.exs'))
        self.assertTrue(self.tool.match_file('dir/name/test.ex'))
        self.assertTrue(self.tool.match_file('dir/name/test.exs'))

    def test_create_command_types(self):
        self.tool.options = {
            'all': True,
            'all-priorities': 'yes',
            'strict': 1,
        }
        command = self.tool.create_command()
        self.assertTrue('--all' in command)
        self.assertTrue('--all-priorities' in command)
        self.assertTrue('--strict' in command)

    @requires_image('credo')
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        self.assertEqual([], self.problems.all(self.fixtures[0]))

    @requires_image('credo')
    def test_process_files__one_file_fail(self):
        self.tool.process_files([self.fixtures[1]])
        problems = self.problems.all(self.fixtures[1])
        self.assertEqual(1, len(problems))
        fname = self.fixtures[1]
        expected = Comment(fname, 1, 1,
                           'Modules should have a @moduledoc tag.')
        self.assertEqual(expected, problems[0])
Example #31
0
class TestCommitCheck(TestCase):

    fixture = load_fixture("commits.json")

    def setUp(self):
        self.fixture_data = Resource.loads(self.fixture)
        self.problems = Problems()
        self.tool = Commitcheck(self.problems)

    def test_execute_commits__no_pattern(self):
        self.tool.options["pattern"] = ""
        self.tool.execute_commits(self.fixture_data)
        eq_(0, len(self.problems), "Empty pattern does not find issues")

    def test_execute_commits__broken_regex(self):
        self.tool.options["pattern"] = "(.*"
        self.tool.execute_commits(self.fixture_data)
        eq_(0, len(self.problems), "Empty pattern does not find issues")

    def test_execute_commits__match(self):
        self.tool.options["pattern"] = "\w+"
        self.tool.execute_commits(self.fixture_data)
        eq_(0, len(self.problems), "Commits that do match are ok")

        self.tool.options["pattern"] = "bugs?"
        self.tool.execute_commits(self.fixture_data)
        eq_(0, len(self.problems), "Commits that do match are ok")

    def test_execute_commits__no_match(self):
        self.tool.options["pattern"] = "\d+"
        self.tool.execute_commits(self.fixture_data)
        eq_(1, len(self.problems), "Commits that do not match cause errors")
        msg = (
            "The following commits had issues. "
            "The pattern \d+ was not found in:\n"
            "* 6dcb09b5b57875f334f61aebed695e2e4193db5e\n"
        )
        expected = IssueComment(msg)
        eq_(expected, self.problems.all()[0])

    def test_execute_commits__custom_message(self):
        self.tool.options["pattern"] = "\d+"
        self.tool.options["message"] = "You are bad."
        self.tool.execute_commits(self.fixture_data)
        eq_(1, len(self.problems), "Commits that do not match cause errors")
        msg = "You are bad. The pattern \d+ was not found in:\n" "* 6dcb09b5b57875f334f61aebed695e2e4193db5e\n"
        expected = IssueComment(msg)
        eq_(expected, self.problems.all()[0])
Example #32
0
class TestCredo(TestCase):

    fixtures = [
        'tests/fixtures/credo/no_errors.ex',
        'tests/fixtures/credo/has_errors.ex',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Credo(self.problems, {}, root_dir)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('test.js'))
        self.assertFalse(self.tool.match_file('dir/name/test.js'))
        self.assertTrue(self.tool.match_file('test.ex'))
        self.assertTrue(self.tool.match_file('test.exs'))
        self.assertTrue(self.tool.match_file('dir/name/test.ex'))
        self.assertTrue(self.tool.match_file('dir/name/test.exs'))

    def test_create_command_types(self):
        self.tool.options = {
            'all': True,
            'all-priorities': 'yes',
            'strict': 1,
        }
        command = self.tool.create_command()
        self.assertTrue('--all' in command)
        self.assertTrue('--all-priorities' in command)
        self.assertTrue('--strict' in command)

    @requires_image('credo')
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        self.assertEqual([], self.problems.all(self.fixtures[0]))

    @requires_image('credo')
    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])
Example #33
0
class TestCommitCheck(TestCase):

    fixture = load_fixture('commits.json')

    def setUp(self):
        self.fixture_data = create_commits(self.fixture)
        self.problems = Problems()
        self.tool = Commitcheck(self.problems)

    def test_execute_commits__no_pattern(self):
        self.tool.options['pattern'] = ''
        self.tool.execute_commits(self.fixture_data)
        eq_(0, len(self.problems), 'Empty pattern does not find issues')

    def test_execute_commits__broken_regex(self):
        self.tool.options['pattern'] = '(.*'
        self.tool.execute_commits(self.fixture_data)
        eq_(0, len(self.problems), 'Empty pattern does not find issues')

    def test_execute_commits__match(self):
        self.tool.options['pattern'] = '\w+'
        self.tool.execute_commits(self.fixture_data)
        eq_(0, len(self.problems), 'Commits that do match are ok')

        self.tool.options['pattern'] = 'bugs?'
        self.tool.execute_commits(self.fixture_data)
        eq_(0, len(self.problems), 'Commits that do match are ok')

    def test_execute_commits__no_match(self):
        self.tool.options['pattern'] = '\d+'
        self.tool.execute_commits(self.fixture_data)
        eq_(1, len(self.problems), 'Commits that do not match cause errors')
        msg = (
            'The following commits had issues. '
            'The pattern \d+ was not found in:\n'
            '* 6dcb09b5b57875f334f61aebed695e2e4193db5e\n')
        expected = IssueComment(msg)
        eq_(expected, self.problems.all()[0])

    def test_execute_commits__custom_message(self):
        self.tool.options['pattern'] = '\d+'
        self.tool.options['message'] = 'You are bad.'
        self.tool.execute_commits(self.fixture_data)
        eq_(1, len(self.problems), 'Commits that do not match cause errors')
        msg = ('You are bad. The pattern \d+ was not found in:\n'
               '* 6dcb09b5b57875f334f61aebed695e2e4193db5e\n')
        expected = IssueComment(msg)
        eq_(expected, self.problems.all()[0])
Example #34
0
    def test(self):
        problems = Problems()
        text = """
/src/file.py:1:1: A message.
/src/dir/file.text:10:1: Another message
"""
        tools.process_quickfix(problems, text.splitlines(), lambda x: x)
        assert len(problems) == 2
        filepy = problems.all('/src/file.py')[0]
        assert 1 == filepy.position
        assert 1 == filepy.line
        assert 'A message.' == filepy.body

        filetext = problems.all('/src/dir/file.text')[0]
        assert 10 == filetext.position
        assert 10 == filetext.line
        assert 'Another message' == filetext.body
Example #35
0
class TestXo(TestCase):

    needs_xo = skipIf(xo_missing, 'Needs xo to run')

    def setUp(self):
        self.problems = Problems()
        options = {'ignore': ''}
        self.tool = Xo(self.problems, options)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('test.jsx'))
        self.assertTrue(self.tool.match_file('dir/name/test.js'))

    @needs_xo
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @needs_xo
    def test_process_files_pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        eq_([], self.problems.all(FILE_WITH_NO_ERRORS))

    @needs_xo
    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 = ("Filename is not in kebab case. Rename it to `has-errors.js`."
               " (unicorn/filename-case)\n"
               "Unexpected var, use let or const instead. (no-var)\n"
               "'foo' is assigned a value but never used. (no-unused-vars)\n"
               "'bar' is not defined. (no-undef)\n"
               "Missing semicolon. (semi)")
        expected = Comment(FILE_WITH_ERRORS, 2, 2, msg)
        eq_(expected, problems[0])

        msg = ("Unexpected alert. (no-alert)\n"
               "'alert' is not defined. (no-undef)\n"
               "Strings must use singlequote. (quotes)")
        expected = Comment(FILE_WITH_ERRORS, 4, 4, msg)
        eq_(expected, problems[1])
Example #36
0
    def test_invalid_content(self):
        problems = Problems()
        text = """
Error: No such file or directory: /src/main.rb
/src/readme.txt:8:1: Bad words.
"""
        tools.process_quickfix(problems, text.splitlines(), lambda x: x)
        assert len(problems) == 1
        assert 8 == problems.all('/src/readme.txt')[0].line
Example #37
0
class TestFoodcritic(TestCase):

    fixtures = [
        'tests/fixtures/foodcritic/noerrors',
        'tests/fixtures/foodcritic/errors',
    ]

    def setUp(self):
        self.problems = Problems()

    def test_version(self):
        self.tool = Foodcritic(self.problems, {}, root_dir)
        assert self.tool.version != ''

    @requires_image('ruby2')
    def test_process_cookbook_pass__no_path(self):
        self.tool = Foodcritic(self.problems,
                               {},
                               os.path.join(root_dir, self.fixtures[0]))
        self.tool.process_files(None)
        self.assertEqual([], self.problems.all())

    @requires_image('ruby2')
    def test_process_cookbook_pass(self):
        self.tool = Foodcritic(self.problems,
                               {'path': self.fixtures[0]},
                               root_dir)
        self.tool.process_files(None)
        self.assertEqual([], self.problems.all())

    @requires_image('ruby2')
    def test_process_cookbook_fail(self):
        self.tool = Foodcritic(self.problems,
                               {'path': self.fixtures[1]},
                               root_dir)
        self.tool.process_files(None)
        problems = self.problems.all()
        self.assertEqual(5, len(problems))

        expected = Comment(
            'tests/fixtures/foodcritic/errors/recipes/apache2.rb', 1, 1,
            'FC007: Ensure recipe dependencies are reflected in cookbook '
            'metadata')
        self.assertEqual(expected, problems[1])
Example #38
0
class TestPuppet(TestCase):
    needs_puppet = skipIf(puppet_missing, 'Missing puppet-lint, cannot run')

    fixtures = [
        'tests/fixtures/puppet/no_errors.pp',
        'tests/fixtures/puppet/has_errors.pp',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Puppet(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertTrue(self.tool.match_file('test.pp'))
        self.assertTrue(self.tool.match_file('dir/name/test.pp'))

    @needs_puppet
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[0]))

    @needs_puppet
    def test_process_files__one_file_fail(self):
        filename = abspath(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'))
        eq_(expected_problems, problems)

    @needs_puppet
    def test_process_files_two_files(self):
        self.tool.process_files(self.fixtures)

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

        freshly_laundered_filename = abspath(self.fixtures[0])
        eq_([], self.problems.all(freshly_laundered_filename))
Example #39
0
class TestPuppet(TestCase):
    needs_puppet = skipIf(puppet_missing, 'Missing puppet-lint, cannot run')

    fixtures = [
        'tests/fixtures/puppet/no_errors.pp',
        'tests/fixtures/puppet/has_errors.pp',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Puppet(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertTrue(self.tool.match_file('test.pp'))
        self.assertTrue(self.tool.match_file('dir/name/test.pp'))

    @needs_puppet
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[0]))

    @needs_puppet
    def test_process_files__one_file_fail(self):
        filename = abspath(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'))
        eq_(expected_problems, problems)

    @needs_puppet
    def test_process_files_two_files(self):
        self.tool.process_files(self.fixtures)

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

        freshly_laundered_filename = abspath(self.fixtures[0])
        eq_([], self.problems.all(freshly_laundered_filename))
Example #40
0
    def test_extra_colons(self):
        problems = Problems()
        text = """
/src/styles.css:8:1: invalid selector .thing::before
"""
        tools.process_quickfix(problems, text.splitlines(), lambda x: x)
        assert len(problems) == 1
        error = problems.all('/src/styles.css')[0]
        assert 8 == error.line
        assert 'invalid selector .thing::before' == error.body
Example #41
0
class TestStandardjs(TestCase):

    def setUp(self):
        self.problems = Problems()
        options = {}
        self.tool = Standardjs(self.problems, options, root_dir)

    def test_version(self):
        assert self.tool.version != ''

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('dir/name/test.js'))

    @requires_image('nodejs')
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @requires_image('nodejs')
    def test_process_files_pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        self.assertEqual([], self.problems.all(FILE_WITH_NO_ERRORS))

    @requires_image('nodejs')
    def test_process_files_fail(self):
        self.tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        self.assertEqual(2, len(problems))

        msg = ("'foo' is assigned a value but never used.\n"
               "'bar' is not defined.")
        expected = Comment(FILE_WITH_ERRORS, 2, 2, msg)
        self.assertEqual(expected, problems[0])

        msg = ("'alert' is not defined.\n"
               'Strings must use singlequote.\n'
               'Extra semicolon.')
        expected = Comment(FILE_WITH_ERRORS, 4, 4, msg)
        self.assertEqual(expected, problems[1])
class TestStandardjs(TestCase):

    needs_standardjs = skipIf(standardjs_missing, 'Needs standardjs to run')

    def setUp(self):
        self.problems = Problems()
        options = {}
        self.tool = Standardjs(self.problems, options)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('dir/name/test.js'))

    @needs_standardjs
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @needs_standardjs
    def test_process_files_pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        eq_([], self.problems.all(FILE_WITH_NO_ERRORS))

    @needs_standardjs
    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.\n"
               "'bar' is not defined.")
        expected = Comment(FILE_WITH_ERRORS, 2, 2, msg)
        eq_(expected, problems[0])

        msg = ("'alert' is not defined.\n"
               'Strings must use singlequote.\n'
               'Extra semicolon.')
        expected = Comment(FILE_WITH_ERRORS, 4, 4, msg)
        eq_(expected, problems[1])
Example #43
0
class TestStandardjs(TestCase):

    needs_standardjs = skipIf(standardjs_missing, 'Needs standardjs to run')

    def setUp(self):
        self.problems = Problems()
        options = {}
        self.tool = Standardjs(self.problems, options)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('dir/name/test.js'))

    @needs_standardjs
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @needs_standardjs
    def test_process_files_pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        eq_([], self.problems.all(FILE_WITH_NO_ERRORS))

    @needs_standardjs
    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.\n"
               "'bar' is not defined.")
        expected = Comment(FILE_WITH_ERRORS, 2, 2, msg)
        eq_(expected, problems[0])

        msg = ("'alert' is not defined.\n"
               'Strings must use singlequote.\n'
               'Extra semicolon.')
        expected = Comment(FILE_WITH_ERRORS, 4, 4, msg)
        eq_(expected, problems[1])
Example #44
0
    def test_run_timeout_error(self, mock_docker):
        mock_docker.side_effect = TimeoutError("Read timed out. (read timeout=300)")
        config = build_review_config(simple_ini)
        problems = Problems()
        files = ['./tests/fixtures/pep8/has_errors.py']
        tool_list = tools.factory(config, problems, root_dir)
        tools.run(tool_list, files, [])

        errors = problems.all()
        assert 1 == len(errors)
        assert 'timed out during' in errors[0].body
        assert 'run pep8 linter' in errors[0].body
Example #45
0
    def test_add__with_diff_containing_block_offset(self):
        res = Resource.loads(self.block_offset)
        changes = DiffCollection(res)

        problems = Problems(changes=changes)
        line_num = 32
        problems.add('somefile.py', line_num, 'Not good')
        eq_(1, len(problems))

        result = problems.all('somefile.py')
        eq_(changes.line_position('somefile.py', line_num), result[0].position,
            'Offset should be transformed to match value in changes')
Example #46
0
    def test_add__with_diff_containing_block_offset(self):
        res = [PullFile(f) for f in json.loads(self.block_offset)]
        changes = DiffCollection(res)

        problems = Problems(changes=changes)
        line_num = 32
        problems.add('somefile.py', line_num, 'Not good')
        eq_(1, len(problems))

        result = problems.all('somefile.py')
        eq_(changes.line_position('somefile.py', line_num), result[0].position,
            'Offset should be transformed to match value in changes')
Example #47
0
class TestFoodcritic(TestCase):

    fixtures = [
        'tests/fixtures/foodcritic/noerrors',
        'tests/fixtures/foodcritic/errors',
    ]

    def setUp(self):
        self.problems = Problems()

    @requires_image('ruby2')
    def test_process_cookbook_pass__no_path(self):
        self.tool = Foodcritic(self.problems,
                               {},
                               os.path.join(root_dir, self.fixtures[0]))
        self.tool.process_files(None)
        self.assertEqual([], self.problems.all())

    @requires_image('ruby2')
    def test_process_cookbook_pass(self):
        self.tool = Foodcritic(self.problems,
                               {'path': self.fixtures[0]},
                               root_dir)
        self.tool.process_files(None)
        self.assertEqual([], self.problems.all())

    @requires_image('ruby2')
    def test_process_cookbook_fail(self):
        self.tool = Foodcritic(self.problems,
                               {'path': self.fixtures[1]},
                               root_dir)
        self.tool.process_files(None)
        problems = self.problems.all()
        self.assertEqual(5, len(problems))

        expected = Comment(
            'tests/fixtures/foodcritic/errors/recipes/apache2.rb', 1, 1,
            'FC007: Ensure recipe dependencies are reflected in cookbook '
            'metadata')
        self.assertEqual(expected, problems[1])
Example #48
0
    def test_run_timeout_error(self, mock_docker):
        mock_docker.side_effect = TimeoutError(
            "Read timed out. (read timeout=300)")
        config = build_review_config(simple_ini)
        problems = Problems()
        files = ['./tests/fixtures/pep8/has_errors.py']
        tool_list = tools.factory(config, problems, root_dir)
        tools.run(tool_list, files, [])

        errors = problems.all()
        assert 1 == len(errors)
        assert 'timed out during' in errors[0].body
        assert 'run pep8 linter' in errors[0].body
Example #49
0
class TestCredo(TestCase):

    fixtures = [
        'tests/fixtures/credo/no_errors.ex',
        'tests/fixtures/credo/has_errors.ex',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Credo(self.problems, {}, root_dir)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('test.js'))
        self.assertFalse(self.tool.match_file('dir/name/test.js'))
        self.assertTrue(self.tool.match_file('test.ex'))
        self.assertTrue(self.tool.match_file('test.exs'))
        self.assertTrue(self.tool.match_file('dir/name/test.ex'))
        self.assertTrue(self.tool.match_file('dir/name/test.exs'))

    @requires_image('credo')
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        eq_([], self.problems.all(self.fixtures[0]))

    @requires_image('credo')
    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, 3, 3,
                           'Pipe chain should start with a raw value.')
        eq_(expected, problems[0])
        expected = Comment(fname, 1, 1,
                           'Modules should have a @moduledoc tag.')
        eq_(expected, problems[1])
Example #50
0
 def test_process_undefined(self):
     problems = Problems()
     xml = """
 <checkstyle>
   <file name="other_things.py">
     <error line="undefined" message="Not good" />
   </file>
 </checkstyle>
 """
     tools.process_checkstyle(problems, xml, lambda x: x)
     self.assertEqual(1, len(problems))
     errors = problems.all('other_things.py')
     assert len(errors) == 1, errors
     assert errors[0].line == Comment.FIRST_LINE_IN_DIFF
     assert errors[0].body == 'Not good'
Example #51
0
class TestGpg(TestCase):
    def setUp(self):
        self.problems = Problems()
        self.tool = Gpg(self.problems, {}, root_dir)

    @requires_image('gpg')
    def test_check_dependencies(self):
        eq_(True, self.tool.check_dependencies())

    @requires_image('gpg')
    def test_execute(self):
        self.tool.execute_commits([])

        comments = self.problems.all()
        if len(comments):
            assert_in('gpg signature', comments[0].body)
Example #52
0
class TestGpg(TestCase):

    def setUp(self):
        self.problems = Problems()
        self.tool = Gpg(self.problems, {}, root_dir)

    @requires_image('gpg')
    def test_check_dependencies(self):
        self.assertEqual(True, self.tool.check_dependencies())

    @requires_image('gpg')
    def test_execute(self):
        self.tool.execute_commits([])

        comments = self.problems.all()
        if len(comments):
            self.assertIn('gpg signature', comments[0].body)
Example #53
0
    def test_add__with_diff_containing_block_offset(self):
        res = [
            PullFile(f, self.session) for f in json.loads(self.block_offset)
        ]
        changes = DiffCollection(res)

        problems = Problems(changes=changes)
        line_num = 32
        problems.add('somefile.py', line_num, 'Not good')
        self.assertEqual(1, len(problems))

        result = problems.all('somefile.py')
        first_result = result[0]
        self.assertIsInstance(first_result, Comment)
        self.assertEqual(
            changes.line_position('somefile.py',
                                  line_num), first_result.position,
            'Offset should be transformed to match value in changes')
Example #54
0
    def test_add__with_diff_containing_block_offset(self):
        res = [
            PullFile(f, self.session) for f in json.loads(self.block_offset)
        ]
        changes = DiffCollection(res)

        problems = Problems(changes=changes)
        line_num = 32
        problems.add('somefile.py', line_num, 'Not good')
        self.assertEqual(1, len(problems))

        result = problems.all('somefile.py')
        first_result = result[0]
        self.assertIsInstance(first_result, Comment)
        self.assertEqual(
            changes.line_position('somefile.py', line_num),
            first_result.position,
            'Offset should be transformed to match value in changes'
        )
Example #55
0
    def test_process_checkstyle(self):
        problems = Problems()
        xml = """
    <checkstyle>
      <file name="things.py">
        <error line="1" message="Not good" />
        <error line="2" message="Also not good" />
      </file>
      <file name="other_things.py">
        <error line="3" message="Not good" />
      </file>
    </checkstyle>
    """
        tools.process_checkstyle(problems, xml, lambda x: x)
        self.assertEqual(3, len(problems))

        things = problems.all('things.py')
        self.assertEqual(2, len(things))
        self.assertEqual(1, things[0].line)
        self.assertEqual('Not good', things[0].body)
Example #56
0
    def test_process_checkstyle__comma_lines(self):
        problems = Problems()
        xml = """
    <checkstyle>
      <file name="other_things.py">
        <error line="3,4,5" message="Not good" />
      </file>
    </checkstyle>
    """
        tools.process_checkstyle(problems, xml, lambda x: x)
        self.assertEqual(3, len(problems))

        things = problems.all('other_things.py')
        self.assertEqual(3, len(things))
        self.assertEqual(3, things[0].line)
        self.assertEqual('Not good', things[0].body)

        self.assertEqual(4, things[1].line)
        self.assertEqual('Not good', things[1].body)

        self.assertEqual(5, things[2].line)
        self.assertEqual('Not good', things[2].body)
Example #57
0
class TestTslint(TestCase):

    needs_tslint = skipIf(tslint_missing, 'Needs tslint to run')

    def setUp(self):
        self.problems = Problems()
        options = {
            'config': 'tests/fixtures/tslint/tslint_good.json'
        }
        self.tool = Tslint(self.problems, options)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertFalse(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('test.ts'))
        self.assertTrue(self.tool.match_file('dir/name/test.ts'))

    @needs_tslint
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @needs_tslint
    def test_process_files__pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        eq_([], self.problems.all(FILE_WITH_NO_ERRORS))

    @needs_tslint
    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 = ("Shadowed name: 'range'\n"
               "Spaces before function parens are disallowed")
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        eq_(expected, problems[0])

    @needs_tslint
    def test_process_files__invalid_config(self):
        tool = Tslint(self.problems, options={'config': 'invalid-file'})
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all()
        eq_(1, len(problems), 'Invalid config returns 1 error')
        msg = ('Your tslint config file is missing or invalid. '
               'Please ensure that `invalid-file` exists and is valid JSON.')
        expected = [IssueComment(msg)]
        eq_(expected, problems)

    @needs_tslint
    def test_process_files__no_config_set_no_default(self):
        tool = Tslint(self.problems, options={})
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all()
        eq_(1, len(problems), 'Missing config returns 1 error')
        msg = ('Your tslint config file is missing or invalid. '
               'Please ensure that `tslint.json` exists and is valid JSON.')
        expected = [IssueComment(msg)]
        eq_(expected, problems)

    @needs_tslint
    def test_process_files_with_config(self):
        options = {
            'config': 'tests/fixtures/tslint/tslint_good.json'
        }
        tool = Tslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all(FILE_WITH_ERRORS)

        msg = ("Shadowed name: 'range'\n"
               'Spaces before function parens are disallowed')
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        eq_(expected, problems[0])

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

    @needs_tslint
    def test_process_output__ancestor_directory(self):
        # Simulate XML with ../file in the output
        # which happens with tslint
        options = {
            'config': 'tests/fixtures/tslint/tslint_good.json'
        }
        restore = os.getcwd()
        tool = Tslint(self.problems, options, restore)
        xml = """<?xml version="1.0" encoding="utf-8"?>
<checkstyle version="4.3">
  <file name="../tests/fixtures/tslint/has_errors.ts">
    <error line="11" column="3" severity="error" message="bad code"
      source="failure.tslint.object-literal-sort-keys" />
  </file>
</checkstyle>"""
        os.chdir(os.path.join('.', 'lintreview'))
        tool._process_output(xml, [FILE_WITH_ERRORS])
        os.chdir(restore)

        problems = self.problems.all(FILE_WITH_ERRORS)
        expected = Comment(FILE_WITH_ERRORS, 11, 11, 'bad code')
        eq_(expected, problems[0])

    @needs_tslint
    def test_process_files__invalid_rule(self):
        options = {
            'config': 'tests/fixtures/tslint/tslint_invalid_rule.json'
        }
        tool = Tslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all()
        eq_(1, len(problems))
        msg = ('Your tslint configuration output the following error:\n'
               '```\n'
               'Could not find implementations for the following rules '
               'specified in the configuration:\n'
               '    not_a_real_rule\n'
               'Try upgrading TSLint and/or ensuring that you have all '
               'necessary custom rules installed.\n'
               'If TSLint was recently upgraded, you may '
               'have old rules configured which need to be cleaned up.\n'
               '```')
        expected = [IssueComment(msg)]
        eq_(expected, problems)
Example #58
0
class TestEslint(TestCase):

    needs_eslint = skipIf(eslint_missing, 'Needs eslint to run')

    def setUp(self):
        self.problems = Problems()
        options = {
            'config': 'tests/fixtures/eslint/recommended_config.json'
        }
        self.tool = Eslint(self.problems, options)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('test.jsx'))
        self.assertTrue(self.tool.match_file('dir/name/test.js'))

    @needs_eslint
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @needs_eslint
    def test_process_files_pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        eq_([], self.problems.all(FILE_WITH_NO_ERRORS))

    @needs_eslint
    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])

    @needs_eslint
    def test_process_files__config_file_missing(self):
        tool = Eslint(self.problems, options={'config': 'invalid-file'})
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all()
        eq_(1, len(problems), 'Invalid config returns 1 error')
        msg = ('Your eslint config file is missing or invalid. '
               'Please ensure that `invalid-file` exists and is valid.')
        expected = [IssueComment(msg)]
        eq_(expected, problems)

    @needs_eslint
    def test_process_files_uses_default_config(self):
        tool = Eslint(self.problems, options={})
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        eq_(2, len(problems), 'With no config file there should be no errors.')

    @needs_eslint
    def test_process_files__invalid_config(self):
        options = {'config': 'tests/fixtures/eslint/invalid.json'}
        tool = Eslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all()
        eq_(1, len(problems), 'Invalid config should report an error')
        error = problems[0]
        ok_('Your eslint configuration output the following error'
            in error.body)
        ok_("Cannot find module 'eslint-config-invalid-rules'" in error.body)

    @needs_eslint
    def test_process_files__missing_plugin(self):
        options = {'config': 'tests/fixtures/eslint/missingplugin.json'}
        tool = Eslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all()
        eq_(1, len(problems), 'Invalid config should report an error')
        error = problems[0]
        ok_('Your eslint configuration output the following error'
            in error.body)
        ok_('ESLint couldn\'t find the plugin "eslint-plugin-mocha"'
            in error.body)

    @needs_eslint
    def test_process_files_with_config(self):
        options = {
            'config': 'tests/fixtures/eslint/config.json'
        }
        tool = Eslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all(FILE_WITH_ERRORS)

        msg = ("'foo' is assigned a value but never used. (no-unused-vars)\n"
               "'bar' is not defined. (no-undef)\n"
               "Missing semicolon. (semi)")
        expected = [Comment(FILE_WITH_ERRORS, 2, 2, msg)]
        eq_(expected, problems)
Example #59
0
class TestStylelint(TestCase):

    fixtures = [
        'tests/fixtures/stylelint/no_errors.scss',
        'tests/fixtures/stylelint/has_errors.scss',
        'tests/fixtures/stylelint/has_more_errors.scss',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Stylelint(self.problems, base_path=root_dir)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.sass'))
        self.assertTrue(self.tool.match_file('dir/name/test.sass'))
        self.assertTrue(self.tool.match_file('dir/name/test.scss'))
        self.assertTrue(self.tool.match_file('dir/name/test.less'))
        self.assertTrue(self.tool.match_file('dir/name/test.css'))

    @requires_image('nodejs')
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @requires_image('nodejs')
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
        self.assertEqual([], self.problems.all(self.fixtures[0]))

    @requires_image('nodejs')
    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]
        error = ('Unexpected unknown at-rule "@include" '
                 '(at-rule-no-unknown) [error]')
        expected = Comment(fname, 2, 2, error)
        self.assertEqual(expected, problems[0])

    @requires_image('nodejs')
    def test_process_files__multiple_files(self):
        self.tool.process_files(self.fixtures)

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

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

        problems = self.problems.all(self.fixtures[2])
        self.assertEqual(2, len(problems))

    @requires_image('nodejs')
    def test_process_files_with_config(self):
        config = {
            'config': 'tests/fixtures/stylelint/stylelintrc.json'
        }

        tool = Stylelint(self.problems, config, root_dir)
        tool.process_files([self.fixtures[1]])

        problems = self.problems.all()
        self.assertEqual(6, len(problems),
                         'Config file should change error count')

    @requires_image('nodejs')
    def test_process_files_with_invalid_config(self):
        config = {
            'config': 'tests/fixtures/stylelint/badconfig'
        }
        tool = Stylelint(self.problems, config, root_dir)
        tool.process_files([self.fixtures[1]])

        problems = self.problems.all()
        self.assertEqual(1, len(problems),
                         'Should capture missing config error')

        self.assertIn('Your configuration file', problems[0].body)
        self.assertIn('ENOENT', problems[0].body)

    def test_has_fixer__not_enabled(self):
        tool = Stylelint(self.problems, {})
        self.assertEqual(False, tool.has_fixer())

    def test_has_fixer__enabled(self):
        tool = Stylelint(self.problems, {'fixer': True}, root_dir)
        self.assertEqual(True, tool.has_fixer())

    @requires_image('nodejs')
    def test_execute_fixer(self):
        fixture = self.fixtures[1]
        tool = Stylelint(self.problems, {
            'config': 'tests/fixtures/stylelint/stylelintrc.json',
            'fixer': True,
        }, root_dir)
        original = read_file(fixture)
        tool.execute_fixer([fixture])

        updated = read_and_restore_file(fixture, original)
        assert original != updated, 'File content should change.'
Example #60
0
class TestEslint(TestCase):

    needs_eslint = skipIf(eslint_missing, 'Needs eslint to run')

    def setUp(self):
        self.problems = Problems()
        options = {
            'config': 'tests/fixtures/eslint/recommended_config.json'
        }
        self.tool = Eslint(self.problems, options)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('dir/name/test.js'))

    @needs_eslint
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @needs_eslint
    def test_process_files_pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        eq_([], self.problems.all(FILE_WITH_NO_ERRORS))

    @needs_eslint
    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 defined 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])

    @needs_eslint
    def test_process_files_with_no_config(self):
        tool = Eslint(self.problems, options={})
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        eq_(0, len(problems), 'With no config file there should be no errors.')

    @needs_eslint
    def test_process_files_with_config(self):
        options = {
            'config': 'tests/fixtures/eslint/config.json'
        }
        tool = Eslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all(FILE_WITH_ERRORS)

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