From f5f74b7ddc2e104eee16bc4b7f80d8925cda2a43 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 6 Nov 2015 06:49:36 +0100 Subject: [PATCH] tests: Use a base class for testprocess lines. --- tests/integration/quteprocess.py | 15 +++++---------- tests/integration/test_testprocess.py | 11 +---------- tests/integration/testprocess.py | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tests/integration/quteprocess.py b/tests/integration/quteprocess.py index 1367177e7..3d85828b8 100644 --- a/tests/integration/quteprocess.py +++ b/tests/integration/quteprocess.py @@ -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.+) """, 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): diff --git a/tests/integration/test_testprocess.py b/tests/integration/test_testprocess.py index f7feb21eb..0ad7e1240 100644 --- a/tests/integration/test_testprocess.py +++ b/tests/integration/test_testprocess.py @@ -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 = [ diff --git a/tests/integration/testprocess.py b/tests/integration/testprocess.py index 67cd6095b..4d516bdab 100644 --- a/tests/integration/testprocess.py +++ b/tests/integration/testprocess.py @@ -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.