예제 #1
0
파일: core.py 프로젝트: llwang/powerdroid
    def __call__(self, *args, **kwargs):
        """Invoke the test.

        The test is "kicked-off" by calling this. Any arguments are passed to
        the test implementation (`execute` method).
        """
        self._report.add_heading(self.test_name, 2)
        if args or kwargs:
            self._report.add_message("TESTARGUMENTS", ReprArgs(args, kwargs),
                                     2)
        self.starttime = timelib.now()  # saved starttime in case initializer
        # needs to create the log file.
        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 the execute() method and check for exceptions.
        try:
            rv = self.execute(*args, **kwargs)
        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, ))
예제 #2
0
파일: core.py 프로젝트: llwang/powerdroid
    def _finalize(self):
        """Run the finalize phase for suite level.

        Runs the user finalize and aborts the suite on error or interrupt. If
        this is a sub-suite then TestSuiteAbort is raised so that the
        top-level suite can handle it.
        """
        try:
            self.finalize()
        except KeyboardInterrupt:
            if self._nested:
                raise TestSuiteAbort, \
                            "Suite '%s' aborted by user in finalize()." % (self.suite_name,)
            else:
                self.Info("Suite aborted by user in finalize().")
        except:
            ex, val, tb = sys.exc_info()
            if self._debug:
                print  # ensure debugger prompts starts on new line.
                debugger.post_mortem(tb, ex, val)
            self.Info("Suite failed to finalize: %s (%s)" % (ex, val))
            if self._nested:
                raise TestSuiteAbort, \
                        "subordinate suite '%s' failed to finalize." % (self.test_name,)
        self._reportSummary()
        return self.result
예제 #3
0
 def _lambda(*iargs, **ikwargs):
     try:
         return meth(*iargs, **ikwargs)
     except:
         ex, val, tb = sys.exc_info()
         from pycopia import debugger
         debugger.post_mortem(tb, ex, val)
예제 #4
0
 def _finalize(self):
     try:
         self.finalize()
     except KeyboardInterrupt:
         if self._nested:
             raise TestSuiteAbort(
                 "Suite {!r} aborted by user in finalize().".format(
                     self.test_name))
         else:
             self.info("Suite aborted by user in finalize().")
     except:
         ex, val, tb = sys.exc_info()
         if self._debug:
             print()  # ensure debugger prompts starts on new line.
             debugger.post_mortem(tb, ex, val)
         self.info(
             "Suite failed to finalize: {} ({})".format(ex.__name__, val))
         if self._nested:
             raise TestSuiteAbort(
                 "subordinate suite {!r} failed to finalize.".format(
                     self.test_name))
     resultset = {TestResult.PASSED: 0, TestResult.FAILED: 0,
                  TestResult.EXPECTED_FAIL: 0, TestResult.INCOMPLETE: 0,
                  TestResult.NA: 0}
     # Aggregate result for suite.
     for entry in self._tests:
         resultset[entry.result] += 1
     if resultset[TestResult.FAILED] > 0:
         self.result = TestResult.FAILED
     elif resultset[TestResult.INCOMPLETE] > 0:
         self.result = TestResult.INCOMPLETE
     elif resultset[TestResult.PASSED] > 0:
         self.result = TestResult.PASSED
예제 #5
0
파일: aid.py 프로젝트: bharathi26/pycopia
 def _lambda(*iargs, **ikwargs):
     try:
         return meth(*iargs, **ikwargs)
     except:
         ex, val, tb = sys.exc_info()
         from pycopia import debugger
         debugger.post_mortem(tb, ex, val)
예제 #6
0
파일: core.py 프로젝트: llwang/powerdroid
    def _initialize(self, *args, **kwargs):
        """initialize phase handler for suite-level initialization.

        Handles calling the user `initialize()` method, and handling
        interrupts, reporting, and invoking the debugger if the DEBUG flag is
        set.
        """
        self.report.add_heading(self.test_name, 1)
        if self.config.flags.VERBOSE:
            s = ["Tests in suite:"]
            for i, entry in enumerate(self._tests):
                s.append("%3d. %r" % (i + 1, entry))
            self.report.info("\n".join(s), 1)
            del s
        try:
            self.initialize(*args, **kwargs)
        except KeyboardInterrupt:
            self.Info("Suite aborted by user in initialize().")
            raise TestSuiteAbort
        except:
            ex, val, tb = sys.exc_info()
            if self._debug:
                ex, val, tb = sys.exc_info()
                debugger.post_mortem(tb, ex, val)
            self.Info("Suite failed to initialize: %s (%s)" % (ex, val))
            raise TestSuiteAbort, val
