summaryrefslogtreecommitdiff
path: root/tko
diff options
context:
space:
mode:
Diffstat (limited to 'tko')
-rw-r--r--tko/parsers/version_1.py2
-rw-r--r--tko/utils.py19
-rw-r--r--tko/utils_unittest.py27
3 files changed, 48 insertions, 0 deletions
diff --git a/tko/parsers/version_1.py b/tko/parsers/version_1.py
index fb82a99d..ab3a62c4 100644
--- a/tko/parsers/version_1.py
+++ b/tko/parsers/version_1.py
@@ -292,6 +292,8 @@ class parser(base.parser):
# update the status of a currently running test
if running_test:
running_reasons.add(line.reason)
+ running_reasons = tko_utils.drop_redundant_messages(
+ running_reasons)
sorted_reasons = sorted(running_reasons)
running_test.reason = ", ".join(sorted_reasons)
current_reason = running_test.reason
diff --git a/tko/utils.py b/tko/utils.py
index 8fc3711f..1bd1bf46 100644
--- a/tko/utils.py
+++ b/tko/utils.py
@@ -30,3 +30,22 @@ def find_toplevel_job_dir(start_dir):
return None
job_dir = os.path.dirname(job_dir)
return job_dir
+
+
+def drop_redundant_messages(messages):
+ """ Given a set of message strings discard any 'redundant' messages which
+ are simple a substring of the existing ones.
+
+ @param messages - a set of message strings
+
+ @return - a subset of messages with unnecessary strings dropped
+ """
+ sorted_messages = sorted(messages, key=len, reverse=True)
+ filtered_messages = set()
+ for message in sorted_messages:
+ for filtered_message in filtered_messages:
+ if message in filtered_message:
+ break
+ else:
+ filtered_messages.add(message)
+ return filtered_messages
diff --git a/tko/utils_unittest.py b/tko/utils_unittest.py
index 2a04191d..7d184079 100644
--- a/tko/utils_unittest.py
+++ b/tko/utils_unittest.py
@@ -98,6 +98,33 @@ class find_toplevel_job_dir_test(unittest.TestCase):
self.assertEqual(utils.find_toplevel_job_dir(jobdir), None)
+class drop_redundant_messages(unittest.TestCase):
+ def test_empty_set(self):
+ self.assertEqual(utils.drop_redundant_messages(set()), set())
+
+
+ def test_singleton(self):
+ self.assertEqual(utils.drop_redundant_messages(set(["abc"])),
+ set(["abc"]))
+
+
+ def test_distinct_messages(self):
+ self.assertEqual(utils.drop_redundant_messages(set(["abc", "def"])),
+ set(["abc", "def"]))
+
+
+ def test_one_unique_message(self):
+ self.assertEqual(
+ utils.drop_redundant_messages(set(["abc", "abcd", "abcde"])),
+ set(["abcde"]))
+
+
+ def test_some_unique_some_not(self):
+ self.assertEqual(
+ utils.drop_redundant_messages(set(["abc", "def", "abcdef",
+ "defghi", "cd"])),
+ set(["abcdef", "defghi"]))
+
if __name__ == "__main__":
unittest.main()