diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-05-27 17:33:16 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-05-29 10:17:16 +0100 |
commit | bde0f60971c3c9b758b31fae7cf243e70b3833ff (patch) | |
tree | 2fab1f3979f39a7aa92f1a1fa40678b7695da363 /bitbake/lib | |
parent | 8d8b02aacde8d9fb87a55a7c200a4519bfbe8631 (diff) | |
download | poky-bde0f60971c3c9b758b31fae7cf243e70b3833ff.tar.gz |
bitbake: tests/data: Add log parsing test code
This allows us to write tests which ensure a particular action generates
a particular log message.
(Bitbake rev: b30ee0aba51a35a194a4338b988f93ece1ed281c)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/bb/tests/data.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/bitbake/lib/bb/tests/data.py b/bitbake/lib/bb/tests/data.py index 7994a88a78..b4e90e0327 100644 --- a/bitbake/lib/bb/tests/data.py +++ b/bitbake/lib/bb/tests/data.py | |||
@@ -24,6 +24,30 @@ import unittest | |||
24 | import bb | 24 | import bb |
25 | import bb.data | 25 | import bb.data |
26 | import bb.parse | 26 | import bb.parse |
27 | import logging | ||
28 | |||
29 | class LogRecord(): | ||
30 | def __enter__(self): | ||
31 | logs = [] | ||
32 | class LogHandler(logging.Handler): | ||
33 | def emit(self, record): | ||
34 | logs.append(record) | ||
35 | logger = logging.getLogger("BitBake") | ||
36 | handler = LogHandler() | ||
37 | self.handler = handler | ||
38 | logger.addHandler(handler) | ||
39 | return logs | ||
40 | def __exit__(self, type, value, traceback): | ||
41 | logger = logging.getLogger("BitBake") | ||
42 | logger.removeHandler(self.handler) | ||
43 | return | ||
44 | |||
45 | def logContains(item, logs): | ||
46 | for l in logs: | ||
47 | m = l.getMessage() | ||
48 | if item in m: | ||
49 | return True | ||
50 | return False | ||
27 | 51 | ||
28 | class DataExpansions(unittest.TestCase): | 52 | class DataExpansions(unittest.TestCase): |
29 | def setUp(self): | 53 | def setUp(self): |
@@ -301,7 +325,6 @@ class TestOverrides(unittest.TestCase): | |||
301 | bb.data.update_data(self.d) | 325 | bb.data.update_data(self.d) |
302 | self.assertEqual(self.d.getVar("TEST", True), "testvalue3") | 326 | self.assertEqual(self.d.getVar("TEST", True), "testvalue3") |
303 | 327 | ||
304 | |||
305 | class TestFlags(unittest.TestCase): | 328 | class TestFlags(unittest.TestCase): |
306 | def setUp(self): | 329 | def setUp(self): |
307 | self.d = bb.data.init() | 330 | self.d = bb.data.init() |