Ejemplo n.º 1
0
def run(argv=None):
    """run tests using nose

    one or more module names may be present in argv after the --test switch,
    which specifies that the tests for those modules should be run first. If
    there are errors in that set of tests then stop, otherwise run all tests.

    options
     --with-test-timer : print the ten slowest tests after the test run
     --test-all-on-pass : run all tests if specified tests pass
    """
    srcpath = dirname(dirname(abspath(editxt.__file__)))

    editxt.testing = True # for editxt.utils.untested
    unittest_print_first_failures_last()
    patch_nose_tools()
    mockerext.install()
    os.chdir(srcpath)

    if argv is None:
        argv = list(sys.argv)
    index = argv.index("--test")
    argv.remove("--test")
    testmods = set()
    while True:
        try:
            rawmod = mod = argv.pop(index)
        except IndexError:
            break
        if mod.startswith("-"):
            argv.insert(index, mod)
            break
        if mod.endswith(("__init__", "runner", "nosy")):
            continue
        if mod.startswith("editxt.test."):
            pkg, name = mod.rsplit(".", 1)
            if not name.startswith("test_"):
                mod = pkg + ".test_" + name
        elif mod.startswith("editxt."):
            mod = ".test.test_".join(mod.rsplit(".", 1))
        else:
            continue
        path = os.path.join(srcpath, mod.replace(".", os.sep) + ".py")
        if os.path.exists(path):
            testmods.add(mod)
        else:
            log.warn("test module not found: %s", mod)
            if not rawmod.startswith('editxt.'):
                argv.insert(index, rawmod)
            index += 1

    #augment_checks(testmods)
    plugins = [TestTimerPlugin()]

    testall = "--test-all-on-pass" in argv
    if testall:
        argv.remove("--test-all-on-pass")

    if testmods and len(testmods) < 4:
        testmods = sorted(testmods)
        sys.__stdout__.write("pre-testing modules: \n\t%s\n" % "\n\t".join(testmods))
        success = nose.run(argv=argv, defaultTest=testmods, addplugins=plugins)
        if not success or not testall:
            return success

        sys.stdout.write("\n")

    log.info('nose argv: %s', ' '.join(argv))
    return nose.run(argv=argv, addplugins=plugins)
Ejemplo n.º 2
0
def setup():
    install()
Ejemplo n.º 3
0
def run(argv=None):
    """run tests using nose

    one or more module names may be present in argv after the --test switch,
    which specifies that the tests for those modules should be run first. If
    there are errors in that set of tests then stop, otherwise run all tests.

    options
     --with-test-timer : print the ten slowest tests after the test run
     --test-all-on-pass : run all tests if specified tests pass
    """
    srcpath = dirname(dirname(abspath(editxt.__file__)))

    editxt.testing = True  # for editxt.utils.untested
    unittest_print_first_failures_last()
    patch_nose_tools()
    mockerext.install()
    os.chdir(srcpath)

    if argv is None:
        argv = list(sys.argv)
    index = argv.index("--test")
    argv.remove("--test")
    testmods = set()
    while True:
        try:
            rawmod = mod = argv.pop(index)
        except IndexError:
            break
        if mod.startswith("-"):
            argv.insert(index, mod)
            break
        if mod.endswith(("__init__", "runner", "nosy")):
            continue
        if mod.startswith("editxt.test."):
            pkg, name = mod.rsplit(".", 1)
            if not name.startswith("test_"):
                mod = pkg + ".test_" + name
        elif mod.startswith("editxt."):
            mod = ".test.test_".join(mod.rsplit(".", 1))
        else:
            continue
        path = os.path.join(srcpath, mod.replace(".", os.sep) + ".py")
        if os.path.exists(path):
            testmods.add(mod)
        else:
            log.warn("test module not found: %s", mod)
            if not rawmod.startswith('editxt.'):
                argv.insert(index, rawmod)
            index += 1

    #augment_checks(testmods)
    plugins = [TestTimerPlugin()]

    testall = "--test-all-on-pass" in argv
    if testall:
        argv.remove("--test-all-on-pass")

    if testmods and len(testmods) < 4:
        testmods = sorted(testmods)
        sys.__stdout__.write("pre-testing modules: \n\t%s\n" %
                             "\n\t".join(testmods))
        success = nose.run(argv=argv, defaultTest=testmods, addplugins=plugins)
        if not success or not testall:
            return success

        sys.stdout.write("\n")

    log.info('nose argv: %s', ' '.join(argv))
    return nose.run(argv=argv, addplugins=plugins)
Ejemplo n.º 4
0
def setup():
    install()