def test_reset(self): captured = Captured("STDOUT", "STDERR", "LOG_OUTPUT") captured.reset() assert captured.stdout == u"" assert captured.stderr == u"" assert captured.log_output == u"" assert not captured
class BasicStatement(object): def __init__(self, filename, line, keyword, name): filename = filename or '<string>' filename = os.path.relpath(filename, os.getcwd()) # -- NEEDS: abspath? self.location = FileLocation(filename, line) assert isinstance(keyword, six.text_type) assert isinstance(name, six.text_type) self.keyword = keyword self.name = name # -- SINCE: 1.2.6 self.captured = Captured() # -- ERROR CONTEXT INFO: self.exception = None self.exc_traceback = None self.error_message = None @property def filename(self): # return os.path.abspath(self.location.filename) return self.location.filename @property def line(self): return self.location.line def reset(self): # -- RESET: Captured output data self.captured.reset() # -- RESET: ERROR CONTEXT INFO self.exception = None self.exc_traceback = None self.error_message = None def store_exception_context(self, exception): self.exception = exception self.exc_traceback = sys.exc_info()[2] def __hash__(self): # -- NEEDED-FOR: PYTHON3 # return id((self.keyword, self.name)) return id(self) def __eq__(self, other): # -- PYTHON3 SUPPORT, ORDERABLE: # NOTE: Ignore potential FileLocation differences. return (self.keyword, self.name) == (other.keyword, other.name) def __lt__(self, other): # -- PYTHON3 SUPPORT, ORDERABLE: # NOTE: Ignore potential FileLocation differences. return (self.keyword, self.name) < (other.keyword, other.name) def __ne__(self, other): return not self.__eq__(other) def __le__(self, other): # -- SEE ALSO: python2.7, functools.total_ordering # return not other < self return other >= self def __gt__(self, other): # -- SEE ALSO: python2.7, functools.total_ordering assert isinstance(other, BasicStatement) return other < self def __ge__(self, other): # -- SEE ALSO: python2.7, functools.total_ordering # OR: return self >= other return not self < other # pylint: disable=unneeded-not
class BasicStatement(object): def __init__(self, filename, line, keyword, name): filename = filename or '<string>' filename = os.path.relpath(filename, os.getcwd()) # -- NEEDS: abspath? self.location = FileLocation(filename, line) assert isinstance(keyword, six.text_type) assert isinstance(name, six.text_type) self.keyword = keyword self.name = name # -- SINCE: 1.2.6 self.captured = Captured() # -- ERROR CONTEXT INFO: self.exception = None self.exc_traceback = None self.error_message = None @property def filename(self): # return os.path.abspath(self.location.filename) return self.location.filename @property def line(self): return self.location.line def reset(self): # -- RESET: Captured output data self.captured.reset() # -- RESET: ERROR CONTEXT INFO self.exception = None self.exc_traceback = None self.error_message = None def send_status(self): """Emit the volatile attributes of this model in a primitive dict """ ret = { 'exception': self.exception, 'error_message': self.error_message, 'exc_traceback': self.exc_traceback, 'captured': self.captured.send_status() } return ret def recv_status(self, value): """Set volatile attributes from a `send_status()` primitive value """ for key in 'exception', 'error_message', 'exc_traceback': if key in value: setattr(self, key, value[key]) if 'captured' in value: self.captured.recv_status(value['captured']) def store_exception_context(self, exception): self.exception = exception self.exc_traceback = traceback.format_tb(sys.exc_info()[2]) def __hash__(self): # -- NEEDED-FOR: PYTHON3 # return id((self.keyword, self.name)) return id(self) def __eq__(self, other): # -- PYTHON3 SUPPORT, ORDERABLE: # NOTE: Ignore potential FileLocation differences. return (self.keyword, self.name) == (other.keyword, other.name) def __lt__(self, other): # -- PYTHON3 SUPPORT, ORDERABLE: # NOTE: Ignore potential FileLocation differences. return (self.keyword, self.name) < (other.keyword, other.name) def __ne__(self, other): return not self.__eq__(other) def __le__(self, other): # -- SEE ALSO: python2.7, functools.total_ordering # return not other < self return other >= self def __gt__(self, other): # -- SEE ALSO: python2.7, functools.total_ordering assert isinstance(other, BasicStatement) return other < self def __ge__(self, other): # -- SEE ALSO: python2.7, functools.total_ordering # OR: return self >= other return not self < other # pylint: disable=unneeded-not