mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-25 11:15:34 +00:00
c1eaf010be
The ability to capture the parent process' stdio is suggested to be a useful feature to move from web-platform/tests into mozlog. To do so, I have created a new capture.py file within mozlog/mozlog. This includes the CaptureIO class and its dependencies, including the LoggingWrapper and LogThread classes. These have been removed from their original location, to avoid duplication, and the files depending on them updated accordingly. It would be useful to add unittests testing the CaptureIO enter and exit methods, and the original_stdio, logging_queue and logging_thread properties. I have begun such a file with test_capture.py in mozlog/tests. This is a work in progress, however I may need some guidance, please, in regards to creating appropriate mock data to assert. Differential Revision: https://phabricator.services.mozilla.com/D22166 --HG-- extra : moz-landing-system : lando
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from __future__ import absolute_import, print_function
|
|
import sys
|
|
import unittest
|
|
import mozunit
|
|
|
|
from test_structured import TestHandler
|
|
from mozlog import capture, structuredlog
|
|
|
|
|
|
class TestCaptureIO(unittest.TestCase):
|
|
"""Tests expected logging output of CaptureIO"""
|
|
|
|
def setUp(self):
|
|
self.logger = structuredlog.StructuredLogger("test")
|
|
self.handler = TestHandler()
|
|
self.logger.add_handler(self.handler)
|
|
|
|
def test_captureio_log(self):
|
|
"""
|
|
CaptureIO takes in two arguments. The second argument must
|
|
be truthy in order for the code to run. Hence, the string
|
|
"capture_stdio" has been used in this test case.
|
|
"""
|
|
with capture.CaptureIO(self.logger, "capture_stdio"):
|
|
print("message 1")
|
|
sys.stdout.write("message 2")
|
|
sys.stderr.write("message 3")
|
|
sys.stdout.write("\xff")
|
|
log = self.handler.items
|
|
messages = [item["message"] for item in log]
|
|
self.assertIn("STDOUT: message 1", messages)
|
|
self.assertIn("STDOUT: message 2", messages)
|
|
self.assertIn("STDERR: message 3", messages)
|
|
self.assertIn(u"STDOUT: \xff", messages)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
mozunit.main()
|