예제 #1
0
    def _spawn(self, cmdline):
        """Execute a python application."""
        cmdline = coverage_cmdline(cmdline)
        cmdline = profiling_cmdline(
            cmdline, "%s-%d" % (self.service_name, self.shard or 0))

        if CONFIG["VERBOSITY"] >= 1:
            logger.info("$ %s", " ".join(cmdline))

        if CONFIG["VERBOSITY"] >= 3:
            stdout = None
            stderr = None
        else:
            stdout = subprocess.DEVNULL
            stderr = subprocess.STDOUT
        instance = subprocess.Popen(cmdline, stdout=stdout, stderr=stderr)
        if self.cpu_limit is not None:
            logger.info("Limiting %s to %d%% CPU time", self.coord,
                        self.cpu_limit)
            # cputool terminates on its own when the main program terminates.
            subprocess.Popen([
                "cputool", "-c",
                str(self.cpu_limit), "-p",
                str(instance.pid)
            ])
        return instance
예제 #2
0
def run_unittests(test_list):
    """Run all needed unit tests.

    test_list ([(string, string)]): a list of test to run in the
                                    format (path, filename.py).
    return (int):
    """
    logger.info("Running unit tests...")

    failures = []
    num_tests_to_execute = len(test_list)

    # For all tests...
    for i, (path, filename) in enumerate(test_list):
        logger.info("Running test %d/%d: %s.%s", i + 1, num_tests_to_execute,
                    path, filename)
        cmdline = [os.path.join(path, filename)]
        cmdline = coverage_cmdline(cmdline)
        cmdline = profiling_cmdline(
            cmdline,
            os.path.join(path, filename).replace("/", "_"))
        try:
            sh(cmdline)
        except TestException:
            logger.info("  (FAILED: %s)", filename)

            # Add this case to our list of failures, if we haven't already.
            failures.append((path, filename))

    results = "\n\n"
    if not failures:
        results += "================== ALL TESTS PASSED! ==================\n"
    else:
        results += "------ TESTS FAILED: ------\n"

    results += " Executed: %d\n" % num_tests_to_execute
    results += "   Failed: %d\n" % len(failures)
    results += "\n"

    for path, filename in failures:
        results += " %s.%s\n" % (path, filename)

    if failures:
        with io.open(FAILED_UNITTEST_FILENAME, "wt",
                     encoding="utf-8") as failed_filename:
            for path, filename in failures:
                failed_filename.write("%s %s\n" % (path, filename))
        results += "\n"
        results += "Failed tests stored in %s.\n" % FAILED_UNITTEST_FILENAME
        results += "Run again with --retry-failed (or -r) to retry.\n"

    return len(failures) == 0, results
예제 #3
0
파일: RunUnitTests.py 프로젝트: Nyrio/cms
def run_unittests(test_list):
    """Run all needed unit tests.

    test_list ([(string, string)]): a list of test to run in the
                                    format (path, filename.py).
    return (int):
    """
    logger.info("Running unit tests...")

    failures = []
    num_tests_to_execute = len(test_list)

    # For all tests...
    for i, (path, filename) in enumerate(test_list):
        logger.info("Running test %d/%d: %s.%s",
                    i + 1, num_tests_to_execute, path, filename)
        cmdline = [os.path.join(path, filename)]
        cmdline = coverage_cmdline(cmdline)
        cmdline = profiling_cmdline(
            cmdline, os.path.join(path, filename).replace("/", "_"))
        try:
            sh(cmdline)
        except TestException:
            logger.info("  (FAILED: %s)", filename)

            # Add this case to our list of failures, if we haven't already.
            failures.append((path, filename))

    results = "\n\n"
    if not failures:
        results += "================== ALL TESTS PASSED! ==================\n"
    else:
        results += "------ TESTS FAILED: ------\n"

    results += " Executed: %d\n" % num_tests_to_execute
    results += "   Failed: %d\n" % len(failures)
    results += "\n"

    for path, filename in failures:
        results += " %s.%s\n" % (path, filename)

    if failures:
        with io.open(FAILED_UNITTEST_FILENAME,
                     "wt", encoding="utf-8") as failed_filename:
            for path, filename in failures:
                failed_filename.write("%s %s\n" % (path, filename))
        results += "\n"
        results += "Failed tests stored in %s.\n" % FAILED_UNITTEST_FILENAME
        results += "Run again with --retry-failed (or -r) to retry.\n"

    return len(failures) == 0, results
예제 #4
0
파일: programstarter.py 프로젝트: Nyrio/cms
    def _spawn(self, cmdline):
        """Execute a python application."""
        cmdline = coverage_cmdline(cmdline)
        cmdline = profiling_cmdline(
            cmdline, "%s-%d" % (self.service_name, self.shard or 0))

        if CONFIG["VERBOSITY"] >= 1:
            logger.info("$ %s", " ".join(cmdline))

        if CONFIG["VERBOSITY"] >= 3:
            stdout = None
            stderr = None
        else:
            stdout = io.open(os.devnull, "wb")
            stderr = stdout
        instance = subprocess.Popen(cmdline, stdout=stdout, stderr=stderr)
        if self.cpu_limit is not None:
            logger.info("Limiting %s to %d%% CPU time",
                        self.coord, self.cpu_limit)
            # cputool terminates on its own when the main program terminates.
            subprocess.Popen(["cputool", "-c", str(self.cpu_limit),
                              "-p", str(instance.pid)])
        return instance