Exemplo n.º 1
0
 def run_module(self, mod):
     """run_module(module)
 Runs the module. The parameter should be a module object, but if it is a
 string then a module object with that name will be imported. 
 """
     cf = self._config
     if type(mod) is str:
         mod = self.get_module(mod)
     if not mod:
         raise ValueError, "Unable to locate test module"
     try:
         cf.module_ID = mod._ID
     except AttributeError:
         cf.module_ID = "<unknown>"
     cf.reportbasename = mod.__name__.replace(".", "_")
     cf.logbasename = "%s.log" % (cf.reportbasename,)
     # merge any test-module specific config files.
     testconf = os.path.join(os.path.dirname(mod.__file__) , "%s.conf" % (mod.__name__.split(".")[-1],))
     cf.mergefile(testconf)
     # resultsdir is where you would place any resulting data files.
     starttime = timelib.now()
     cf.resultsdir = os.path.join(
             os.path.expandvars(cf.get("resultsdirbase", "/var/tmp")),
             "%s-%s" % (cf.reportbasename, timelib.strftime("%Y%m%d%H%M", timelib.localtime(starttime)))
     )
     # make results dir, don't worry if it already exists
     try:
         os.mkdir(cf.resultsdir)
     except OSError, errno:
         if errno[0] == EEXIST:
             pass
         else:
             raise
Exemplo n.º 2
0
 def logfilename(self, ext="log"):
     """Return a standardized log file name with a timestamp that should be
     unique enough to not clash with other tests, and also able to correlate
     it later to the test report via the time stamp."""
     return "%s-%s.%s" % (self.test_name,
                          timelib.strftime(
                              "%Y%m%d%H%M%S",
                              timelib.localtime(self.starttime)), ext)
Exemplo n.º 3
0
    def RunObject(self, obj):
        """Run a test object (object with run() function or method).

    Arguments: 
      obj: 
        A Python test object.  This object must have a `run()` function
        or method that takes a configuration object as it's single
        parameter. It should also have a `test_name` attribute.

    Messages:
      May send any of the following messages to the report object:
        RUNNERARGUMENTS: 
          command-line arguments given to test runner.
        logfile: 
          name of the log file from the configuration.
        COMMENT:
          User supplied comment given when test object was invoked.
        RUNNERSTART:
          Timestamp when test runner started.
        RUNNEREND:
          Timestamp when test runner ends.
        add_url:
          Location where any generated data files, logs, and reports can
          be found.

    """
        cf = self.config
        basename = "_".join(obj.test_name.split("."))
        cf.reportfilename = basename
        cf.logbasename = "%s.log" % (basename, )
        # resultsdir is where you would place any resulting data files. This
        # is also where any report object or log files are placed.
        cf.resultsdir = os.path.join(
            os.path.expandvars(cf.get("resultsdirbase",
                                      "/var/tmp")), "%s-%s-%s" %
            (cf.reportfilename, cf.username,
             timelib.strftime("%Y%m%d%H%M",
                              timelib.localtime(cf.runnerstarttime))))
        self._CreateResultsDir()
        self._ReportUrl()
        cf.report.logfile(cf.logfilename)
        # run the test object!
        return obj.Run(cf)
Exemplo n.º 4
0
 def __call__(self, *args, **kw):
     # this heading displays the test name just as a PREREQUISITES entry needs.
     self._report.add_heading(repr_test(self.test_name, args, kw), 2)
     self.starttime = timelib.now()
     self.info("STARTTIME: %s" % (timelib.strftime("%a, %d %b %Y %H:%M:%S %Z", timelib.localtime(self.starttime)),))
     rv = None # in case of exception
     rv = self._initialize(rv)
     if rv is not None: # an exception happened
         return rv
     # test elapsed time does not include initializer time.
     teststarttime = timelib.now()
     # run execute
     try:
         rv = apply(self.execute, args, kw)
     except KeyboardInterrupt:
         if self._debug:
             ex, val, tb = sys.exc_info()
             debugger.post_mortem(tb, ex, val)
         rv = self.incomplete("%s: aborted by user." % self.test_name)
         self._finalize(rv)
         raise
     except TestFailError, errval:
         rv = self.failed("Caught Fail exception: %s" % (errval,))
