diff --git a/test/runner/lib/test.py b/test/runner/lib/test.py index eeaac39889c..20c514026ad 100644 --- a/test/runner/lib/test.py +++ b/test/runner/lib/test.py @@ -6,6 +6,8 @@ import datetime import json import os +import lib.types as t + from lib.util import ( display, make_dirs, @@ -246,7 +248,7 @@ class TestFailure(TestResult): super(TestFailure, self).__init__(command, test, python_version) if messages: - messages = sorted(messages, key=lambda m: m.sort_key) + messages = sorted(messages) else: messages = [] @@ -430,14 +432,71 @@ class TestMessage: :type code: str | None :type confidence: int | None """ - self.path = path - self.line = line - self.column = column - self.level = level - self.code = code - self.message = message + self.__path = path + self.__line = line + self.__column = column + self.__level = level + self.__code = code + self.__message = message + self.confidence = confidence + @property + def path(self): # type: () -> str + """Return the path.""" + return self.__path + + @property + def line(self): # type: () -> int + """Return the line number, or 0 if none is available.""" + return self.__line + + @property + def column(self): # type: () -> int + """Return the column number, or 0 if none is available.""" + return self.__column + + @property + def level(self): # type: () -> str + """Return the level.""" + return self.__level + + @property + def code(self): # type: () -> t.Optional[str] + """Return the code, if any.""" + return self.__code + + @property + def message(self): # type: () -> str + """Return the message.""" + return self.__message + + @property + def tuple(self): # type: () -> t.Tuple[str, int, int, str, t.Optional[str], str] + """Return a tuple with all the immutable values of this test message.""" + return self.__path, self.__line, self.__column, self.__level, self.__code, self.__message + + def __lt__(self, other): + return self.tuple < other.tuple + + def __le__(self, other): + return self.tuple <= other.tuple + + def __eq__(self, other): + return self.tuple == other.tuple + + def __ne__(self, other): + return self.tuple != other.tuple + + def __gt__(self, other): + return self.tuple > other.tuple + + def __ge__(self, other): + return self.tuple >= other.tuple + + def __hash__(self): + return hash(self.tuple) + def __str__(self): return self.format() @@ -446,19 +505,12 @@ class TestMessage: :type show_confidence: bool :rtype: str """ - if self.code: - msg = '%s %s' % (self.code, self.message) + if self.__code: + msg = '%s %s' % (self.__code, self.__message) else: - msg = self.message + msg = self.__message if show_confidence and self.confidence is not None: msg += ' (%d%%)' % self.confidence - return '%s:%s:%s: %s' % (self.path, self.line, self.column, msg) - - @property - def sort_key(self): - """ - :rtype: str - """ - return '%s:%6d:%6d:%s:%s' % (self.path, self.line, self.column, self.code or '', self.message) + return '%s:%s:%s: %s' % (self.__path, self.__line, self.__column, msg)