예제 #7
0
 def handle_error(self, ex, val, tb):
     if self._debug:
         from pycopia import debugger
         debugger.post_mortem(ex, val, tb)
     else:
         import traceback
         traceback.print_exception(ex, val, tb)
예제 #8
0
 def error_handler(self, ex, val, tb):
   if ex is StopSequencer or ex is KeyboardInterrupt:
     raise ex, val
   if self._debug:
     from pycopia import debugger
     debugger.post_mortem(tb, ex, val)
   else:
     raise ex, val, tb
예제 #9
0
 def _finalize(self):
     try:
         self.finalize()
     except:
         ex, val, tb = sys.exc_info()
         self.diagnostic("{} ({})".format(ex.__name__, val))
         if self._debug:
             debugger.post_mortem(tb, ex, val)
         raise TestSuiteAbort("Test finalize failed!")
예제 #10
0
    def RunModule(self, mod):
        """Run a test module.

    Prepares the configuration with module configuration, sends report
    messages appropriate for modules, and reports pass or fail.

    Arguments:
      mod:
        A module object with a run() function that takes a configuration
        object as it's single parameter.

    Returns:
      The return value of the module's Run() function, or FAILED if the
      module raised an exception.
    """
        cf = self.config
        # merge any test-module specific config files. The config file name is
        # the same as the module name, with ".conf" appended. Located in the
        # same directory as the module itself.
        testconf = os.path.join(os.path.dirname(mod.__file__),
                                "%s.conf" % (mod.__name__.split(".")[-1], ))
        cf.mergefile(testconf)
        cf.evalupdate(cf.options_override)
        # make the module look like a test.
        mod.test_name = mod.__name__
        try:
            ID = mod.__version__[1:-1]
        except AttributeError:  # should be there, but don't worry if its not.
            ID = "undefined"
        cf.report.add_message("MODULEVERSION", ID)
        cf.report.add_message("MODULESTARTTIME", timelib.now())
        try:
            rv = self.RunObject(mod)
        except KeyboardInterrupt:
            cf.report.add_message("MODULEENDTIME", timelib.now())
            cf.report.incomplete("Module aborted by user.")
            raise
        except:
            ex, val, tb = sys.exc_info()
            if cf.flags.DEBUG:
                debugger.post_mortem(tb, ex, val)
            rv = constants.FAILED
            cf.report.add_message("MODULEENDTIME", timelib.now())
            cf.report.failed("Module exception: %s (%s)" % (ex, val))
        else:
            cf.report.add_message("MODULEENDTIME", timelib.now())
            if rv is None:
                # If module run() function returns None we take that to mean that
                # it runs a TestSuite itself. Report nothing.
                pass
            # But if the module returns something else we take that to mean that
            # it is reporting some true/false value to report as pass/fail.
            elif rv:
                return cf.report.passed("Return evaluates True.")
            else:
                return cf.report.failed("Return evaluates False.")
            return rv
예제 #11
0
 def debugger_hook(exc, value, tb):
     if (not hasattr(sys.stderr, "isatty") or not sys.stderr.isatty()
             or exc in (SyntaxError, IndentationError, KeyboardInterrupt)):
         # We don't have a tty-like device, or it was a SyntaxError, so
         # call the default hook.
         sys.__excepthook__(exc, value, tb)
     else:
         from pycopia import debugger
         debugger.post_mortem(tb, exc, value)
예제 #12
0
 def _finalize(self, rv):
     try:
         self.finalize()
     except:
         ex, val, tb = sys.exc_info()
         self.diagnostic("%s (%s)" % (ex, val))
         if self._debug:
             debugger.post_mortem(tb, ex, val)
         rv = self.abort("Test finalize failed!")
     return rv
예제 #13
0
 def _finalize(self, rv):
     try:
         self.finalize()
     except:
         ex, val, tb = sys.exc_info()
         self.diagnostic("%s (%s)" % (ex, val))
         if self._debug:
             debugger.post_mortem(tb, ex, val)
         rv = self.abort("Test finalize failed!")
     return rv
예제 #14
0
 def accept(self):
     data, addr = self._sock.recvfrom(4096)
     worker = self.workerclass(self._sock, addr)
     if self.debug:
         try:
             worker(data)
         except:
             ex, val, tb = sys.exc_info()
             debugger.post_mortem(tb, ex, val)
     else:
         worker(data)
예제 #15
0
 def import_module(self, modname):
     if _DEBUG:
         print("Doing module: %s" % modname)
     try:
         mod = module.get_module(modname)
         do_module(mod, self.config)
     except:
         ex, val, tb = sys.exc_info()
         if _DEBUG:
             debugger.post_mortem(tb, ex, val)
         else:
             logging.warn("Could not import %s: %s" % ( modname, "%s: %s" % (ex, val)))
