Exemple #1
0
def run_test(mod_name, noOutputPlease=False):
    if not options.RUN_TESTS:
        l.debug("Will not invoke any test cases from '%s'." % mod_name)
        return

    import sys
    module = sys.modules[mod_name]
    stdout = sys.stdout
    stderr = sys.stderr
    failures = []
    total = 0

    includedTests = [
        arg[4:] for arg in sys.argv
        if arg.startswith('run:test_') and not arg.endswith('.py')
    ]
    for name in dir(module):
        obj = getattr(module, name)
        if isinstance(obj, types.functionType):
            if name.endswith("_clionly") and not is_cli: continue
            if name.startswith("test_"):
                if not includedTests or name in includedTests:
                    for i in range(get_num_iterations()):
                        if not noOutputPlease:
                            if hasattr(time, 'clock'):
                                print(">>> %6.2fs testing %-40s" % (
                                    round(time.clock(), 2),
                                    name,
                                ),
                                      end=' ')
                            else:
                                print(">>> testing %-40s" % name, end=' ')
                        #obj()
                        #catches the error and exit at the end of each test
                        total += 1
                        try:
                            try:
                                obj()
                            finally:
                                # restore std-in / std-err incase the test corrupted it
                                sys.stdout = stdout
                                sys.stderr = stderr
                            print()

                        except:
                            failures.append((name, sys.exc_info()))
                            print("FAIL (%s)" % str(sys.exc_info()[0]))
                elif not noOutputPlease:
                    print(">>> skipping %-40s" % name)
    if failures:
        print_failures(total, failures)
        if is_cli:
            cmd_line = System.Environment.CurrentDirectory + "> " + System.Environment.CommandLine
            print("Please run the following command to repro:")
            print("\t" + cmd_line)

        sys.exit(len(failures))
    else:
        print()
        print('%d tests passed' % total)
Exemple #2
0
def run_test(mod_name, noOutputPlease=False):
    if not options.RUN_TESTS:
        l.debug("Will not invoke any test cases from '%s'." % mod_name)
        return

    import sys

    module = sys.modules[mod_name]
    stdout = sys.stdout
    stderr = sys.stderr
    failures = []
    total = 0

    includedTests = [arg[4:] for arg in sys.argv if arg.startswith("run:test_") and not arg.endswith(".py")]
    for name in dir(module):
        obj = getattr(module, name)
        if isinstance(obj, types.functionType):
            if name.endswith("_clionly") and not is_cli:
                continue
            if name.startswith("test_"):
                if not includedTests or name in includedTests:
                    for i in xrange(get_num_iterations()):
                        if not noOutputPlease:
                            if hasattr(time, "clock"):
                                print ">>> %6.2fs testing %-40s" % (round(time.clock(), 2), name),
                            else:
                                print ">>> testing %-40s" % name,
                        # obj()
                        # catches the error and exit at the end of each test
                        total += 1
                        try:
                            try:
                                obj()
                            finally:
                                # restore std-in / std-err incase the test corrupted it
                                sys.stdout = stdout
                                sys.stderr = stderr
                            print

                        except:
                            failures.append((name, sys.exc_info()))
                            print "FAIL (%s)" % str(sys.exc_info()[0])

                elif not noOutputPlease:
                    print ">>> skipping %-40s" % name
    if failures:
        print_failures(total, failures)
        if is_cli:
            cmd_line = System.Environment.CurrentDirectory + "> " + System.Environment.CommandLine
            print "Please run the following command to repro:"
            print "\t" + cmd_line

        sys.exit(len(failures))
    else:
        print
        print "%d tests passed" % total