Exemplo n.º 1
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')

        lint = Lint()
        kwargs = {
            'module_path': os.path.join(self.repo_path, ANALYZER_TEST_FILE),
            'details': False
        }
        with self.assertRaises(GraalError):
            _ = lint.analyze(**kwargs)
Exemplo n.º 2
0
class ModuleAnalyzer:
    """Class to evaluate code quality in a Python project"""

    def __init__(self, details=False):
        self.details = details
        self.lint = Lint()

    def analyze(self, module_path):
        """Analyze the content of a module using Pylint

        :param folder_path: folder path

        :returns a dict containing the results of the analysis, like the one below
        {
          'code_quality': ..,
          'modules': [..]
        }
        """
        kwargs = {
            'module_path': module_path,
            'details': self.details
        }
        analysis = self.lint.analyze(**kwargs)

        return analysis
Exemplo n.º 3
0
    def test_analyze_no_details(self):
        """Test whether lint returns the expected fields data"""

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

        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)
Exemplo n.º 4
0
    def test_analyze_details(self):
        """Test whether lint returns the expected fields data"""

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

        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)
        self.assertIn('modules', result)
        self.assertTrue(type(result['modules']), dict)

        first_key = list(result['modules'].keys())[0]
        for md in result['modules'].get(first_key):
            self.assertTrue(type(md), str)
Exemplo n.º 5
0
 def __init__(self, details=False):
     self.details = details
     self.lint = Lint()