예제 #16
0
 def accept(self):
     conn, addr = self._sock.accept()
     worker = self.workerclass(conn, addr)
     if self.debug:
         try:
             worker()
         except:
             ex, val, tb = sys.exc_info()
             debugger.post_mortem(tb, ex, val)
     else:
         self._procmanager(worker)
     conn.close()
예제 #17
0
 def _run_module(self, module_with_run):
     try:
         rv = module_with_run.run(self.config, self.environment, self._ui)
     except:
         if self.config.flags.DEBUG:
             ex, val, tb = sys.exc_info()
             debugger.post_mortem(tb, ex, val)
         else:
             logging.exception_error(module_with_run.__name__)
         return TestResult.INCOMPLETE
     else:
         return rv
예제 #18
0
    def _run_module_hack(self, module_with_exec):
        tcinst = core.TestCase(self.config, self.environment, self._ui)
        tcinst.set_test_options()
        tcinst.test_name = module_with_exec.__name__
        # Pull out essential functions.
        execute = getattr(module_with_exec, "execute")
        initialize = getattr(module_with_exec, "initialize", None)
        finalize = getattr(module_with_exec, "finalize", None)
        # Make functions bound methods of temporary TestCase instance.
        MethodType = type(tcinst.execute)

        def wrap_execute(s):
            return execute()

        setattr(tcinst, "execute", MethodType(wrap_execute, tcinst))
        if initialize is not None:
            def wrap_initialize(s):
                return initialize()
            setattr(tcinst, "initialize", MethodType(wrap_initialize, tcinst))
        if finalize is not None:
            def wrap_finalize(s):
                return finalize()
            setattr(tcinst, "finalize", MethodType(wrap_finalize, tcinst))
        # Put TestCase instance methods into module namespace.
        # This enables execute function to call disposition methods as globals.
        for name in _EXPORTED_METHODS:
            value = getattr(tcinst, name)
            setattr(module_with_exec, name, value)
        module_with_exec.config = self.config
        module_with_exec.environment = self.environment
        module_with_exec.UI = self._ui
        module_with_exec.print = tcinst.info
        module_with_exec.input = self._ui.user_input
        # Run inside a TestEntry, which handles result reporting.
        try:
            entry = core.TestEntry(tcinst)
            rv = entry.run()
        except:
            if self.config.flags.DEBUG:
                ex, val, tb = sys.exc_info()
                debugger.post_mortem(tb, ex, val)
            else:
                logging.exception_error(module_with_exec.__name__)
            rv = TestResult.INCOMPLETE
        # Clean up
        del module_with_exec.config
        del module_with_exec.environment
        del module_with_exec.UI
        del module_with_exec.print
        del module_with_exec.input
        for name in _EXPORTED_METHODS:
            delattr(module_with_exec, name)
        return rv
예제 #19
0
    def debugger_hook(exc, value, tb):
        if (
            not hasattr(sys.stderr, "isatty")
            or not sys.stderr.isatty()
            or exc in (SyntaxError, IndentationError, KeyboardInterrupt)
        ):
            # We don't have a tty-like device, or it was a SyntaxError, so
            # call the default hook.
            sys.__excepthook__(exc, value, tb)
        else:
            from pycopia import debugger

            debugger.post_mortem(tb, exc, value)
예제 #20
0
 def mainloop(self, debug=False):
     try:
         self.parser.interact()
     except KeyboardInterrupt:
         self.syslog.message("EXITING", "User interrupt")
         return
     except:
         exc, val, tb = sys.exc_info()
         self.syslog.message("EXCEPTION", "internal error: %s(%s)" % (exc, val))
         if debug:
             from pycopia import debugger
             debugger.post_mortem(tb)
     else:
         self.syslog.message("EXITING", "User exited")
예제 #21
0
 def mainloop(self, debug=False):
     try:
         self.parser.interact()
     except KeyboardInterrupt:
         self.syslog.message("EXITING", "User interrupt")
         return
     except:
         exc, val, tb = sys.exc_info()
         self.syslog.message("EXCEPTION", "internal error: %s(%s)" % (exc, val))
         if debug:
             from pycopia import debugger
             debugger.post_mortem(tb)
     else:
         self.syslog.message("EXITING", "User exited")
예제 #22
0
 def _initialize(self):
     try:
         self.initialize()
     except KeyboardInterrupt:
         self.info("Suite aborted by user in initialize().")
         raise TestSuiteAbort("Interrupted in suite initialize.")
     except:
         ex, val, tb = sys.exc_info()
         if self._debug:
             ex, val, tb = sys.exc_info()
             debugger.post_mortem(tb, ex, val)
         self.info(
             "Suite failed to initialize: {} ({})".format(ex.__name__, val))
         raise TestSuiteAbort(val)
