[bitbake-devel,4/9] tests/data: extract LogRecord into own file

Submitted by Urs Fässler on July 23, 2018, 3:42 p.m. | Patch ID: 152879

Details

Message ID 20180723154259.9076-5-urs.fassler@bbv.ch
State New
Headers show

Commit Message

Urs Fässler July 23, 2018, 3:42 p.m.
LogRecord is a mechanism to capture the log output. It is used in the
data tests. It is moved into its own file to be used by other tests.

Signed-off-by: Urs Fässler <urs.fassler@bbv.ch>
Signed-off-by: Pascal Bach <pascal.bach@siemens.com>
---
 lib/bb/tests/data.py      | 25 +------------------
 lib/bb/tests/logrecord.py | 51 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 24 deletions(-)
 create mode 100644 lib/bb/tests/logrecord.py

Patch hide | download patch | download mbox

diff --git a/lib/bb/tests/data.py b/lib/bb/tests/data.py
index a4a9dd30..e8121a21 100644
--- a/lib/bb/tests/data.py
+++ b/lib/bb/tests/data.py
@@ -24,30 +24,7 @@  import unittest
 import bb
 import bb.data
 import bb.parse
-import logging
-
-class LogRecord():
-    def __enter__(self):
-        logs = []
-        class LogHandler(logging.Handler):
-            def emit(self, record):
-                logs.append(record)
-        logger = logging.getLogger("BitBake")
-        handler = LogHandler()
-        self.handler = handler
-        logger.addHandler(handler)
-        return logs
-    def __exit__(self, type, value, traceback):
-        logger = logging.getLogger("BitBake")
-        logger.removeHandler(self.handler)
-        return
-
-def logContains(item, logs):
-    for l in logs:
-        m = l.getMessage()
-        if item in m:
-            return True
-    return False
+from bb.tests.logrecord import LogRecord, logContains
 
 class DataExpansions(unittest.TestCase):
     def setUp(self):
diff --git a/lib/bb/tests/logrecord.py b/lib/bb/tests/logrecord.py
new file mode 100644
index 00000000..2693e4ff
--- /dev/null
+++ b/lib/bb/tests/logrecord.py
@@ -0,0 +1,51 @@ 
+# ex:ts=4:sw=4:sts=4:et
+# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
+#
+# BitBake Tests for the Data Store (data.py/data_smart.py)
+#
+# Copyright (C) 2010 Chris Larson
+# Copyright (C) 2012 Richard Purdie
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+import logging
+
+
+class LogRecord():
+    def __enter__(self):
+        logs = []
+
+        class LogHandler(logging.Handler):
+            def emit(self, record):
+                logs.append(record)
+
+        logger = logging.getLogger("BitBake")
+        handler = LogHandler()
+        self.handler = handler
+        logger.addHandler(handler)
+        return logs
+
+    def __exit__(self, type, value, traceback):
+        logger = logging.getLogger("BitBake")
+        logger.removeHandler(self.handler)
+        return
+
+
+def logContains(item, logs):
+    for l in logs:
+        m = l.getMessage()
+        if item in m:
+            return True
+    return False