示例#1
0
def all_tests(ui):
    try:
        from testcases import unittests
    except ImportError:
        logging.warn("Cannot find 'testcases.unittests' base package.")
        return []

    modnames = []
    runnables = []
    for finder, name, ispkg in pkgutil.walk_packages(
            unittests.__path__, unittests.__name__ + '.'):
        if ispkg:
            continue
        if "._" not in name:
            modnames.append(name)

    for modname in modnames:
        try:
            mod = module.get_module(modname)
        except module.ModuleImportError:
            ui.warning("  Warning: could not import '{}'".format(modname))
            continue
        except:
            ex, val, tb = sys.exc_info()
            ui.warning("  Warning: could not import '{}'".format(modname))
            ui.error("      {}: {}".format(ex, val))
            continue
        for attrname in dir(mod):
            obj = getattr(mod, attrname)
            if type(obj) is type:
                if issubclass(obj, core.UseCase):
                    runnables.append("{}.{}".format(modname, obj.__name__))
    return runnables
示例#2
0
def all_tests(ui):
    try:
        from testcases import unittests
    except ImportError:
        logging.warn("Cannot find 'testcases.unittests' base package.")
        return []

    modnames = []
    runnables = []
    for finder, name, ispkg in pkgutil.walk_packages(unittests.__path__,
                                                     unittests.__name__ + '.'):
        if ispkg:
            continue
        if "._" not in name:
            modnames.append(name)

    for modname in modnames:
        try:
            mod = module.get_module(modname)
        except module.ModuleImportError:
            ui.warning("  Warning: could not import '{}'".format(modname))
            continue
        except:
            ex, val, tb = sys.exc_info()
            ui.warning("  Warning: could not import '{}'".format(modname))
            ui.error("      {}: {}".format(ex, val))
            continue
        for attrname in dir(mod):
            obj = getattr(mod, attrname)
            if type(obj) is type:
                if issubclass(obj, core.UseCase):
                    runnables.append("{}.{}".format(modname, obj.__name__))
    return runnables
示例#3
0
 def import_package(self, basepackage):
     for basepath in module.get_module(basepackage).__path__:
         lenbasepath = len(basepath)-len(basepackage)
         for dirpath, dirnames, filenames in os.walk(basepath):
             for filename in filenames:
                 modname = self._convert_path(lenbasepath, dirpath, filename)
                 if modname:
                     self.import_module(modname)
示例#4
0
def choose_tests(ui):
    try:
        import testcases
    except ImportError:
        logging.warn("Cannot find 'testcases' base package.")
        return []

    ui.printf("Select a %gUseCase%N object, a single %yTestCase%N object, "
              "a module with a %mrun%N callable, or a module with "
              "an %cexecute%N style callable.")

    modnames = []
    runnables = []
    for finder, name, ispkg in pkgutil.walk_packages(testcases.__path__,
                                                     testcases.__name__ + '.'):
        if ispkg:
            continue
        if "._" not in name:
            modnames.append(name)

    modnames.sort()
    for modname in modnames:
        try:
            mod = module.get_module(modname)
        except module.ModuleImportError:
            ui.warning("  Warning: could not import '{}'".format(modname))
            continue
        except:
            ex, val, tb = sys.exc_info()
            ui.warning("  Warning: could not import '{}'".format(modname))
            ui.error("      {}: {}".format(ex, val))
            continue
        for attrname in dir(mod):
            obj = getattr(mod, attrname)
            if type(obj) is type:
                if issubclass(obj, core.UseCase):
                    runnables.append(
                        FormatWrapper(ui, modname, obj.__name__, "%U.%g%O%N"))
                if issubclass(obj, core.TestCase):
                    runnables.append(
                        FormatWrapper(ui, modname, obj.__name__, "%U.%y%O%N"))
            elif callable(obj):
                if attrname == "run":
                    runnables.append(FormatWrapper(ui, modname, None,
                                                   "%m%U%N"))
                elif attrname == "execute":
                    runnables.append(FormatWrapper(ui, modname, None,
                                                   "%c%U%N"))

    return [
        o.fullname
        for o in ui.choose_multiple(runnables, prompt="Select tests")
    ]
示例#5
0
 def import_module(self, modname):
     if _DEBUG:
         print("Doing module: %s" % modname)
     try:
         mod = module.get_module(modname)
         do_module(mod, self.config)
     except:
         ex, val, tb = sys.exc_info()
         if _DEBUG:
             debugger.post_mortem(tb, ex, val)
         else:
             logging.warn("Could not import %s: %s" % ( modname, "%s: %s" % (ex, val)))
