[rtems-central commit] tests: Add and use get_and_clear_log()

Sebastian Huber sebh at rtems.org
Fri Sep 18 11:31:55 UTC 2020


Module:    rtems-central
Branch:    master
Commit:    0b314499a0f5f3dd52d99a6d0a6fd88edd132d92
Changeset: http://git.rtems.org/rtems-central/commit/?id=0b314499a0f5f3dd52d99a6d0a6fd88edd132d92

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Jul 28 10:58:08 2020 +0200

tests: Add and use get_and_clear_log()

---

 rtemsspec/tests/test_specverify.py | 17 +++++++----------
 rtemsspec/tests/util.py            |  7 +++++++
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/rtemsspec/tests/test_specverify.py b/rtemsspec/tests/test_specverify.py
index 076a6fa..c382820 100644
--- a/rtemsspec/tests/test_specverify.py
+++ b/rtemsspec/tests/test_specverify.py
@@ -28,7 +28,8 @@ import logging
 
 from rtemsspec.items import ItemCache
 from rtemsspec.specverify import verify
-from rtemsspec.tests.util import create_item_cache_config_and_copy_spec
+from rtemsspec.tests.util import create_item_cache_config_and_copy_spec, \
+    get_and_clear_log
 
 
 def test_no_root_type(caplog, tmpdir):
@@ -38,9 +39,8 @@ def test_no_root_type(caplog, tmpdir):
     config = {}
     caplog.set_level(logging.INFO)
     verify(config, item_cache)
-    log = "\n".join(
-        [f"{rec.levelname} {rec.message}" for rec in caplog.records])
-    assert log == """ERROR configuration has no root type"""
+    assert get_and_clear_log(
+        caplog) == """ERROR configuration has no root type"""
 
 
 def test_no_root_item(caplog, tmpdir):
@@ -50,9 +50,8 @@ def test_no_root_item(caplog, tmpdir):
     config = {"root-type": "/nix"}
     caplog.set_level(logging.INFO)
     verify(config, item_cache)
-    log = "\n".join(
-        [f"{rec.levelname} {rec.message}" for rec in caplog.records])
-    assert log == """ERROR root type item does not exist in item cache"""
+    assert get_and_clear_log(
+        caplog) == """ERROR root type item does not exist in item cache"""
 
 
 def test_verify(caplog, tmpdir):
@@ -62,9 +61,7 @@ def test_verify(caplog, tmpdir):
     config = {"root-type": "/spec/root"}
     caplog.set_level(logging.INFO)
     verify(config, item_cache)
-    log = "\n".join(
-        [f"{rec.levelname} {rec.message}" for rec in caplog.records])
-    assert log == """INFO type: any-dict
+    assert get_and_clear_log(caplog) == """INFO type: any-dict
 INFO type: bool
 INFO type: c
 INFO type: copyright
diff --git a/rtemsspec/tests/util.py b/rtemsspec/tests/util.py
index d07df74..ccece8e 100644
--- a/rtemsspec/tests/util.py
+++ b/rtemsspec/tests/util.py
@@ -51,3 +51,10 @@ def create_item_cache_config_and_copy_spec(
     else:
         config["spec-type-root-uid"] = None
     return config
+
+
+def get_and_clear_log(the_caplog) -> str:
+    log = "\n".join(f"{rec.levelname} {rec.message}"
+                    for rec in the_caplog.records)
+    the_caplog.clear()
+    return log



More information about the vc mailing list