示例#1
0
    def test_timelib(self):
        mt = timelib.localtime_mutable()
        print mt
        mt.add_seconds(3600)
        print mt
        print timelib.strftime("%Y-%m-%d", timelib.weekof(timelib.time()))

        t = timelib.now()
        for d in range(1, 60):
            week = timelib.weekof(t+(d*60*60*24))
            print timelib.MutableTime(week)

        print "Local time:"
        print timelib.localtimestamp()

        p = timelib.TimespecParser()
        for spec, secs in [
            ("0s", 0.0),
            ("3m", 180.0),
            ("3.0m", 180.0),
            ("3minute+2secs", 182.0),
            ("2h 3minute+2.2secs", 7382.2),
            ("-3m", -180.0),
            ("-3.0m", -180.0),
            ("1h3m", 3780.0),
            ("1h-3m", 3420.0),
            ("1d 3m", 86580.0)]:
            p.parse(spec)
            self.assert_(p.seconds == secs)

        self.assertRaises(ValueError, p.parse, "12m -m")
示例#2
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
示例#3
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)
示例#4
0
 def get_setstring(self):
     s = []
     s.append("%s=%s" % (self.name, self.value))
     if self.comment:
         s.append("comment=%s" % httpquote(self.comment))
     if self.domain:
         s.append("domain=%s" % httpquote(self.domain))
     if self.max_age:
         s.append("max_age=%s" % httpquote(self.max_age))
     if self.path:
         s.append("path=%s" % httpquote(self.path))
     if self.secure:
         s.append("secure")
     if self.version:
         s.append("version=%s" % httpquote(str(self.version)))
     if self.expires:
         s.append("expires=%s" % timelib.strftime(
             "%a, %d-%b-%Y %H:%M:%S GMT", timelib.gmtime(self.expires)))
     return "; ".join(s)
示例#5
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)
示例#6
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,))
示例#7
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)
示例#8
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)
示例#9
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, ))
示例#10
0
文件: core.py 项目: llwang/powerdroid
 def GetStartTimestamp(self):
     return timelib.strftime("%m%d%H%M%S",
                             timelib.localtime(self.starttime))
示例#11
0
文件: core.py 项目: llwang/powerdroid
def timestamp(t):
    return timelib.strftime("%a, %d %b %Y %H:%M:%S %Z", timelib.localtime(t))
示例#12
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)
示例#13
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)
示例#14
0
 def __str__(self):
     return timelib.strftime("%a, %d %b %Y %H:%M:%S GMT", self._value)
示例#15
0
 def __str__(self):
     return timelib.strftime("%a, %d %b %Y %H:%M:%S GMT", self._value)
示例#16
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)