コード例 #1
0
ファイル: test.py プロジェクト: vsoch/gridtest
 def get_func(self):
     """Get the function name, meaning we get the module first. This can
        also be used for one off (custom) function and module names.
     """
     sys.path.insert(0, os.path.dirname(self.filename))
     module = import_module(self.module)
     func = getattr(module, self.get_funcname())
     if func is None:
         bot.error("Cannot find function.")
     return func
コード例 #2
0
ファイル: defaults.py プロジェクト: vsoch/gridtest
def getenv(variable_key, default=None, required=False, silent=True):
    """ attempt to get an environment variable. If the variable
        is not found, None is returned.

        Arguments:

         - variable_key (str) : the variable name
         - default (str) : default value if variable_key does not exist
         - required (bool) : exit with error if not found
         - silent (bool) : Do not print debugging information
    """
    variable = os.environ.get(variable_key, default)
    if variable is None and required:
        bot.error("Cannot find environment variable %s, exiting." %
                  variable_key)
        sys.exit(1)

    if not silent and variable is not None:
        bot.verbose("%s found as %s" % (variable_key, variable))

    return variable
コード例 #3
0
    def run(self, tests, cleanup=True):
        """run will execute a test for each entry in the list of tests.
           the result of the test, and error codes, are saved with the test.
        
           Arguments:
               - tests (gridtest.main.test.GridTest) : the GridTest object
        """

        # Keep track of some progress for the user
        total = len(tests)
        progress = 1

        # Cut out early if no tests
        if not tests:
            return

        results = []
        to_cleanup = []

        try:
            prefix = "[%s/%s]" % (progress, total)
            if self.show_progress:
                bot.show_progress(0, total, length=35, prefix=prefix)
            pool = multiprocessing.Pool(self.workers, init_worker)

            self.start()
            for name, task in tests.items():

                # If a class is returned, needs to be in path too
                sys.path.insert(0, os.path.dirname(task.filename))

                # Get the function name from the tester
                params = {
                    "funcname": task.get_funcname(),
                    "module": task.module,
                    "filename": task.filename,
                    "metrics": task.params.get("metrics", []),
                    "args": task.params.get("args", {}),
                    "returns": task.params.get("returns"),
                }

                if not self.show_progress:
                    bot.info(f"Running test {name}")
                result = pool.apply_async(multi_wrapper,
                                          multi_package(test_basic, [params]))

                # result returns [passed, result, out, error]
                # Store the test with the result
                results.append((task, result))

            while results:
                pair = results.pop()
                test, result = pair
                result.wait()
                if self.show_progress:
                    bot.show_progress(progress,
                                      total,
                                      length=35,
                                      prefix=prefix)
                progress += 1
                prefix = "[%s/%s]" % (progress, total)

                # Update the task with the result
                passed, result, out, err, raises = result.get()
                test.out = out
                test.err = err
                test.success = passed
                test.result = result
                test.raises = raises

            self.end()
            pool.close()
            pool.join()

        except (KeyboardInterrupt, SystemExit):
            bot.error("Keyboard interrupt detected, terminating workers!")
            pool.terminate()
            sys.exit(1)

        except:
            bot.exit("Error running task.")