예제 #23
0
    def run_module(self, mod):
        """Run a test module.

        Prepares the configuration with module configuration, sends report
        messages appropriate for modules, and reports pass or fail.

        Arguments:
            mod:
                A module object with a run() function that takes a configuration
                object as it's single parameter.

        Returns:
            The return value of the module's Run() function, or FAILED if the
            module raised an exception.
        """
        cf = self.config
        # make the module look like a test.
        mod.test_name = mod.__name__
        ID = get_module_version(mod)
        cf.report.add_message("MODULEVERSION", ID)
        cf.report.add_message("USECASESTARTTIME", timelib.now())
        try:
            rv = self.run_object(mod)
        except KeyboardInterrupt:
            cf.report.add_message("MODULEENDTIME", timelib.now())
            cf.report.incomplete("Module aborted by user.")
            raise
        except:
            ex, val, tb = sys.exc_info()
            if cf.flags.DEBUG:
                from pycopia import debugger
                debugger.post_mortem(tb, ex, val)
            rv = constants.FAILED
            cf.report.add_message("MODULEENDTIME", timelib.now())
            cf.report.failed("Module exception: %s (%s)" % (ex, val))
        else:
            cf.report.add_message("MODULEENDTIME", timelib.now())
            if rv is None:
                # If module run() function returns None we take that to mean that
                # it runs a TestSuite itself. Report PASSED value.
                return 1
            elif type(rv) is core.TestResult:
                return bool(rv)
            # If the module returns something else we take that to mean that
            # it is reporting some true/false value to report as pass/fail.
            elif rv:
                return cf.report.passed("Return evaluates True.")
            else:
                return cf.report.failed("Return evaluates False.")
예제 #24
0
    def run_module(self, mod):
        """Run a test module.

        Prepares the configuration with module configuration, sends report
        messages appropriate for modules, and reports pass or fail.

        Arguments:
            mod:
                A module object with a run() function that takes a configuration
                object as it's single parameter.

        Returns:
            The return value of the module's Run() function, or FAILED if the
            module raised an exception.
        """
        cf = self.config
        # make the module look like a test.
        mod.test_name = mod.__name__
        ID = get_module_version(mod)
        cf.report.add_message("MODULEVERSION", ID)
        cf.report.add_message("USECASESTARTTIME", timelib.now())
        try:
            rv = self.run_object(mod)
        except KeyboardInterrupt:
            cf.report.add_message("MODULEENDTIME", timelib.now())
            cf.report.incomplete("Module aborted by user.")
            raise
        except:
            ex, val, tb = sys.exc_info()
            if cf.flags.DEBUG:
                from pycopia import debugger
                debugger.post_mortem(tb, ex, val)
            rv = constants.FAILED
            cf.report.add_message("MODULEENDTIME", timelib.now())
            cf.report.failed("Module exception: %s (%s)" % (ex, val))
        else:
            cf.report.add_message("MODULEENDTIME", timelib.now())
            if rv is None:
                # If module run() function returns None we take that to mean that
                # it runs a TestSuite itself. Report PASSED value.
                return 1
            elif type(rv) is core.TestResult:
                return bool(rv)
            # If the module returns something else we take that to mean that
            # it is reporting some true/false value to report as pass/fail.
            elif rv:
                return cf.report.passed("Return evaluates True.")
            else:
                return cf.report.failed("Return evaluates False.")
예제 #25
0
 def _initialize(self, args, kwargs):
     self.report.add_heading("Test suite: %s" % self.__class__.__name__, 1)
     # initialize the suite
     try:
         rv = self.initialize(*args, **kwargs)
     except KeyboardInterrupt:
         self.info("Suite aborted by user in initialize().")
         raise TestSuiteAbort
     except:
         ex, val, tb = sys.exc_info()
         if self._debug:
             ex, val, tb = sys.exc_info()
             debugger.post_mortem(tb, ex, val)
         self.info("Suite failed to initialize: %s (%s)" % (ex, val))
         raise TestSuiteAbort, val
예제 #26
0
 def _initialize(self, args, kwargs):
     self.report.add_heading("Test suite: %s" % self.__class__.__name__, 1)
     # initialize the suite
     try:
         rv = self.initialize(*args, **kwargs)
     except KeyboardInterrupt:
         self.info("Suite aborted by user in initialize().")
         raise TestSuiteAbort
     except:
         ex, val, tb = sys.exc_info()
         if self._debug:
             ex, val, tb = sys.exc_info()
             debugger.post_mortem(tb, ex, val)
         self.info("Suite failed to initialize: %s (%s)" % (ex, val))
         raise TestSuiteAbort, val
