def find_parsers(): import n6datasources from n6datasources.parsers.base import BaseParser console_scripts_list = [] dirname = osp.dirname(osp.abspath(n6datasources.parsers.__file__)) for importer, package_name, _ in pkgutil.iter_modules([dirname]): full_package_name = 'n6datasources.parsers.%s' % package_name if full_package_name not in sys.modules and package_name != "base": module = importer.find_module(package_name).load_module() for pclass in all_subclasses(BaseParser): # @UndefinedVariable if pclass.__module__ == "n6datasources.parsers.base": continue if pclass.__qualname__.startswith('_'): continue script_name = pclass.__qualname__.split(".")[-1].lower().replace("parser", "") console_line = "n6parser_%s" % (script_name) console_scripts_list.append(console_line) return console_scripts_list
def entry_point_factory(module): for parser_class in all_subclasses(BaseParser): if (not parser_class.__module__.endswith('.generic') and not parser_class.__name__.startswith('_')): setattr(module, "%s_main" % parser_class.__name__, generate_parser_main(parser_class))
def entry_point_factory(module): for collector_class in all_subclasses(AbstractBaseCollector): if (not collector_class.__module__.endswith('.generic') and not collector_class.__name__.startswith('_')): setattr(module, "%s_main" % collector_class.__name__, generate_collector_main(collector_class))
def test(self): class Z(object): pass class Y(object): pass class X(Z): pass class XY(X, Y): pass class XZ(X, Z): pass class YZ(Y, Z): pass class XYZ_A(X, Y, Z): pass class XYZ_B(X, Y, Z): pass class XYZ_A1(XYZ_A): pass class XYZ_A2(XYZ_A): pass class XYZ_A12(XYZ_A1, XYZ_A2): pass class XYZ_A1_AB(XYZ_A1, XYZ_A, XYZ_B): pass class XYZ_XZ_A1(XZ, XYZ_A1): pass class XYZ_XZ_A12(XZ, XYZ_A12): pass class XYZ_XZ_A1_AB(XYZ_XZ_A1, XYZ_A1_AB): pass self.assertEqual(all_subclasses(Z), {X, XY, XZ, YZ, XYZ_A, XYZ_B, XYZ_A1, XYZ_A2, XYZ_A12, XYZ_A1_AB, XYZ_XZ_A1, XYZ_XZ_A12, XYZ_XZ_A1_AB}) self.assertEqual(all_subclasses(Y), {XY, YZ, XYZ_A, XYZ_B, XYZ_A1, XYZ_A2, XYZ_A12, XYZ_A1_AB, XYZ_XZ_A1, XYZ_XZ_A12, XYZ_XZ_A1_AB}) self.assertEqual(all_subclasses(X), {XY, XZ, XYZ_A, XYZ_B, XYZ_A1, XYZ_A2, XYZ_A12, XYZ_A1_AB, XYZ_XZ_A1, XYZ_XZ_A12, XYZ_XZ_A1_AB}) self.assertEqual(all_subclasses(XY), set()) self.assertEqual(all_subclasses(XZ), {XYZ_XZ_A1, XYZ_XZ_A12, XYZ_XZ_A1_AB}) self.assertEqual(all_subclasses(YZ), set()) self.assertEqual(all_subclasses(XYZ_A), {XYZ_A1, XYZ_A2, XYZ_A12, XYZ_A1_AB, XYZ_XZ_A1, XYZ_XZ_A12, XYZ_XZ_A1_AB}) self.assertEqual(all_subclasses(XYZ_B), {XYZ_A1_AB, XYZ_XZ_A1_AB}) self.assertEqual(all_subclasses(XYZ_A1), {XYZ_A12, XYZ_A1_AB, XYZ_XZ_A1, XYZ_XZ_A12, XYZ_XZ_A1_AB}) self.assertEqual(all_subclasses(XYZ_A2), {XYZ_A12, XYZ_XZ_A12}) self.assertEqual(all_subclasses(XYZ_A12), {XYZ_XZ_A12}) self.assertEqual(all_subclasses(XYZ_A1_AB), {XYZ_XZ_A1_AB}) self.assertEqual(all_subclasses(XYZ_XZ_A1), {XYZ_XZ_A1_AB}) self.assertEqual(all_subclasses(XYZ_XZ_A1_AB), set())
def iter_test_case_classes(cls): for subclass in all_subclasses(cls): if isinstance(subclass, type) and issubclass( subclass, unittest.TestCase): yield subclass