summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-07-28 10:58:08 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-09-18 13:27:36 +0200
commit0b314499a0f5f3dd52d99a6d0a6fd88edd132d92 (patch)
tree905f8e1243887c60731b74074bb837d61c1b7119
parent05e4cb2c83bea63b46d878e9bbea42f188f0d48f (diff)
downloadrtems-central-0b314499a0f5f3dd52d99a6d0a6fd88edd132d92.tar.bz2
tests: Add and use get_and_clear_log()
-rw-r--r--rtemsspec/tests/test_specverify.py17
-rw-r--r--rtemsspec/tests/util.py7
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