예제 #27
0
 def _finalize(self):
     # finalize the suite
     try:
         self.finalize()
     except KeyboardInterrupt:
         if self._nested:
             raise TestSuiteAbort, "Suite '%s' aborted by user in finalize()." % (self.suite_name,)
         else:
             self.info("Suite aborted by user in finalize().")
     except:
         ex, val, tb = sys.exc_info()
         if self._debug:
             print
             debugger.post_mortem(tb, ex, val)
         self.info("Suite failed to finalize: %s (%s)" % (ex, val))
         if self._nested:
             raise TestSuiteAbort, "subordinate suite '%s' failed to finalize." % (self.test_name,)
     self._report_summary()
예제 #28
0
    def run(self, *args, **kwargs):
        """Invoke the test.

        Handles the disposition exceptions, and optional debugging. Invokes the
        ``initialize`` and ``finalize`` methods.
        """
        test_arguments.send(self, arguments=repr_args(args, kwargs))
        self._initialize()
        # test elapsed time does not include initializer time.
        teststarttime = datetime.now()
        test_start.send(self, name=self.test_name, time=teststarttime)
        rv = None
        try:
            rv = self.execute(*args, **kwargs)
        except KeyboardInterrupt:
            if self._debug:
                ex, val, tb = sys.exc_info()
                debugger.post_mortem(tb, ex, val)
            self.incomplete("{}: aborted by user.".format(self.test_name))
            self._finalize()
            raise
        except TestFailError as errval:
            self.failed(str(errval))
        except TestIncompleteError as errval:
            self.incomplete(str(errval))
        # Test asserts and validation errors are based on this.
        except AssertionError as errval:
            self.failed("failed assertion: {}".format(errval))
        except TestSuiteAbort:
            raise  # pass this one up to suite
        except debugger.DebuggerQuit:  # set_trace "leaks" BdbQuit
            self.incomplete("{}: Debugger exit.".format(self.test_name))
        except:
            ex, val, tb = sys.exc_info()
            if self._debug:
                debugger.post_mortem(tb, ex, val)
                tb = None
            self.incomplete("{}: Exception: ({}: {})".format(
                self.test_name, ex.__name__, val))
        endtime = datetime.now()
        test_end.send(self, time=endtime)
        self._finalize()
        return rv
예제 #29
0
파일: core.py 프로젝트: llwang/powerdroid
    def _initialize(self, rv):
        """initialize phase handler.

        Run user-defined `initialize()` and catch exceptions. If an exception
        occurs in the `initialize()` method (which establishes the
        pre-conditions for a test) then alter the return value to abort()
        which will abort the suite. Invokes the debugger if the debug flag is
        set. If debug flag is not set then emit a diagnostic message to the
        report.
        """
        try:
            self.initialize()
        except:
            ex, val, tb = sys.exc_info()
            self.Diagnostic("%s (%s)" % (ex, val))
            if self._debug:
                debugger.post_mortem(tb, ex, val)
            rv = self.Abort("Test initialization failed!")
        return rv
예제 #30
0
def main(argv):
    """qashell [-dD]
    Run the QA shell.
    """
    from pycopia import getopt
    debug = 0
    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "?hdD")
    except getopt.GetoptError:
        print(main.__doc__)
        return
    for opt, val in optlist:
        if opt in ("-?", "-h"):
            print(main.__doc__)
            return
        elif opt == "-d":
            debug += 1
        elif opt == "-D":
            from pycopia import autodebug

    if debug:
        from pycopia import logwindow
        widgets.DEBUG = logwindow.DebugLogWindow(do_stderr=True)

    app = TestRunnerShell()
    try:
        app.run()
    except:
        if debug:
            ex, val, tb = sys.exc_info()
            from pycopia import debugger
            if debug > 1:
                from pycopia import IOurxvt
                io = IOurxvt.UrxvtIO()
            else:
                io = None
            debugger.post_mortem(tb, ex, val, io)
            widgets.DEBUG.close()
            if debug > 1:
                io.close()
        else:
            raise
예제 #31
0
파일: main.py 프로젝트: bharathi26/pycopia
def main(argv):
    """qashell [-dD]
    Run the QA shell.
    """
    from pycopia import getopt
    debug = 0
    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "?hdD")
    except getopt.GetoptError:
            print (main.__doc__)
            return
    for opt, val in optlist:
        if opt in ("-?", "-h"):
            print (main.__doc__)
            return
        elif opt == "-d":
            debug += 1
        elif opt == "-D":
            from pycopia import autodebug

    if debug:
        from pycopia import logwindow
        widgets.DEBUG = logwindow.DebugLogWindow(do_stderr=True)

    app = TestRunnerShell()
    try:
        app.run()
    except:
        if debug:
            ex, val, tb = sys.exc_info()
            from pycopia import debugger
            if debug > 1:
                from pycopia import IOurxvt
                io = IOurxvt.UrxvtIO()
            else:
                io = None
            debugger.post_mortem(tb, ex, val, io)
            widgets.DEBUG.close()
            if debug > 1:
                io.close()
        else:
            raise
