Append error log to output header
authorReto Buerki <reet@codelabs.ch>
Thu, 14 Sep 2017 12:42:02 +0000 (14:42 +0200)
committerReto Buerki <reet@codelabs.ch>
Fri, 15 Sep 2017 07:16:18 +0000 (09:16 +0200)
This makes it more evident that warnings/errors occurred during XML
generation.

src/output.py
test/test_output.py

index fe916dc..eea2bec 100644 (file)
@@ -147,6 +147,15 @@ def produce_biosinfo():
     return result, success
 
 
+def produce_log():
+    "Append warnings and errors during generation"
+    if message.messagequeue:
+        result = produceLine("Log:", SPACES_MAIN)
+        for msg in message.messagequeue:
+            result += produceLine(msg.to_str(), SPACES_SUB)
+    return result, True
+
+
 def produce_productinfo():
     "Produces product information"
     success = True
@@ -231,6 +240,7 @@ def genXML(elemtree, encoding):
         produce_productinfo,
         produce_boardinfo,
         produce_biosinfo,
+        produce_log,
     )
 
     # Combine declaration with header and body
index c37cffd..4368144 100644 (file)
@@ -26,6 +26,7 @@ import pytest
 import pyxb
 
 import src.output as output
+import src.message as message
 import src.schemadata
 from src import customExceptions
 from src import parseutil
@@ -263,6 +264,20 @@ class TestOutput:
         assert test_success()[1] is True
         assert test_fail()[1] is False
 
+    def test_produce_productinfo(self):
+
+        successline = ("""     Log:\n       * WARNING *: Warning1\n""")
+
+        mock_queue = []
+        mock_queue.append(message.WarningMessage("Warning1"))
+
+        @mock.patch.object(message, "messagequeue", mock_queue)
+        def test_success():
+            print output.produce_log()
+            return output.produce_log()
+
+        assert test_success() == (successline, True)
+
     def test_runCommand(self):
 
         def command_fail(*args, **kwargs):