tests: Use a base class for testprocess lines.

This commit is contained in:
Florian Bruhin 2015-11-06 06:49:36 +01:00
parent da88908815
commit f5f74b7ddc
3 changed files with 21 additions and 20 deletions

View File

@ -54,14 +54,13 @@ class NoLineMatch(Exception):
pass pass
class LogLine: class LogLine(testprocess.Line):
"""A parsed line from the qutebrowser log output. """A parsed line from the qutebrowser log output.
Attributes: Attributes:
timestamp/loglevel/category/module/function/line/message: timestamp/loglevel/category/module/function/line/message:
Parsed from the log output. Parsed from the log output.
_line: The entire unparsed line.
expected: Whether the message was expected or not. expected: Whether the message was expected or not.
""" """
@ -73,12 +72,11 @@ class LogLine:
\ (?P<message>.+) \ (?P<message>.+)
""", re.VERBOSE) """, re.VERBOSE)
def __init__(self, line): def __init__(self, data):
self._line = line super().__init__(data)
match = self.LOG_RE.match(line) match = self.LOG_RE.match(data)
if match is None: if match is None:
raise NoLineMatch(line) raise NoLineMatch(data)
self.__dict__.update(match.groupdict())
self.timestamp = datetime.datetime.strptime(match.group('timestamp'), self.timestamp = datetime.datetime.strptime(match.group('timestamp'),
'%H:%M:%S') '%H:%M:%S')
@ -102,9 +100,6 @@ class LogLine:
self.expected = is_ignored_qt_message(self.message) self.expected = is_ignored_qt_message(self.message)
def __repr__(self):
return 'LogLine({!r})'.format(self._line)
class QuteProc(testprocess.Process): class QuteProc(testprocess.Process):

View File

@ -47,15 +47,6 @@ def stopwatch(min_ms=None, max_ms=None):
assert delta_ms <= max_ms assert delta_ms <= max_ms
class Line:
def __init__(self, data):
self.data = data
def __repr__(self):
return 'Line({!r})'.format(self.data)
class PythonProcess(testprocess.Process): class PythonProcess(testprocess.Process):
"""A testprocess which runs the given Python code.""" """A testprocess which runs the given Python code."""
@ -69,7 +60,7 @@ class PythonProcess(testprocess.Process):
print("LINE: {}".format(line)) print("LINE: {}".format(line))
if line.strip() == 'ready': if line.strip() == 'ready':
self.ready.emit() self.ready.emit()
return Line(line) return testprocess.Line(line)
def _executable_args(self): def _executable_args(self):
code = [ code = [

View File

@ -46,6 +46,21 @@ class WaitForTimeout(Exception):
"""Raised when wait_for didn't get the expected message.""" """Raised when wait_for didn't get the expected message."""
class Line:
"""Container for a line of data the process emits.
Attributes:
data: The raw data passed to the constructor.
"""
def __init__(self, data):
self.data = data
def __repr__(self):
return '{}({!r})'.format(self.__class__.__name__, self.data)
class Process(QObject): class Process(QObject):
"""Abstraction over a running test subprocess process. """Abstraction over a running test subprocess process.