示例#6
0
def scan_source(include_testcases=False, on_activate=None):
    """Scan the installed source code base, in the "testcases" base package,
    for runnable modules, UseCases, and TestCases.

    Return a list of tuples (DisplayNode, children)
    """
    from pycopia import module
    try:
        import testcases
    except ImportError:
        return []

    # callback for testdir walker
    def filternames(flist, dirname, names):
        for name in names:
            if name.endswith(".py") and not name.startswith("_"):
                flist.append(os.path.join(dirname, name[:-3]))
    testhome = os.path.dirname(testcases.__file__)
    modnames = []
    os.path.walk(testhome, filternames, modnames)
    testhome_index = len(os.path.dirname(testhome)) + 1
    modnames = map(lambda n: n[testhome_index:].replace("/", "."), modnames)
    # have a list of full module names at this point
    rootlist = []
    root = (widgets.PackageNode("testcases"), rootlist)
    rootdict = {"testcases": {"children": rootlist}}
    for modname in sorted(modnames):
        try:
            mod = module.get_module(modname)
        except module.ModuleImportError:
            continue
        d = rootdict
        parts = modname.split(".")
        for part in parts[:-1]:
            try:
                d = d[part]
            except KeyError:
                newlist = []
                d[part] = {"children": newlist}
                d["children"].append((widgets.PackageNode(part), newlist))
                d = d[part]
        modchildren = []
        for attrname in dir(mod):
            obj = getattr(mod, attrname)
            if type(obj) is type:
                if issubclass(obj, core.UseCase):
                    modchildren.append((widgets.UseCaseNode(".".join([modname, obj.__name__]), on_activate=on_activate), None))
                if include_testcases and issubclass(obj, core.Test):
                    modchildren.append((widgets.TestCaseNode(".".join([modname, obj.__name__]), on_activate=on_activate), None))
        if not modchildren:
            modchildren = None
        d["children"].append((widgets.ModuleNode(modname, hasattr(mod, "run"), on_activate=on_activate), modchildren))
    return [root]
示例#7
0
def choose_tests(ui):
    try:
        import testcases
    except ImportError:
        logging.warn("Cannot find 'testcases' base package.")
        return []

    ui.printf("Select a %gUseCase%N object, a single %yTestCase%N object, "
              "a module with a %mrun%N callable, or a module with "
              "an %cexecute%N style callable.")

    modnames = []
    runnables = []
    for finder, name, ispkg in pkgutil.walk_packages(
            testcases.__path__, testcases.__name__ + '.'):
        if ispkg:
            continue
        if "._" not in name:
            modnames.append(name)

    modnames.sort()
    for modname in modnames:
        try:
            mod = module.get_module(modname)
        except module.ModuleImportError:
            ui.warning("  Warning: could not import '{}'".format(modname))
            continue
        except:
            ex, val, tb = sys.exc_info()
            ui.warning("  Warning: could not import '{}'".format(modname))
            ui.error("      {}: {}".format(ex, val))
            continue
        for attrname in dir(mod):
            obj = getattr(mod, attrname)
            if type(obj) is type:
                if issubclass(obj, core.UseCase):
                    runnables.append(FormatWrapper(ui, modname, obj.__name__,
                                                   "%U.%g%O%N"))
                if issubclass(obj, core.TestCase):
                    runnables.append(FormatWrapper(ui, modname, obj.__name__,
                                                   "%U.%y%O%N"))
            elif callable(obj):
                if attrname == "run":
                    runnables.append(FormatWrapper(ui, modname, None,
                                                   "%m%U%N"))
                elif attrname == "execute":
                    runnables.append(FormatWrapper(ui, modname, None,
                                                   "%c%U%N"))

    return [o.fullname for o in ui.choose_multiple(runnables,
            prompt="Select tests")]
示例#8
0
def choose_tests():
    try:
        import testcases
    except ImportError:
        logging.warn("Cannot find 'testcases' base package.")
        return None
    from pycopia import UI
    from pycopia.QA import core

    ui = UI.get_userinterface(themename="ANSITheme")
    ui.printf(
        "Select any number of runnable objects. %n"
        "You can select %wmodules%N, %gUseCase%N objects, or single %yTest%N object."
    )

    # callback for testdir walker
    def filternames(flist, dirname, names):
        for name in names:
            if name.endswith(".py") and not name.startswith("_"):
                flist.append(os.path.join(dirname, name[:-3]))

    modnames = []
    runnables = []
    for testbase in testcases.__path__:
        mnlist = []
        os.path.walk(testbase, filternames, mnlist)
        testhome_index = len(os.path.dirname(testbase)) + 1
        modnames.extend(
            map(lambda n: n[testhome_index:].replace("/", "."), mnlist))
    modnames.sort()
    for modname in modnames:
        try:
            mod = module.get_module(modname)
        except module.ModuleImportError:
            ui.warning("  Warning: could not import '{}'".format(modname))
            continue
        if getattr(mod, "run", None) is not None:
            runnables.append(FormatWrapper(ui, modname, None, "%w%U%N"))
        for attrname in dir(mod):
            obj = getattr(mod, attrname)
            if type(obj) is type:
                if issubclass(obj, core.UseCase):
                    runnables.append(
                        FormatWrapper(ui, modname, obj.__name__, "%U.%g%O%N"))
                if issubclass(obj, core.Test):
                    runnables.append(
                        FormatWrapper(ui, modname, obj.__name__, "%U.%y%O%N"))
    return [
        o.fullname
        for o in ui.choose_multiple(runnables, prompt="Select tests")
    ]