예제 #32
0
 def _finalize(self):
     # finalize the suite
     try:
         self.finalize()
     except KeyboardInterrupt:
         if self._nested:
             raise TestSuiteAbort, "Suite '%s' aborted by user in finalize()." % (
                 self.suite_name, )
         else:
             self.info("Suite aborted by user in finalize().")
     except:
         ex, val, tb = sys.exc_info()
         if self._debug:
             print
             debugger.post_mortem(tb, ex, val)
         self.info("Suite failed to finalize: %s (%s)" % (ex, val))
         if self._nested:
             raise TestSuiteAbort, "subordinate suite '%s' failed to finalize." % (
                 self.test_name, )
     self._report_summary()
예제 #33
0
def main(argv):
    """dbedit [-d]
    """
    debug = 0
    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "?hdD")
    except getopt.GetoptError:
        print((main.__doc__))
        return
    for opt, val in optlist:
        if opt in ("-?", "-h"):
            print((main.__doc__))
            return
        elif opt == "-d":
            debug += 1
        elif opt == "-D":
            from pycopia import autodebug

    sess = models.get_session()
    try:
        app = DBEditor(sess, debug)
        try:
            app.run()
        except:
            if debug:
                ex, val, tb = sys.exc_info()
                from pycopia import debugger
                if debug > 1:
                    from pycopia import IOurxvt
                    io = IOurxvt.UrxvtIO()
                else:
                    io = None
                debugger.post_mortem(tb, ex, val, io)
                if debug > 1:
                    io.close()
            else:
                raise
    finally:
        sess.close()
예제 #34
0
파일: main.py 프로젝트: bharathi26/pycopia
def main(argv):
    """dbedit [-d]
    """
    debug = 0
    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "?hdD")
    except getopt.GetoptError:
            print (main.__doc__)
            return
    for opt, val in optlist:
        if opt in ("-?", "-h"):
            print (main.__doc__)
            return
        elif opt == "-d":
            debug += 1
        elif opt == "-D":
            from pycopia import autodebug

    sess = models.get_session()
    try:
        app = DBEditor(sess, debug)
        try:
            app.run()
        except:
            if debug:
                ex, val, tb = sys.exc_info()
                from pycopia import debugger
                if debug > 1:
                    from pycopia import IOurxvt
                    io = IOurxvt.UrxvtIO()
                else:
                    io = None
                debugger.post_mortem(tb, ex, val, io)
                if debug > 1:
                    io.close()
            else:
                raise
    finally:
        sess.close()
예제 #35
0
    def run_class(self, cls):
        """Run a container class inside a module.

        The class is run as if it were a module, using the classes containing
        module. The class is just a container, and the run method should be a
        static method or class method.

        Arguments:
            class with run method:
                A class object with a run() method that takes a configuration
                object as it's single parameter.

        Returns:
            The return value of the class's run() method, or FAILED if the
            module raised an exception.
        """
        rpt = self.config.report
        cls.test_name = ".".join([cls.__module__, cls.__name__])
        ID = get_module_version(sys.modules[cls.__module__])
        rpt.add_message("MODULEVERSION", ID)
        rpt.add_message("USECASESTARTTIME", timelib.now())
        try:
            rv = self.run_object(cls)
        except KeyboardInterrupt:
            rpt.add_message("MODULEENDTIME", timelib.now())
            rpt.incomplete("Module aborted by user.")
            raise
        except:
            ex, val, tb = sys.exc_info()
            if self.config.flags.DEBUG:
                from pycopia import debugger
                debugger.post_mortem(tb, ex, val)
            rpt.add_message("MODULEENDTIME", timelib.now())
            rpt.incomplete("Test container exception: %s (%s)" % (ex, val))
            return constants.INCOMPLETE
        else:
            rpt.add_message("MODULEENDTIME", timelib.now())
            return rv
