[elbe-devel] [PATCH 01/10] test: move testspecific system() implementation to test command

Torben Hohn torben.hohn at linutronix.de
Thu Apr 1 13:15:23 CEST 2021


The implementation of the test base classes currently resides
in elbepack.commands.test. Move the system() implementation
there.

Also change the Exception raised to ElbeTestException and allow
the test code to log the stdout of the test when the exception
is caught.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/commands/test.py  | 19 +++++++++++++++++++
 elbepack/tests/test_xml.py |  8 +-------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/elbepack/commands/test.py b/elbepack/commands/test.py
index 8c8585302..c67f7c04a 100644
--- a/elbepack/commands/test.py
+++ b/elbepack/commands/test.py
@@ -14,12 +14,31 @@ import warnings
 
 import junit_xml as junit
 
+from elbepack.shellhelper import command_out
+
 class ElbeTestLevel(enum.IntEnum):
     BASE   = enum.auto()
     EXTEND = enum.auto()
     INITVM = enum.auto()
     FULL   = enum.auto()
 
+class ElbeTestException(Exception):
+
+    def __init__(self, cmd, ret, out):
+        self.cmd = cmd
+        self.ret = ret
+        self.out = out
+
+    def __repr__(self):
+        return f"ElbeTestException: \"{self.cmd}\" returns {self.ret}"
+
+    def __str__(self):
+        return f"ElbeTestException: \"{self.cmd}\" returns {self.ret}"
+
+def system(cmd, allow_fail=False):
+    ret, out = command_out(cmd)
+    if ret != 0 and not allow_fail:
+        raise ElbeTestException(cmd, ret, out)
 
 class ElbeTestCase(unittest.TestCase):
 
diff --git a/elbepack/tests/test_xml.py b/elbepack/tests/test_xml.py
index 2b4881925..0f3069a37 100644
--- a/elbepack/tests/test_xml.py
+++ b/elbepack/tests/test_xml.py
@@ -8,13 +8,7 @@ import unittest
 import tempfile
 
 from elbepack.directories import elbe_dir, elbe_exe
-from elbepack.commands.test import ElbeTestCase, ElbeTestLevel
-from elbepack.shellhelper import command_out
-
-def system(cmd, allow_fail=False):
-    ret, out = command_out(cmd)
-    if ret != 0 and not allow_fail:
-        raise Exception(out)
+from elbepack.commands.test import ElbeTestCase, ElbeTestLevel, system
 
 @unittest.skipIf(ElbeTestCase.level < ElbeTestLevel.INITVM,
                  "Test level not set to INITVM")
-- 
2.20.1



More information about the elbe-devel mailing list