[bitbake-devel] [PATCH 4/7] tests/data: extract LogRecord into own file
Urs Fässler
urs.fassler at bbv.ch
Wed Oct 3 12:04:07 UTC 2018
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 at bbv.ch>
Signed-off-by: Pascal Bach <pascal.bach at 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
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
--
2.19.0
More information about the bitbake-devel
mailing list