def test_extract_aspects_from_section_no_language(self): section = Section('section') section.append(Setting('aspects', 'commitmessage')) with self.assertRaisesRegex( AttributeError, 'Language was not found in configuration file. ' 'Usage of aspect-based configuration must include ' 'language information.'): extract_aspects_from_section(section)
def test_extract_aspects_from_section(self): section = Section('section') section.append(Setting( 'aspects', 'spelling, commitmessage, methodsmell')) # Custom taste for ColonExistence section.append(Setting('commitmessage:shortlog_colon', 'false')) section.language = Language['py 3.4'] aspects = extract_aspects_from_section(section) spelling_instance = Root.Spelling('py 3.4') colon_existence_instance = ( Root.Metadata.CommitMessage.Shortlog.ColonExistence( 'py 3.4', shortlog_colon=False)) method_smell_instance = Root.Smell.MethodSmell('py 3.4') trailing_period_instance = ( Root.Metadata.CommitMessage.Shortlog.TrailingPeriod('py 3.4')) self.assertIsInstance(aspects, AspectList) self.assertEqual(aspects.get('spelling'), spelling_instance) self.assertEqual(aspects.get('colonexistence'), colon_existence_instance) self.assertEqual(aspects.get('methodsmell'), method_smell_instance) self.assertEqual(aspects.get('TrailingPeriod'), trailing_period_instance)
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 aspectize_sections(sections): """ Search for aspects related setting in a section, initialize it, and then embed the aspects information as AspectList object into the section itself. :param sections: List of section that potentially contain aspects setting. :return: The new sections. """ for _, section in sections.items(): section.aspects = extract_aspects_from_section(section) return sections
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 aspectize_sections(sections): """ Search for aspects related setting in a section, initialize it, and then embed the aspects information as AspectList object into the section itself. :param sections: List of section that potentially contain aspects setting. :return: The new sections. """ for _, section in sections.items(): if validate_aspect_config(section): section.aspects = extract_aspects_from_section(section) else: section.aspects = None return sections
def aspectize_sections(sections): """ Search for aspects related setting in a section, initialize it, and then embed the aspects information as AspectList object into the section itself. :param sections: List of section that potentially contain aspects setting. :return: The new sections. """ for section_name, section in sections.items(): section.aspects = extract_aspects_from_section(section) if section.aspects is not None and len(section.get('bears')): logging.warning("'aspects' and 'bears' configuration is detected " "in section '{}'. Aspect-based configuration will " 'takes priority and will overwrite any ' 'explicitly listed bears'.format(section_name)) return sections
def test_extract_aspects_from_section(self): section = Section('section') section.append( Setting('aspects', 'spelling, commitmessage, methodsmell')) # Custom taste for ColonExistence section.append(Setting('commitmessage.shortlog_colon', 'false')) section.append(Setting('language', 'py 3.4')) aspects = extract_aspects_from_section(section) spelling_instance = Root.Spelling('py 3.4') colon_existence_instance = ( Root.Metadata.CommitMessage.Shortlog.ColonExistence( 'py 3.4', shortlog_colon=False)) method_smell_instance = Root.Smell.MethodSmell('py 3.4') trailing_period_instance = ( Root.Metadata.CommitMessage.Shortlog.TrailingPeriod('py 3.4')) self.assertIsInstance(aspects, AspectList) self.assertEqual(aspects.get('spelling'), spelling_instance) self.assertEqual(aspects.get('colonexistence'), colon_existence_instance) self.assertEqual(aspects.get('methodsmell'), method_smell_instance) self.assertEqual(aspects.get('TrailingPeriod'), trailing_period_instance)
def test_extract_aspects_from_section_incorrect_language(self): section = Section('section') section.append(Setting('aspects', 'commitmessage')) section.append(Setting('language', 'not a language')) with self.assertRaises(UnknownLanguageError): extract_aspects_from_section(section)
def test_extract_aspects_from_section_no_aspects(self): section = Section('section') self.assertIsNone(extract_aspects_from_section(section))