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)
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)
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)
def __init__(self, details=False): self.details = details self.lint = Lint()