tests: Use a base class for testprocess lines.
This commit is contained in:
parent
da88908815
commit
f5f74b7ddc
@ -54,14 +54,13 @@ class NoLineMatch(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class LogLine:
|
||||
class LogLine(testprocess.Line):
|
||||
|
||||
"""A parsed line from the qutebrowser log output.
|
||||
|
||||
Attributes:
|
||||
timestamp/loglevel/category/module/function/line/message:
|
||||
Parsed from the log output.
|
||||
_line: The entire unparsed line.
|
||||
expected: Whether the message was expected or not.
|
||||
"""
|
||||
|
||||
@ -73,12 +72,11 @@ class LogLine:
|
||||
\ (?P<message>.+)
|
||||
""", re.VERBOSE)
|
||||
|
||||
def __init__(self, line):
|
||||
self._line = line
|
||||
match = self.LOG_RE.match(line)
|
||||
def __init__(self, data):
|
||||
super().__init__(data)
|
||||
match = self.LOG_RE.match(data)
|
||||
if match is None:
|
||||
raise NoLineMatch(line)
|
||||
self.__dict__.update(match.groupdict())
|
||||
raise NoLineMatch(data)
|
||||
|
||||
self.timestamp = datetime.datetime.strptime(match.group('timestamp'),
|
||||
'%H:%M:%S')
|
||||
@ -102,9 +100,6 @@ class LogLine:
|
||||
|
||||
self.expected = is_ignored_qt_message(self.message)
|
||||
|
||||
def __repr__(self):
|
||||
return 'LogLine({!r})'.format(self._line)
|
||||
|
||||
|
||||
class QuteProc(testprocess.Process):
|
||||
|
||||
|
@ -47,15 +47,6 @@ def stopwatch(min_ms=None, max_ms=None):
|
||||
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):
|
||||
|
||||
"""A testprocess which runs the given Python code."""
|
||||
@ -69,7 +60,7 @@ class PythonProcess(testprocess.Process):
|
||||
print("LINE: {}".format(line))
|
||||
if line.strip() == 'ready':
|
||||
self.ready.emit()
|
||||
return Line(line)
|
||||
return testprocess.Line(line)
|
||||
|
||||
def _executable_args(self):
|
||||
code = [
|
||||
|
@ -46,6 +46,21 @@ class WaitForTimeout(Exception):
|
||||
"""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):
|
||||
|
||||
"""Abstraction over a running test subprocess process.
|
||||
|
Loading…
Reference in New Issue
Block a user