* [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
* Re: [PATCH] tests/data: Add log parsing test code
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
1 sibling, 1 reply; 4+ messages in thread
From: Christopher Larson @ 2015-05-26 15:26 UTC (permalink / raw)
To: Richard Purdie; +Cc: bitbake-devel
[-- Attachment #1: Type: text/plain, Size: 905 bytes --]
On Tue, May 26, 2015 at 8:17 AM, Richard Purdie <
richard.purdie@linuxfoundation.org> wrote:
> +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
>
I realize it probably doesn’t matter in the testing case specifically, but
this lies to the user of the class. Using a context manager that doesn’t
undo what it’s done on exit.. :)
--
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
[-- Attachment #2: Type: text/html, Size: 1463 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tests/data: Add log parsing test code
2015-05-26 15:26 ` Christopher Larson
@ 2015-05-27 16:34 ` Richard Purdie
0 siblings, 0 replies; 4+ messages in thread
From: Richard Purdie @ 2015-05-27 16:34 UTC (permalink / raw)
To: Christopher Larson; +Cc: bitbake-devel
On Tue, 2015-05-26 at 08:26 -0700, Christopher Larson wrote:
>
> On Tue, May 26, 2015 at 8:17 AM, Richard Purdie
> <richard.purdie@linuxfoundation.org> wrote:
> +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
>
> I realize it probably doesn’t matter in the testing case specifically,
> but this lies to the user of the class. Using a context manager that
> doesn’t undo what it’s done on exit.. :)
Er, yes, quite. I knew there was something I'd meant to go back and do
once it worked. I've posted a v2 with that fixed.
Cheers,
Richard
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tests/data: Add log parsing test code
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:52 ` Christopher Larson
1 sibling, 0 replies; 4+ messages in thread
From: Christopher Larson @ 2015-05-27 16:52 UTC (permalink / raw)
To: Richard Purdie; +Cc: bitbake-devel
[-- Attachment #1: Type: text/plain, Size: 574 bytes --]
On Tue, May 26, 2015 at 8:17 AM, Richard Purdie <
richard.purdie@linuxfoundation.org> wrote:
> +def LogContains(item, logs):
> + for l in logs:
> + m = l.getMessage()
> + if item in m:
> + return True
> + return False
>
I didn’t notice at first, but this doesn’t comply with PEP8 — camelcase is
for use with class names, not function names. Minor, obviously :)
--
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
[-- Attachment #2: Type: text/html, Size: 998 bytes --]
^ permalink raw reply [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.