Exemplo n.º 5
0
    def initialize(self):
        """Perform any initialization needed by the test runner.

        Initializes report. Sends runner and header messages to the report.
        """
        cf = self.config
        cf.username = os.environ["USER"]
        os.chdir(cf.logfiledir)  # Make sure runner CWD is a writable place.
        cf.runnerstarttime = starttime = timelib.now()
        cf.runnertimestamp = timelib.strftime(
            "%Y%m%d%H%M%S", timelib.localtime(cf.runnerstarttime))
        try:
            rpt = cf.get_report()
        except reports.ReportFindError as err:
            cf.UI.error(str(err))
            cf.UI.printf("%YUse at least one of the following%N:")
            cf.UI.print_list(cf.reports.keys())
            cf.UI.Print("\n")
            raise TestRunnerError("Cannot continue without report.")
        # Report file's names. save for future use.
        rpt.initialize(cf)
        cf.reportfilenames = rpt.filenames
        rpt.add_title("Test Results for %r." %
                      " ".join(cf.get("argv", ["unknown"])))
        arguments = cf.get("arguments")
        # Report command line arguments, if any.
        if arguments:
            rpt.add_message("RUNNERARGUMENTS", " ".join(arguments))
        # Report comment, if any.
        comment = cf.get("comment")
        if comment:
            rpt.add_message("COMMENT", comment)
        # Report build here, if given.
        build = cf.get("build")
        if build:
            rpt.add_message("BUILD", build)
        rpt.add_message("RUNNERSTARTTIME", starttime, 0)
Exemplo n.º 6
0
    def initialize(self):
        """Perform any initialization needed by the test runner.

        Initializes report. Sends runner and header messages to the report.
        """
        cf = self.config
        cf.username = os.environ["USER"]
        os.chdir(cf.logfiledir) # Make sure runner CWD is a writable place.
        cf.runnerstarttime = starttime = timelib.now()
        cf.runnertimestamp = timelib.strftime("%Y%m%d%H%M%S",
                timelib.localtime(cf.runnerstarttime))
        try:
            rpt = cf.get_report()
        except reports.ReportFindError as err:
            cf.UI.error(str(err))
            cf.UI.printf("%YUse at least one of the following%N:")
            cf.UI.print_list(cf.reports.keys())
            cf.UI.Print("\n")
            raise TestRunnerError("Cannot continue without report.")
        # Report file's names. save for future use.
        rpt.initialize(cf)
        cf.reportfilenames = rpt.filenames
        rpt.add_title("Test Results for %r." % " ".join(cf.get("argv", ["unknown"])))
        arguments = cf.get("arguments")
        # Report command line arguments, if any.
        if arguments:
            rpt.add_message("RUNNERARGUMENTS", " ".join(arguments))
        # Report comment, if any.
        comment = cf.get("comment")
        if comment:
            rpt.add_message("COMMENT", comment)
        # Report build here, if given.
        build = cf.get("build")
        if build:
            rpt.add_message("BUILD", build)
        rpt.add_message("RUNNERSTARTTIME", starttime, 0)
Exemplo n.º 7
0
 def __call__(self, *args, **kw):
     # this heading displays the test name just as a PREREQUISITES entry needs.
     self._report.add_heading(repr_test(self.test_name, args, kw), 2)
     self.starttime = timelib.now()
     self.info("STARTTIME: %s" % (timelib.strftime(
         "%a, %d %b %Y %H:%M:%S %Z", timelib.localtime(self.starttime)), ))
     rv = None  # in case of exception
     rv = self._initialize(rv)
     if rv is not None:  # an exception happened
         return rv
     # test elapsed time does not include initializer time.
     teststarttime = timelib.now()
     # run execute
     try:
         rv = apply(self.execute, args, kw)
     except KeyboardInterrupt:
         if self._debug:
             ex, val, tb = sys.exc_info()
             debugger.post_mortem(tb, ex, val)
         rv = self.incomplete("%s: aborted by user." % self.test_name)
         self._finalize(rv)
         raise
     except TestFailError, errval:
         rv = self.failed("Caught Fail exception: %s" % (errval, ))
Exemplo n.º 8
0
 def GetStartTimestamp(self):
     return timelib.strftime("%m%d%H%M%S",
                             timelib.localtime(self.starttime))
Exemplo n.º 9
0
def timestamp(t):
    return timelib.strftime("%a, %d %b %Y %H:%M:%S %Z", timelib.localtime(t))
Exemplo n.º 10
0
 def encode(self):
     ts = timelib.strftime("%b %d %H:%M:%S", timelib.localtime(self.timestamp))
     return "<%s>%s %s %s: %s" % ((self.facility<<3) + self.priority, ts, self.tag, self.message)
Exemplo n.º 11
0
 def encode(self):
     ts = timelib.strftime("%b %d %H:%M:%S", timelib.localtime(self.timestamp))
     return "<%s>%s %s %s: %s" % ((self.facility<<3) + self.priority, ts, self.tag, self.message)
Exemplo n.º 12
0
 def logfilename(self, ext="log"):
     """Return a standardized log file name with a timestamp that should be
     unique enough to not clash with other tests, and also able to correlate
     it later to the test report via the time stamp."""
     return "%s-%s.%s" % (self.test_name, timelib.strftime("%Y%m%d%H%M%S", timelib.localtime(self.starttime)), ext)