예제 #1
0
    def test_fetch(self):
        """Test whether commits are properly processed"""

        cd = CoDep('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'], 'CoDep')
        self.assertEqual(commit['category'], CATEGORY_CODEP)
        result = commit['data']['analysis']
        self.assertIn('classes', result)
        self.assertTrue(type(result['classes']), dict)
        self.assertIn('nodes', result['classes'])
        self.assertTrue(type(result['classes']['nodes']), list)
        self.assertIn('links', result['classes'])
        self.assertTrue(type(result['classes']['links']), list)
        self.assertIn('packages', result)
        self.assertTrue(type(result['packages']), dict)
        self.assertTrue(type(result['packages']['nodes']), list)
        self.assertIn('links', result['packages'])
        self.assertTrue(type(result['packages']['links']), list)
예제 #2
0
    def test_fetch_unknown_category(self):
        """Test whether an exception is thrown when the category is unknown"""

        cd = CoDep('http://example.com',
                   self.git_path,
                   self.worktree_path,
                   tag='test')
        with self.assertRaises(GraalError):
            _ = [item for item in cd.fetch(category="unknown")]
예제 #3
0
    def test_fetch_error(self):
        """Test whether an exception is thrown when the exec_path isn't defined and the category is jadolint"""

        cd = CoDep('http://example.com',
                   self.git_path,
                   self.worktree_path,
                   tag='test')
        with self.assertRaises(GraalError):
            _ = [item for item in cd.fetch(category=CATEGORY_CODEP_JADOLINT)]
예제 #4
0
    def test_fetch_error(self):
        """Test whether an exception is thrown when the entrypoint isn't defined and the category is pyreverse"""

        cd = CoDep('http://example.com',
                   self.git_path,
                   self.worktree_path,
                   details=True,
                   tag='test')
        with self.assertRaises(GraalError):
            _ = [item for item in cd.fetch()]
예제 #5
0
    def test_fetch_empty(self):
        """Test whether no commits are returned"""

        cd = CoDep('http://example.com',
                   self.git_path,
                   self.worktree_path,
                   exec_path=JADOLINT_PATH,
                   in_paths=['Unknown'])
        commits = [
            commit for commit in cd.fetch(category=CATEGORY_CODEP_JADOLINT)
        ]
        self.assertEqual(commits, [])
예제 #6
0
    def test_fetch_not_existing_module(self):
        """Test whether warning messages are logged when a module is not found"""

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

        with self.assertLogs(logger, level='WARNING') as cm:
            for commit in cd.fetch():
                self.assertRegex(
                    cm.output[-1],
                    'module path .* does not exist .* analysis will be skipped'
                )
                self.assertEqual(commit['data']['analysis'], {})
예제 #7
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": "pyreverse",
            "commit": "5866a479587e8b548b0cb2d591f3a3f5dab04443",
            "message": "[copyright] Update copyright dates"
        }
        self.assertEqual(CoDep.metadata_category(item),
                         CATEGORY_CODEP_PYREVERSE)

        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": "jadolint",
            "commit": "5866a479587e8b548b0cb2d591f3a3f5dab04443",
            "message": "[copyright] Update copyright dates"
        }
        self.assertEqual(CoDep.metadata_category(item),
                         CATEGORY_CODEP_JADOLINT)

        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):
            _ = CoDep.metadata_category(item)
예제 #8
0
    def test_fetch(self):
        """Test whether commits are properly processed"""

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

        self.assertEqual(len(commits), 2)

        analysis = commits[0]['data']['analysis']
        self.assertIn('Dockerfile', analysis)
        expected_deps = [
            'debian stretch-slim', 'bash', 'locales', 'gcc', 'git', 'git-core',
            'python3', 'python3-pip', 'python3-venv', 'python3-dev',
            'python3-gdbm', 'mariadb-client', 'unzip', 'curl', 'wget', 'sudo',
            'ssh'
        ]
        analysis['Dockerfile'][DEPENDENCIES].sort()
        expected_deps.sort()
        self.assertListEqual(analysis['Dockerfile'][DEPENDENCIES],
                             expected_deps)

        analysis = commits[1]['data']['analysis']
        self.assertIn('Dockerfile', analysis)
        expected_deps = [
            'debian stretch-slim', 'bash', 'locales', 'gcc', 'git', 'cloc',
            'git-core', 'python3', 'python3-pip', 'python3-venv',
            'python3-dev', 'python3-gdbm', 'mariadb-client', 'unzip', 'curl',
            'wget', 'sudo', 'ssh'
        ]
        analysis['Dockerfile'][DEPENDENCIES].sort()
        expected_deps.sort()
        self.assertListEqual(analysis['Dockerfile'][DEPENDENCIES],
                             expected_deps)
예제 #9
0
    def test_initialization(self):
        """Test whether attributes are initializated"""

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

        with self.assertRaises(GraalError):
            _ = CoDep('http://example.com',
                      self.git_path,
                      self.worktree_path,
                      details=True,
                      tag='test')
예제 #10
0
    def test_initialization(self):
        """Test whether attributes are initializated"""

        cd = CoDep('http://example.com',
                   self.git_path,
                   self.worktree_path,
                   exec_path=JADOLINT_PATH,
                   tag='test')
        self.assertEqual(cd.uri, 'http://example.com')
        self.assertEqual(cd.gitpath, self.git_path)
        self.assertEqual(
            cd.worktreepath,
            os.path.join(self.worktree_path,
                         os.path.split(cd.gitpath)[1]))
        self.assertEqual(cd.origin, 'http://example.com')
        self.assertEqual(cd.tag, 'test')
        self.assertEqual(cd.exec_path, JADOLINT_PATH)