Exemple #1
0
def test_format_exception_context1():
    """ Utils.format_exception_context with valid arguments. """
    try:
        raise ValueError("ioshivfq")
    except ValueError:
        message = Utils.format_exception_context(*sys.exc_info())
        assert re.search("Exception <type 'exceptions.ValueError'> occured " +
                         "\(in context.*: ioshivfq", message)
Exemple #2
0
def test_format_exception_context1():
    """ Utils.format_exception_context with valid arguments. """
    try:
        raise ValueError("ioshivfq")
    except ValueError:
        message = Utils.format_exception_context(*sys.exc_info())
        assert re.search("Exception <type 'exceptions.ValueError'> occured " +
                         "\(in context.*: ioshivfq", message)
Exemple #3
0
    def next(self):
        """Return next object constructed from a suitable XML element

        Reads the 'next' element and returns an object constructed out of it,
        if at all possible. The object construction is dispatched to
        subclasses (via next_object). If the object construction fails,
        next_object should return None.

        This method would consume subsequent XML elements/subtrees until a
        suitable object can be constructed or we run out of XML elements. In
        the latter case StopIteration is thrown (as per iterator protocol).

        IVR 2007-12-25 TBD: releasing the memory occupied by subtrees is quite
        helpful, but very ugly in this code. This should be implemented more
        elegantly.
        """

        import sys
        while 1:
            try:
                # Fetch the next XML subtree...
                element = self._xmliter.next()
                # ... and dispatch to subclass to create an object
                obj = self.next_object(element)

                # free the memory in the ElementTree framework.
                element.clear()

                # IVR 2007-12-28 TBD: Do we want some generic 'no object
                # created' error message here? The problem with such a message
                # is that it is difficult to ignore a separate generic error
                # line in the logs. Typically, when obj is None,
                # next_element() would have made (or at least, it should have)
                # some sort of error message which explains far better what
                # went wrong, thus making a generic message here somewhat
                # moot.
                if obj is not None:
                    return obj
            except StopIteration:
                raise
            except:
                # If *any* sort of exception occurs, log this, and continue
                # with the parsing. We cannot afford one defective entry to
                # break down the entire data import run.
                if self.logger:
                    self.logger.warn(
                        "%s occurred while processing XML element %s. "
                        "Skipping it.",
                        Utils.format_exception_context(*sys.exc_info()),
                        element.tag)
                element.clear()
Exemple #4
0
    def next(self):
        """Return next object constructed from a suitable XML element

        Reads the 'next' element and returns an object constructed out of it,
        if at all possible. The object construction is dispatched to
        subclasses (via next_object). If the object construction fails,
        next_object should return None.

        This method would consume subsequent XML elements/subtrees until a
        suitable object can be constructed or we run out of XML elements. In
        the latter case StopIteration is thrown (as per iterator protocol).

        IVR 2007-12-25 TBD: releasing the memory occupied by subtrees is quite
        helpful, but very ugly in this code. This should be implemented more
        elegantly.
        """

        import sys
        while 1:
            try:
                # Fetch the next XML subtree...
                element = self._xmliter.next()
                # ... and dispatch to subclass to create an object
                obj = self.next_object(element)

                # free the memory in the ElementTree framework.
                element.clear()

                # IVR 2007-12-28 TBD: Do we want some generic 'no object
                # created' error message here? The problem with such a message
                # is that it is difficult to ignore a separate generic error
                # line in the logs. Typically, when obj is None,
                # next_element() would have made (or at least, it should have)
                # some sort of error message which explains far better what
                # went wrong, thus making a generic message here somewhat
                # moot.
                if obj is not None:
                    return obj
            except StopIteration:
                raise
            except:
                # If *any* sort of exception occurs, log this, and continue
                # with the parsing. We cannot afford one defective entry to
                # break down the entire data import run.
                if self.logger:
                    self.logger.warn(
                        "%s occurred while processing XML element %s. "
                        "Skipping it.",
                        Utils.format_exception_context(*sys.exc_info()),
                        element.tag)
                element.clear()
Exemple #5
0
def test_format_exception_context_no_exc():
    """ Utils.format_exception_context with empty arguments. """
    retval = Utils.format_exception_context(None, None, None)
    assert retval == ''
def test_format_exception_context_no_exc():
    """ Utils.format_exception_context with empty arguments. """
    retval = Utils.format_exception_context(None, None, None)
    assert retval == ''