Esempio n. 1
0
    def test_fetch_flake8(self):
        """Test whether commits are properly processed"""

        cq = CoQua('http://example.com',
                   self.git_path,
                   self.worktree_path,
                   entrypoint="perceval")
        commits = [
            commit for commit in cq.fetch(category=CATEGORY_COQUA_FLAKE8)
        ]

        self.assertEqual(len(commits), 6)
        self.assertFalse(os.path.exists(cq.worktreepath))

        commit = commits[0]
        self.assertEqual(commit['backend_name'], 'CoQua')
        self.assertEqual(commit['category'], CATEGORY_COQUA_FLAKE8)
        result = commit['data']['analysis']
        self.assertIn('warnings', result)
        self.assertTrue(type(result['warnings']), int)
        self.assertNotIn('lines', result)

        cq = CoQua('http://example.com',
                   self.git_path,
                   self.worktree_path,
                   entrypoint="unknown")
Esempio n. 2
0
    def test_fetch_empty(self):
        """Test whether no commits are returned"""

        cq = CoQua('http://example.com', self.git_path, self.worktree_path,
                   exec_path=JADOLINT_PATH, in_paths=['unknown'])
        commits = [commit for commit in cq.fetch(category=CATEGORY_COQUA_JADOLINT)]
        self.assertEqual(commits, [])
Esempio n. 3
0
    def test_fetch_unknown(self):
        """Test whether commits are properly processed"""

        cq = CoQua('http://example.com', self.git_path,
                   self.worktree_path, entrypoint="perceval")

        with self.assertRaises(GraalError):
            _ = cq.fetch(category="unknown")
Esempio n. 4
0
    def test_fetch_error(self):
        """Test whether an exception is thrown when the module isn't defined and the category is pylint or flake8"""

        cq = CoQua('http://example.com', self.git_path, self.worktree_path, tag='test')
        with self.assertRaises(GraalError):
            _ = [item for item in cq.fetch(category=CATEGORY_COQUA_PYLINT)]

        with self.assertRaises(GraalError):
            _ = [item for item in cq.fetch(category=CATEGORY_COQUA_FLAKE8)]
Esempio n. 5
0
    def test_fetch_module_not_found(self):
        """Test whether a warning is thrown when the module is not found"""

        cq = CoQua('http://example.com', self.git_path,
                   self.worktree_path, entrypoint="unknown")

        with self.assertLogs(logger, level='WARNING') as cm:
            _ = [item for item in cq.fetch(category=CATEGORY_COQUA_PYLINT)]

            self.assertRegex(cm.output[0], '.*does not exist at commit.*')
Esempio n. 6
0
    def test_fetch_error(self):
        """Test whether an exception is thrown when the exec_path isn't defined and the category is jadolint"""

        cq = CoQua('http://example.com',
                   self.git_path,
                   self.worktree_path,
                   entrypoint="module",
                   tag='test')
        with self.assertRaises(GraalError):
            _ = [item for item in cq.fetch(category=CATEGORY_COQUA_JADOLINT)]
Esempio n. 7
0
    def test_initialization(self):
        """Test whether attributes are initializated"""

        cq = CoQua('http://example.com', self.git_path,
                   self.worktree_path, entrypoint="module", tag='test')
        self.assertEqual(cq.uri, 'http://example.com')
        self.assertEqual(cq.gitpath, self.git_path)
        self.assertEqual(cq.worktreepath, os.path.join(
            self.worktree_path, os.path.split(cq.gitpath)[1]))
        self.assertEqual(cq.origin, 'http://example.com')
        self.assertEqual(cq.tag, 'test')
        self.assertEqual(cq.entrypoint, "module")

        with self.assertRaises(GraalError):
            _ = CoQua('http://example.com', self.git_path,
                      self.worktree_path, details=True, tag='test')
Esempio n. 8
0
    def test_initialization(self):
        """Test whether attributes are initializated"""

        cq = CoQua('http://example.com', self.git_path, self.worktree_path, exec_path=JADOLINT_PATH, tag='test')
        self.assertEqual(cq.uri, 'http://example.com')
        self.assertEqual(cq.gitpath, self.git_path)
        self.assertEqual(cq.worktreepath, os.path.join(self.worktree_path, os.path.split(cq.gitpath)[1]))
        self.assertEqual(cq.origin, 'http://example.com')
        self.assertEqual(cq.tag, 'test')
        self.assertEqual(cq.exec_path, JADOLINT_PATH)
