Пример #1
0
    def __init__(self, details=False, kind=PYLINT):
        self.details = details
        self.kind = kind

        if kind == PYLINT:
            self.analyzer = PyLint()
        else:
            self.analyzer = Flake8()
Пример #2
0
    def test_analyze_error(self, check_output_mock):
        """Test whether an exception is thrown in case of errors"""

        check_output_mock.side_effect = subprocess.CalledProcessError(
            -1, "command", output=b'output')

        flake8 = Flake8()
        kwargs = {
            'module_path': os.path.join(self.repo_path, ANALYZER_TEST_FILE),
            'worktree_path': self.worktree_path,
            'details': False
        }
        _ = flake8.analyze(**kwargs)
Пример #3
0
    def test_analyze_no_details(self):
        """Test whether flake8 returns the expected fields data"""

        flake8 = Flake8()
        kwargs = {
            'module_path': os.path.join(self.repo_path, ANALYZER_TEST_FILE),
            'worktree_path': self.worktree_path,
            'details': False
        }
        result = flake8.analyze(**kwargs)

        self.assertNotIn('lines', result)
        self.assertIn('warnings', result)
        self.assertTrue(type(result['warnings']), int)
Пример #4
0
    def test_analyze_details(self):
        """Test whether flake8 returns the expected fields data"""

        flake8 = Flake8()
        kwargs = {
            'module_path': os.path.join(self.repo_path, "perceval"),
            'worktree_path': self.worktree_path,
            'details': True
        }
        result = flake8.analyze(**kwargs)

        self.assertIn('lines', result)
        self.assertTrue(type(result['lines']), list)
        self.assertIn('warnings', result)
        self.assertTrue(type(result['warnings']), int)
Пример #5
0
# creating a new worktree if not already present
if GraalRepository.exists(worktreepath):
    shutil.rmtree(worktreepath)

repo.worktree(worktreepath)

# preforming checkout at given SHA
repo.checkout(sha)

print("cloning done")

# Using flake8 to find errors if any

flk_args = {
    'module_path': os.path.join(os.sep, 'tmp', 'fossology'),
    'worktree_path': '/tmp/worktrees',
    'details': True
}

# instantiating flake8
flake8 = Flake8()

check = flake8.analyze(**flk_args)

print("flake 8 results: ")

for val in check['lines']:
    print('type:' + val['type_of_warning'] + '  line:' + val['line'] +
          '  column:' + val['column'] + '  desc:' + val['description'])