예제 #36
0
    def run_class(self, cls):
        """Run a container class inside a module.

        The class is run as if it were a module, using the classes containing
        module. The class is just a container, and the run method should be a
        static method or class method.

        Arguments:
            class with run method:
                A class object with a run() method that takes a configuration
                object as it's single parameter.

        Returns:
            The return value of the class's run() method, or FAILED if the
            module raised an exception.
        """
        rpt = self.config.report
        cls.test_name = ".".join([cls.__module__, cls.__name__])
        ID = get_module_version(sys.modules[cls.__module__])
        rpt.add_message("MODULEVERSION", ID)
        rpt.add_message("USECASESTARTTIME", timelib.now())
        try:
            rv = self.run_object(cls)
        except KeyboardInterrupt:
            rpt.add_message("MODULEENDTIME", timelib.now())
            rpt.incomplete("Module aborted by user.")
            raise
        except:
            ex, val, tb = sys.exc_info()
            if self.config.flags.DEBUG:
                from pycopia import debugger
                debugger.post_mortem(tb, ex, val)
            rpt.add_message("MODULEENDTIME", timelib.now())
            rpt.incomplete("Test container exception: %s (%s)" % (ex, val))
            return constants.INCOMPLETE
        else:
            rpt.add_message("MODULEENDTIME", timelib.now())
            return rv
예제 #37
0
파일: core.py 프로젝트: llwang/powerdroid
 def _finalize(self, rv):
     """
     Run user-defined `finalize()` and catch exceptions. If an exception
     occurs in the finalize() method (which is supposed to clean up from
     the test and leave the UUT in the same condition as when it was
     entered) then alter the return value to abort() which will abort the
     suite. Invokes the debugger if the debug flag is set.
     """
     try:
         self.finalize(rv)
     except:
         ex, val, tb = sys.exc_info()
         self.Diagnostic("%s (%s)" % (ex, val))
         if self._debug:
             debugger.post_mortem(tb, ex, val)
         rv = self.Abort("Test finalize failed!")
     if self.__datapoints and rv == constants.PASSED:
         self.SaveData(self.__datapoints,
                       DT_PICKLE,
                       note="datapoints: %d" % (len(self.__datapoints), ))
         # the above note has special meaning to other parts of the
         # framework (reporting)
     return rv
예제 #38
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,))
예제 #39
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, ))
예제 #40
0
파일: CLI.py 프로젝트: kdart/pycopia3
 def __call__(self, argv):
     if not argv or not argv[0] or argv[0].startswith("_"):
         return 2
     argv = self._expand_aliases(argv)
     # special escape characters...
     if argv[0].startswith("!"): # bang-escape reads pipe
         argv[0] = argv[0][1:]
         argv.insert(0, "pipe")
     elif argv[0].startswith("%"): # percent-escape spawns pty
         argv[0] = argv[0][1:]
         argv.insert(0, "spawn")
     elif argv[0].startswith("#"): # comment
         return 0
     elif argv[0].startswith("@"): # python exec escape
         argv[0] = argv[0][1:]
         argv.insert(0, "pyexec")
     elif argv[0].startswith("="): # python eval escape
         argv[0] = argv[0][1:]
         argv.insert(0, "pyeval")
     # ok, now fetch the real method...
     try:
         meth = getattr(self, argv[0])
     except AttributeError:
         meth = self.default_command
     # ...and exec it.
     try:
         rv = meth(argv) # call the method
     except (NewCommand, CommandQuit, CommandExit, KeyboardInterrupt):
         raise # pass these through to parser
     except CLISyntaxError as err:
         self._ui.printf("%RSyntax error%N: {}".format(str(err.value)))
         self._ui.help_local(meth.__doc__)
     except IndexError: # may have tried to get non-existent argv value.
         ex, val, tb = sys.exc_info()
         lev = 0
         t = tb
         while t.tb_next is not None:
             t = t.tb_next
             lev += 1
         if lev == 1: # Happened inside the command method.
             self._ui.printf("%RInsufficient number of arguments.%N")
             self._ui.help_local(meth.__doc__)
         else:        # IndexError from something called by command method.
             if _DEBUG:
                 from pycopia import debugger
                 debugger.post_mortem(tb, ex, val)
             else:
                 self.except_hook(ex, val, tb)
     except getopt.GetoptError as err:
         self._print("option %r: %s" % (err.opt, err.msg))
     except:
         ex, val, tb = sys.exc_info()
         if _DEBUG:
             from pycopia import debugger # import here due to circular dependency
             debugger.post_mortem(tb, ex, val)
         else:
             self.except_hook(ex, val, tb)
     else:
         if rv is not None:
             try:
                 self._environ["?"] = int(rv)
             except (ValueError, TypeError, AttributeError):
                 self._environ["?"] = 0
             self._environ["_"] = rv
         return rv
예제 #41
0
파일: pyro.py 프로젝트: bharathi26/pycopia
    def exception_handler(self, ex, val, tb):
        from pycopia import debugger

        debugger.post_mortem(tb, ex, val)
