All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tests/data: Add log parsing test code
@ 2015-05-26 15:17 Richard Purdie
  2015-05-26 15:26 ` Christopher Larson
  2015-05-27 16:52 ` Christopher Larson
  0 siblings, 2 replies; 4+ messages in thread
From: Richard Purdie @ 2015-05-26 15:17 UTC (permalink / raw)
  To: bitbake-devel

This allows us to write tests which ensure a particular action generates
a particular log message.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>

diff --git a/bitbake/lib/bb/tests/data.py b/bitbake/lib/bb/tests/data.py
index 7994a88..6ed80fb 100644
--- a/bitbake/lib/bb/tests/data.py
+++ b/bitbake/lib/bb/tests/data.py
@@ -25,6 +25,28 @@ import bb
 import bb.data
 import bb.parse
 
+class LogRecord():
+    def __enter__(self):
+        import logging
+        logs = []
+        class LogHandler(logging.Handler):
+            def emit(self, record):
+                logs.append(record)
+
+        logger = logging.getLogger("BitBake")
+        handler = LogHandler()
+        logger.addHandler(handler)
+        return logs
+    def __exit__(self, type, value, traceback):
+        return
+
+def LogContains(item, logs):
+    for l in logs:
+        m = l.getMessage()
+        if item in m:
+            return True
+    return False
+
 class DataExpansions(unittest.TestCase):
     def setUp(self):
         self.d = bb.data.init()




^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-05-27 16:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-26 15:17 [PATCH] tests/data: Add log parsing test code Richard Purdie
2015-05-26 15:26 ` Christopher Larson
2015-05-27 16:34   ` Richard Purdie
2015-05-27 16:52 ` Christopher Larson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.