def __find_implementations(): """Returns all the concrete subclasses of MetadataExtractor. """ implementations = {} for implementation in all_subclasses(MetadataExtractor): try: implementations[implementation.feature_name()] = implementation except NotImplementedError: pass return implementations
def test_all_subclasses(self): class Root(object): pass class AB(Root): pass class ABC(AB): pass class AD(Root): pass class ABAD(AB, AD): pass class ABADE(ABAD): pass self.assertTrue(all_subclasses(Root), set([AB, ABC, AD, ABAD, ABADE])) self.assertEqual(all_subclasses(ABADE), set())
def test_all_subclasses(self): class Root(object): pass class AB(Root): pass class ABC(AB): pass class AD(Root): pass class ABAD(AB, AD): pass class ABADE(ABAD): pass self.assertTrue(all_subclasses(Root), set([AB, ABC, AD, ABAD, ABADE])) self.assertTrue(all_subclasses(ABADE) == set())
def test_all_subclasses(self): class Root(object): pass class AB(Root): pass class ABC(AB): pass class AD(Root): pass class ABAD(AB, AD): pass class ABADE(ABAD): pass self.assertItemsEqual(all_subclasses(Root), [AB, ABC, AD, ABAD, ABADE]) self.assertSetEqual(all_subclasses(ABADE), set())
def _implementations(cls): """Returns all the concrete subclasses of MetadataExtractor. """ if cls.__implementations: return cls.__implementations cls.__implementations = {} for implementation in all_subclasses(MetadataExtractor): try: feature_name = implementation.feature_name() cls.__implementations[feature_name] = implementation except NotImplementedError: pass return cls.__implementations