Example #1
0
    def _get_modules(self):
        """Gets modules given the repo paths passed in to init"""
        modules = []
        error = False
        for repo in self.testrepos:

            # We're assuming only packages have __file__ attribute strings
            # that end with __init__.py (or .pyc).  If this doesn't match
            # that pattern, assume it's a module.
            if "__init__.py" not in getattr(repo, "__file__", ""):
                modules.append(repo)
                continue

            # We're still in a package, so walk it and find the rest of the
            # modules.
            prefix = "{0}.".format(repo.__name__)
            for _, modname, is_pkg in pkgutil.walk_packages(
                    path=repo.__path__, prefix=prefix, onerror=lambda x: None):
                if not is_pkg:
                    try:
                        modules.append(importlib.import_module(modname))
                    except Exception as exception:
                        print_exception(
                            "Suite Builder", "import_module", modname,
                            exception)
                        error = True
        if self.exit_on_error and error:
            exit(get_error(exception))

        return modules
Example #2
0
    def run(self):
        """Starts the run of the tests"""
        results = []
        worker_list = []
        to_worker = Queue()
        from_worker = Queue()
        verbose = self.cl_args.verbose
        failfast = self.cl_args.failfast
        workers = int(not self.cl_args.parallel) or self.cl_args.workers

        for suite in self.suites:
            to_worker.put(suite)

        for _ in range(workers):
            to_worker.put(None)

        start = time.time()

        # A second try catch is needed here because queues can cause locking
        # when they go out of scope, especially when termination signals used
        try:
            for _ in range(workers):
                proc = Consumer(to_worker, from_worker, verbose, failfast)
                worker_list.append(proc)
                proc.start()

            for _ in self.suites:
                results.append(self.log_result(from_worker.get()))

            tests_run, errors, failures = self.compile_results(time.time() - start, results)
        except KeyboardInterrupt:
            print_exception("Runner", "run", "Keyboard Interrupt, exiting...")
            os.killpg(0, 9)
        return bool(sum([errors, failures, not tests_run]))
Example #3
0
def entry_point():
    """Function setup.py links cafe-runner to"""
    try:
        runner = UnittestRunner()
        exit(runner.run())
    except KeyboardInterrupt:
        print_exception("Runner", "run", "Keyboard Interrupt, exiting...")
        os.killpg(0, 9)
Example #4
0
def entry_point():
    """setup.py script entry point"""
    try:
        runner = BrewRunner()
        exit(runner.run())
    except KeyboardInterrupt:
        print_exception(
            "BrewRunner", "run", "Keyboard Interrupt, exiting...")
        os.killpg(0, 9)
Example #5
0
def import_repos(repo_list):
    """Imports the repos passed in on the command line"""
    repos = []
    for repo_name in repo_list:
        try:
            repos.append(importlib.import_module(repo_name))
        except Exception as exception:
            print_exception("Runner", "import_repos", repo_name, exception)
    if len(repo_list) != len(repos):
        exit(get_error(exception))
    return repos
Example #6
0
def tree(start):
    """
        Prints tree structure, files first then directories in alphabetical
        order.
    """
    start = os.path.abspath(os.path.expanduser(start))
    if not os.path.exists(start):
        print_exception("Argument Parser", "tree", "{0} Does Not Exist".format(start))
        return
    elif os.path.isfile(start):
        print("+-{0}".format(os.path.basename(start)))
        return
    for path, dirs, files in os.walk(start):
        dirs.sort()
        files.sort()
        depth = path.replace(start, "").count(os.sep)
        print("{0}{1}+-{2}/".format("  " * (depth > 0), "| " * (depth - 1), os.path.basename(path)))
        for file_ in files:
            if not file_.endswith(".pyc") and file_ != "__init__.py":
                print("  {0}{1}".format("| " * depth, file_))
Example #7
0
 def _get_modules(self):
     """Gets modules given the repo paths passed in to init"""
     modules = []
     error = False
     for repo in self.testrepos:
         if not repo.__file__.endswith("__init__.pyc"):
             modules.append(repo)
             continue
         prefix = "{0}.".format(repo.__name__)
         for _, modname, is_pkg in pkgutil.walk_packages(
                 path=repo.__path__, prefix=prefix, onerror=lambda x: None):
             if not is_pkg:
                 try:
                     modules.append(importlib.import_module(modname))
                 except Exception as exception:
                     print_exception(
                         "Suite Builder", "import_module", modname,
                         exception)
                     error = True
     if self.exit_on_error and error:
         exit(get_error(exception))
     return modules
Example #8
0
 def error(self, message):
     self.print_usage(sys.stderr)
     print_exception("Argument Parser", message)
     exit(get_error())