コード例 #1
0
ファイル: run_tests.py プロジェクト: josegutab/scipion
def printTests(tests, mode='modules'):
    """ Show the list of tests available """

    assert mode in ['modules', 'classes', 'all'], 'Unknown mode %s' % mode

    # First flatten the list of tests.
    testsFlat = []
    toCheck = [t for t in tests]
    while toCheck:
        test = toCheck.pop()
        if isinstance(test, unittest.TestSuite):
            toCheck += [t for t in test]
        else:
            testsFlat.append(test)

    # Follow the flattened list of tests and show the module, class
    # and name, in a nice way.
    lastClass = None
    lastModule = None
    for t in testsFlat:
        moduleName, className, testName = t.id().rsplit('.', 2)

        # If there is a failure loading the test, show it
        if moduleName.startswith('unittest.loader.ModuleImportFailure'):
            print redStr(moduleName), "  test:", t.id()
            continue

        if moduleName != lastModule:
            lastModule = moduleName
            print moduleName
        if mode in ['classes', 'all'] and className != lastClass:
            lastClass = className
            print "  %s" % className
        if mode == 'all':
            print "    %s" % testName
コード例 #2
0
ファイル: tests.py プロジェクト: denisfortun/scipion
 def doReport(self):
     secs = time.time() - self.startTimeAll
     sys.stderr.write("\n%s run %d tests (%0.3f secs)\n" %
                      (greenStr("[==========]"), self.numberTests, secs))
     if self.testFailed:
         print >> sys.stderr, redStr("[  FAILED  ]") + " %d tests" % self.testFailed
     print >> sys.stdout, greenStr("[  PASSED  ]") + " %d tests" % (self.numberTests - self.testFailed)
コード例 #3
0
 def doReport(self):
     secs = time.time() - self.startTimeAll
     sys.stderr.write("\n%s run %d tests (%0.3f secs)\n" %
                      (greenStr("[==========]"), self.numberTests, secs))
     if self.testFailed:
         print >> sys.stderr, redStr("[  FAILED  ]") + " %d tests" % self.testFailed
     print >> sys.stdout, greenStr("[  PASSED  ]") + " %d tests" % (self.numberTests - self.testFailed)
コード例 #4
0
def send(command, comm, dest, tag):
    """ Send command in a non-blocking way and raise exception on error. """

    # This function blocks, but it uses the isend() function (which is
    # nonblocking) and sleeps without using the cpu while we try to send.
    # Also, if we cannot send after TIMEOUT seconds, raise exception.

    if command.startswith('env='):
        print("Sending environment to %d" % dest)
    else:
        print("Sending command to %d: %s" % (dest, command))

    # Send command with isend()
    req_send = comm.isend(dumps(command), dest=dest, tag=tag)
    t0 = time()
    while not req_send.test()[0]:
        sleep(1)
        if time() - t0 > TIMEOUT:
            raise Exception("Timeout in process %d, cannot send command "
                            "to worker %d." % (os.getpid(), dest))

    # Receive the result in a non-blocking way too (with irecv())
    req_recv = comm.irecv(source=dest, tag=tag)
    while True:
        done, result = req_recv.test()
        if done:
            break
        sleep(1)

    if result != 0:  # result will then be a string with the error
        print(
            redStr("Worker process %d has failed. Please check the terminal "
                   "for details." % dest))
        raise Exception(str(result))
コード例 #5
0
 def reportError(self, test, err):
     sys.stderr.write("%s %s\n" %
                      (redStr('[   FAILED ]'), self.getTestName(test)))
     sys.stderr.write("\n%s" % redStr("".join(format_exception(*err))))
     self.testFailed += 1
コード例 #6
0
ファイル: tests.py プロジェクト: azazellochg/scipion
 def reportError(self, test, err):
     sys.stderr.write("%s %s\n" % (redStr("[   FAILED ]"), self.getTestName(test)))
     sys.stderr.write("\n%s" % redStr("".join(format_exception(*err))))
     self.testFailed += 1