def test_mapping(self): self.section.aspects = AspectList([ get_aspect('UnreachableCode')('py'), get_aspect('Clone')('py', min_clone_tokens=30), ]) result = self.bear.execute() self.assertEqual([True, 30], result)
def test_setting_priority(self): self.section.aspects = AspectList([ get_aspect('UnreachableCode')('py'), get_aspect('Clone')('py', min_clone_tokens=30), ]) self.section.append(Setting('remove_unreachable_code', 'False')) self.section.append(Setting('minimum_clone_tokens', 40)) result = self.bear.execute() self.assertEqual([False, 40], result)
def test_mapping(self): self.section.aspects = AspectList([ get_aspect('UnreachableCode')('py'), get_aspect('Clone')('py', min_clone_tokens=30), ]) result = self.bear.execute() expected = self.EXPECTED.copy() expected['remove_unreachable_code'] = True expected['minimum_clone_tokens'] = 30 self.assertEqual(expected, dict(result))
def test_setting_priority(self): self.section.aspects = AspectList([ get_aspect('UnreachableCode')('py'), get_aspect('Clone')('py', min_clone_tokens=30), ]) self.section.append(Setting('remove_unreachable_code', 'False')) self.section.append(Setting('minimum_clone_tokens', 40)) result = self.bear.execute() expected = self.EXPECTED.copy() expected['minimum_clone_tokens'] = 40 self.assertEqual(expected, dict(result))
def test_extract_aspects_from_section_with_exclude(self): section = Section('section') section.append(Setting('aspects', 'commitmessage')) section.append(Setting('excludes', 'TrailingPeriod')) section.language = Language['py 3.4'] aspects = extract_aspects_from_section(section) self.assertTrue(issubaspect(get_aspect('trailingperiod'), get_aspect('commitmessage'))) self.assertIsNone(aspects.get('trailingperiod'))
def test_setting_priority(self): self.section.aspects = AspectList([ get_aspect('UnreachableCode')('py'), get_aspect('Clone')('py', min_clone_tokens=30), ]) self.section.append( Setting('remove_unreachable_code', 'False')) self.section.append( Setting('minimum_clone_tokens', 40)) result = self.bear.execute() self.assertEqual([False, 40], result)
class RunDecoratedBear(LocalBear): @map_setting_to_aspect( remove_unreachable_code=get_aspect('UnreachableCode'), minimum_clone_tokens=get_aspect('Clone').min_clone_tokens, ) def run( self, remove_unreachable_code: bool = False, minimum_clone_tokens: int = 10, ): return [remove_unreachable_code, minimum_clone_tokens]
def test_extract_aspects_from_section_with_exclude(self): section = Section('section') section.append(Setting('aspects', 'commitmessage')) section.append(Setting('excludes', 'TrailingPeriod')) section.append(Setting('language', 'py 3.4')) aspects = extract_aspects_from_section(section) self.assertTrue( issubaspect(get_aspect('trailingperiod'), get_aspect('commitmessage'))) self.assertIsNone(aspects.get('trailingperiod'))
def test_aspect_bear(self): with bear_test_module(): aspects = AspectList([ get_aspect('unusedglobalvariable')('py'), get_aspect('unusedlocalvariable')('py'), ]) local_bears, global_bears = collect_bears_by_aspects( aspects, [BEAR_KIND.LOCAL, BEAR_KIND.GLOBAL]) self.assertEqual(len(global_bears), 0) self.assertEqual(len(local_bears), 1) self.assertIs(local_bears[0].name, 'AspectTestBear')
def test_setting_priority(self): self.section.aspects = AspectList([ get_aspect('UnreachableCode')('py'), get_aspect('Clone')('py', min_clone_tokens=30), ]) self.section.append( Setting('remove_unreachable_code', 'False')) self.section.append( Setting('minimum_clone_tokens', 40)) result = self.bear.execute() expected = self.EXPECTED.copy() expected['minimum_clone_tokens'] = 40 self.assertEqual(expected, dict(result))
class RunDecoratedBear(Bear): @staticmethod def kind(): return BEAR_KIND.LOCAL @map_setting_to_aspect( remove_unreachable_code=get_aspect('UnreachableCode'), minimum_clone_tokens=get_aspect('Clone').min_clone_tokens, ) def run( self, remove_unreachable_code: bool = False, minimum_clone_tokens: int = 10, ): return [remove_unreachable_code, minimum_clone_tokens]
def test_setting_priority(self): self.section.aspects = AspectList([ get_aspect('Indentation')('py', indent_type='tab'), ]) self.section.append(Setting('use_spaces', True)) result = self.bear.execute() expected = self.EXPECTED.copy() self.assertEqual(expected, dict(result))
def test_mapping(self): self.section.aspects = AspectList([ get_aspect('Indentation')('py', indent_type='tab'), ]) result = self.bear.execute() expected = self.EXPECTED.copy() expected['use_spaces'] = False self.assertEqual(expected, dict(result))
def test_partial_mapping(self): self.section.aspects = AspectList([ get_aspect('UnreachableCode')('py'), ]) result = self.bear.execute() expected = self.EXPECTED.copy() expected['remove_unreachable_code'] = True self.assertEqual(expected, dict(result))
class RunDecoratedBear(LocalBear): @map_setting_to_aspect( remove_unreachable_code=get_aspect('UnreachableCode'), minimum_clone_tokens=get_aspect('Clone').min_clone_tokens, ) @map_ambiguous_setting_to_aspect( use_spaces=(get_aspect('Indentation').indent_type, [('space', True), ('tab', False)]), ) def run( self, remove_unreachable_code: bool = False, minimum_clone_tokens: int = 10, use_spaces: bool = True, ): return [ ('remove_unreachable_code', remove_unreachable_code), ('minimum_clone_tokens', minimum_clone_tokens), ('use_spaces', use_spaces), ]
def test_collect_bears_unfulfilled_aspect(self): aspects = AspectList([ get_aspect('unusedvariable')('py'), ]) logger = logging.getLogger() with bear_test_module(), self.assertLogs(logger, 'WARNING') as log: local_bears, global_bears = collect_bears_by_aspects( aspects, [BEAR_KIND.LOCAL, BEAR_KIND.GLOBAL]) self.assertRegex( log.output[0], 'coala cannot find bear that could analyze the ' r'following aspects: \[' r"'Root\.Redundancy\.UnusedVariable\.UnusedParameter'" r'\]') self.assertEqual(global_bears, []) self.assertEqual(str(local_bears), "[<class 'AspectTestBear.AspectTestBear'>]")
def test_collect_bears_unfulfilled_aspect(self): aspects = AspectList([ get_aspect('unusedvariable')('py'), ]) logger = logging.getLogger() with bear_test_module(), self.assertLogs(logger, 'WARNING') as log: local_bears, global_bears = collect_bears_by_aspects( aspects, [BEAR_KIND.LOCAL, BEAR_KIND.GLOBAL]) self.assertRegex(log.output[0], 'coala cannot find bear that could analyze the ' 'following aspects: \[' "'Root\.Redundancy\.UnusedVariable\.UnusedParameter'" '\]') self.assertEqual(global_bears, []) self.assertEqual(str(local_bears), "[<class 'AspectTestBear.AspectTestBear'>]")
invalid_files=(), settings={'max_line_length': 200} ) PycodestyleBearInfiniteLineLengthTest = verify_local_bear( PycodestyleBear, valid_files=(file_with_very_long_line,), invalid_files=(), settings={'max_line_length': 0}) PycodestyleBearAspectsTest = verify_local_bear( PycodestyleBear, valid_files=(small_line,), invalid_files=(long_line,), aspects=AspectList([ get_aspect('LineLength')('Python', max_line_length=30), ]), ) PycodestyleBearSettingsOverAspectsTest = verify_local_bear( PycodestyleBear, valid_files=(small_line,), invalid_files=(long_line,), aspects=AspectList([ get_aspect('LineLength')('Python', max_line_length=2), ]), settings={'max_line_length': 30}, ) class PycodestyleBearTest(unittest.TestCase):
def test_partial_mapping(self): self.section.aspects = AspectList([ get_aspect('UnreachableCode')('py'), ]) result = self.bear.execute() self.assertEqual([True, 10], result)
valid_files=(long_line, ), invalid_files=(), settings={'max_line_length': 200}) PycodestyleBearInfiniteLineLengthTest = verify_local_bear( PycodestyleBear, valid_files=(file_with_very_long_line, ), invalid_files=(), settings={'max_line_length': 0}) PycodestyleBearAspectsTest = verify_local_bear( PycodestyleBear, valid_files=(small_line, ), invalid_files=(long_line, ), aspects=AspectList([ get_aspect('LineLength')('Python', max_line_length=30), ]), ) PycodestyleBearSettingsOverAspectsTest = verify_local_bear( PycodestyleBear, valid_files=(small_line, ), invalid_files=(long_line, ), aspects=AspectList([ get_aspect('LineLength')('Python', max_line_length=2), ]), settings={'max_line_length': 30}, ) class PycodestyleBearTest(unittest.TestCase):
def setUp(self): self.section = Section('') self.section.aspects = AspectList([ get_aspect('LineLength')('Python', max_line_length=30), ]) self.uut = PycodestyleBear(self.section, Queue())
LineLengthBearValidLanguageTest = verify_local_bear( LineLengthBear, valid_files=(test_file,), invalid_files=(invalid_general_file,), settings={'language': 'C'}, ) LineLengthBearAspectTest = verify_local_bear( LineLengthBear, valid_files=(test_file,), invalid_files=('testa', 'test line'), aspects=AspectList([ get_aspect('LineLength')('Unknown', max_line_length=4), ]), ) SettingsOverAspectsPriorityTest = verify_local_bear( LineLengthBear, valid_files=(test_file,), invalid_files=('testa', 'test line'), aspects=AspectList([ get_aspect('LineLength')('Unknown', max_line_length=10), ]), settings={'max_line_length': '4'}, )