示例#9
0
def choose_tests():
    try:
        import testcases
    except ImportError:
        logging.warn("Cannot find 'testcases' base package.")
        return None
    from pycopia import UI
    from pycopia.QA import core

    ui = UI.get_userinterface(themename="ANSITheme")
    ui.printf("Select any number of runnable objects. %n"
            "You can select %wmodules%N, %gUseCase%N objects, or single %yTest%N object.")
    # callback for testdir walker
    def filternames(flist, dirname, names):
        for name in names:
            if name.endswith(".py") and not name.startswith("_"):
                flist.append(os.path.join(dirname, name[:-3]))
    modnames = []
    runnables = []
    for testbase in testcases.__path__:
        mnlist = []
        os.path.walk(testbase, filternames, mnlist)
        testhome_index = len(os.path.dirname(testbase)) + 1
        modnames.extend(map(lambda n: n[testhome_index:].replace("/", "."), mnlist))
    modnames.sort()
    for modname in modnames:
        try:
            mod = module.get_module(modname)
        except module.ModuleImportError:
            ui.warning("  Warning: could not import '{}'".format(modname))
            continue
        if getattr(mod, "run", None) is not None:
            runnables.append(FormatWrapper(ui, modname, None, "%w%U%N"))
        for attrname in dir(mod):
            obj = getattr(mod, attrname)
            if type(obj) is type:
                if issubclass(obj, core.UseCase):
                    runnables.append(FormatWrapper(ui, modname, obj.__name__, "%U.%g%O%N"))
                if issubclass(obj, core.Test):
                    runnables.append(FormatWrapper(ui, modname, obj.__name__, "%U.%y%O%N"))
    return [o.fullname for o in ui.choose_multiple(runnables, prompt="Select tests")]
示例#10
0
文件: runner.py 项目: wildone/pycopia
def scan_source(include_testcases=False, on_activate=None):
    """Scan the installed source code base, in the "testcases" base package,
    for runnable modules, UseCases, and TestCases.

    Return a list of tuples (DisplayNode, children)
    """
    from pycopia import module
    try:
        import testcases
    except ImportError:
        return []

    # callback for testdir walker
    def filternames(flist, dirname, names):
        for name in names:
            if name.endswith(".py") and not name.startswith("_"):
                flist.append(os.path.join(dirname, name[:-3]))

    testhome = os.path.dirname(testcases.__file__)
    modnames = []
    os.path.walk(testhome, filternames, modnames)
    testhome_index = len(os.path.dirname(testhome)) + 1
    modnames = map(lambda n: n[testhome_index:].replace("/", "."), modnames)
    # have a list of full module names at this point
    rootlist = []
    root = (widgets.PackageNode("testcases"), rootlist)
    rootdict = {"testcases": {"children": rootlist}}
    for modname in sorted(modnames):
        try:
            mod = module.get_module(modname)
        except module.ModuleImportError:
            continue
        d = rootdict
        parts = modname.split(".")
        for part in parts[:-1]:
            try:
                d = d[part]
            except KeyError:
                newlist = []
                d[part] = {"children": newlist}
                d["children"].append((widgets.PackageNode(part), newlist))
                d = d[part]
        modchildren = []
        for attrname in dir(mod):
            obj = getattr(mod, attrname)
            if type(obj) is type:
                if issubclass(obj, core.UseCase):
                    modchildren.append(
                        (widgets.UseCaseNode(".".join([modname, obj.__name__]),
                                             on_activate=on_activate), None))
                if include_testcases and issubclass(obj, core.Test):
                    modchildren.append(
                        (widgets.TestCaseNode(".".join([modname,
                                                        obj.__name__]),
                                              on_activate=on_activate), None))
        if not modchildren:
            modchildren = None
        d["children"].append(
            (widgets.ModuleNode(modname,
                                hasattr(mod, "run"),
                                on_activate=on_activate), modchildren))
    return [root]