Esempio n. 9
0
    def test_metadata_category(self):
        """Test metadata_category"""
        item = {
            "Author": "Nishchith Shetty <*****@*****.**>",
            "AuthorDate": "Tue Feb 26 22:06:31 2019 +0530",
            "Commit": "Nishchith Shetty <*****@*****.**>",
            "CommitDate": "Tue Feb 26 22:06:31 2019 +0530",
            "analysis": [],
            "analyzer": "pylint",
            "commit": "5866a479587e8b548b0cb2d591f3a3f5dab04443",
            "message": "[copyright] Update copyright dates"
        }
        self.assertEqual(CoQua.metadata_category(item), CATEGORY_COQUA_PYLINT)

        item = {
            "Author": "Nishchith Shetty <*****@*****.**>",
            "AuthorDate": "Tue Feb 26 22:06:31 2019 +0530",
            "Commit": "Nishchith Shetty <*****@*****.**>",
            "CommitDate": "Tue Feb 26 22:06:31 2019 +0530",
            "analysis": [],
            "analyzer": "flake8",
            "commit": "5866a479587e8b548b0cb2d591f3a3f5dab04443",
            "message": "[copyright] Update copyright dates"
        }
        self.assertEqual(CoQua.metadata_category(item), CATEGORY_COQUA_FLAKE8)

        item = {
            "Author": "Nishchith Shetty <*****@*****.**>",
            "AuthorDate": "Tue Feb 26 22:06:31 2019 +0530",
            "Commit": "Nishchith Shetty <*****@*****.**>",
            "CommitDate": "Tue Feb 26 22:06:31 2019 +0530",
            "analysis": [],
            "analyzer": "unknown",
            "commit": "5866a479587e8b548b0cb2d591f3a3f5dab04443",
            "message": "[copyright] Update copyright dates"
        }
        with self.assertRaises(GraalError):
            _ = CoQua.metadata_category(item)
Esempio n. 10
0
    def test_fetch(self):
        """Test whether commits are properly processed"""

        cd = CoQua('http://example.com',
                   self.git_path,
                   self.worktree_path,
                   entrypoint="perceval")
        commits = [commit for commit in cd.fetch()]

        self.assertEqual(len(commits), 3)
        self.assertFalse(os.path.exists(cd.worktreepath))

        commit = commits[0]
        self.assertEqual(commit['backend_name'], 'CoQua')
        self.assertEqual(commit['category'], CATEGORY_COQUA)
        result = commit['data']['analysis']
        self.assertNotIn('modules', result)
        self.assertIn('quality', result)
        self.assertTrue(type(result['quality']), str)
        self.assertIn('num_modules', result)
        self.assertTrue(type(result['num_modules']), int)
        self.assertIn('warnings', result)
        self.assertTrue(type(result['warnings']), int)
Esempio n. 11
0
    def test_fetch(self):
        """Test whether commits are properly processed"""

        cq = CoQua('http://example.com', self.git_path, self.worktree_path,
                   exec_path=JADOLINT_PATH, in_paths=['Dockerfile'])
        commits = [commit for commit in cq.fetch(category=CATEGORY_COQUA_JADOLINT)]

        self.assertEqual(len(commits), 2)

        analysis = commits[0]['data']['analysis']
        self.assertIn('Dockerfile', analysis)
        expected_smells = [
            '/Dockerfile 5 DL4000 MAINTAINER is deprecated',
            '/Dockerfile 5 DL4000 MAINTAINER is deprecated',
            '/Dockerfile 5 DL4000 MAINTAINER is deprecated',
            '/Dockerfile 5 DL4000 MAINTAINER is deprecated',
            '/Dockerfile 5 DL4000 MAINTAINER is deprecated',
            '/Dockerfile 13 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 16 DL3008 Pin versions in apt-get install',
            '/Dockerfile 16 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 16 DL3014 Use the -y switch',
            '/Dockerfile 16 DL3015 Avoid additional packages by specifying --no-install-recommends',
            '/Dockerfile 32 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 34 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 34 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 37 DL3020 Use COPY instead of ADD for files and folders',
            '/Dockerfile 38 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 40 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 40 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 40 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 40 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 40 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 40 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 55 DL3000 Use absolute WORKDIR',
            '/Dockerfile 57 DL3025 Use arguments JSON notation for CMD and ENTRYPOINT arguments'
        ]

        analysis['Dockerfile'][SMELLS].sort()
        expected_smells.sort()
        self.assertListEqual(analysis['Dockerfile'][SMELLS], expected_smells)

        analysis = commits[1]['data']['analysis']
        self.assertIn('Dockerfile', analysis)
        expected_smells = [
            '/Dockerfile 5 DL4000 MAINTAINER is deprecated',
            '/Dockerfile 5 DL4000 MAINTAINER is deprecated',
            '/Dockerfile 5 DL4000 MAINTAINER is deprecated',
            '/Dockerfile 5 DL4000 MAINTAINER is deprecated',
            '/Dockerfile 5 DL4000 MAINTAINER is deprecated',
            '/Dockerfile 13 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 16 DL3008 Pin versions in apt-get install',
            '/Dockerfile 16 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 16 DL3014 Use the -y switch',
            '/Dockerfile 16 DL3015 Avoid additional packages by specifying --no-install-recommends',
            '/Dockerfile 33 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 35 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 35 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 38 DL3020 Use COPY instead of ADD for files and folders',
            '/Dockerfile 39 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 41 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 41 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 41 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 41 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 41 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 41 DL3009 Delete the apt-get lists after installing something',
            '/Dockerfile 56 DL3000 Use absolute WORKDIR',
            '/Dockerfile 58 DL3025 Use arguments JSON notation for CMD and ENTRYPOINT arguments'
        ]

        analysis['Dockerfile'][SMELLS].sort()
        expected_smells.sort()
        self.assertListEqual(analysis['Dockerfile'][SMELLS], expected_smells)