예제 #42
0
                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,))
        except TestIncompleteError, errval:
            rv = self.incomplete("Caught Incomplete exception: %s" % (errval,))
        except AssertionError, errval:
            rv = self.failed("failed assertion: %s" % (errval,))
        except TestSuiteAbort:
            raise # pass this one up to suite
        except:
            ex, val, tb = sys.exc_info()
            if self._debug:
                debugger.post_mortem(tb, ex, val)
                tb = None
            rv = self.failed("%s: Exception occured! (%s: %s)" % (self.test_name, ex, val))
        endtime = timelib.now()
        minutes, seconds = divmod(endtime - teststarttime, 60.0)
        hours, minutes = divmod(minutes, 60.0)
        self.info("Time elapsed: %02.0f:%02.0f:%02.2f" % (hours, minutes, seconds))
        return self._finalize(rv)

    def _initialize(self, rv):
        try:
            self.initialize()
        except:
            ex, val, tb = sys.exc_info()
            self.diagnostic("%s (%s)" % (ex, val))
            if self._debug:
예제 #43
0
 def __call__(self, argv):
     if not argv or not argv[0] or argv[0].startswith("_"):
         return 2
     argv = self._expand_aliases(argv)
     # special escape characters...
     if argv[0].startswith("!"):  # bang-escape reads pipe
         argv[0] = argv[0][1:]
         argv.insert(0, "pipe")
     elif argv[0].startswith("%"):  # percent-escape spawns pty
         argv[0] = argv[0][1:]
         argv.insert(0, "spawn")
     elif argv[0].startswith("#"):  # comment
         return 0
     elif argv[0].startswith("@"):  # python exec escape
         argv[0] = argv[0][1:]
         argv.insert(0, "pyexec")
     elif argv[0].startswith("="):  # python eval escape
         argv[0] = argv[0][1:]
         argv.insert(0, "pyeval")
     # ok, now fetch the real method...
     try:
         meth = getattr(self, argv[0])
     except AttributeError:
         meth = self.default_command
     # ...and exec it.
     try:
         rv = meth(argv)  # call the method
     except (NewCommand, CommandQuit, CommandExit, KeyboardInterrupt):
         raise  # pass these through to parser
     except CLISyntaxError as err:
         self._ui.printf("%RSyntax error%N: {}".format(str(err.value)))
         self._ui.help_local(meth.__doc__)
     except IndexError:  # may have tried to get non-existent argv value.
         ex, val, tb = sys.exc_info()
         lev = 0
         t = tb
         while t.tb_next is not None:
             t = t.tb_next
             lev += 1
         if lev == 1:  # Happened inside the command method.
             self._ui.printf("%RInsufficient number of arguments.%N")
             self._ui.help_local(meth.__doc__)
         else:  # IndexError from something called by command method.
             if _DEBUG:
                 from pycopia import debugger
                 debugger.post_mortem(tb, ex, val)
             else:
                 self.except_hook(ex, val, tb)
     except getopt.GetoptError as err:
         self._print("option %r: %s" % (err.opt, err.msg))
     except:
         ex, val, tb = sys.exc_info()
         if _DEBUG:
             from pycopia import debugger  # import here due to circular dependency
             debugger.post_mortem(tb, ex, val)
         else:
             self.except_hook(ex, val, tb)
     else:
         if rv is not None:
             try:
                 self._environ["?"] = int(rv)
             except (ValueError, TypeError, AttributeError):
                 self._environ["?"] = 0
             self._environ["_"] = rv
         return rv
예제 #44
0
파일: core.py 프로젝트: llwang/powerdroid
        except TestFailError, errval:
            rv = self.Failed("Caught Fail exception: %s" % (errval, ))
        except TestIncompleteError, errval:
            rv = self.Incomplete("Caught Incomplete exception: %s" %
                                 (errval, ))
        # Test asserts and validation errors are based on this.
        except AssertionError, errval:
            rv = self.Failed("failed assertion: %s" % (errval, ))
        except TestSuiteAbort:
            raise  # pass this one up to suite
        except debugger.DebuggerQuit:  # set_trace "leaks" BdbQuit
            rv = self.Incomplete("%s: Debugger exit." % (self.test_name, ))
        except:
            ex, val, tb = sys.exc_info()
            if self._debug:
                debugger.post_mortem(tb, ex, val)
                tb = None
            rv = self.Incomplete("%s: Exception occured! (%s: %s)" % \
                    (self.test_name, ex, val))
        endtime = timelib.now()

        self._report.add_message("STARTTIME", teststarttime, 2)
        self._report.add_message("ENDTIME", endtime, 2)
        minutes, seconds = divmod(endtime - teststarttime, 60.0)
        hours, minutes = divmod(minutes, 60.0)
        self.Info("Time elapsed: %02.0f:%02.0f:%02.2f" %
                  (hours, minutes, seconds))
        return self._finalize(rv)

    def _initialize(self, rv):
        """initialize phase handler.