14 """Test of gRPC Python's interaction with the python logging module"""
23 INTERPRETER = sys.executable
34 if len(logging.getLogger().handlers) != 0:
35 raise Exception('expected 0 logging handlers')
47 self.assertEqual(0,
len(err),
'unexpected output to stderr')
57 intended_stream = six.StringIO()
58 logging.basicConfig(stream=intended_stream)
60 if len(logging.getLogger().handlers) != 1:
61 raise Exception('expected 1 logging handler')
63 if logging.getLogger().handlers[0].stream is not intended_stream:
64 raise Exception('wrong handler stream')
75 if "grpc" not in logging.Logger.manager.loggerDict:
76 raise Exception('grpc logger not found')
78 root_logger = logging.getLogger("grpc")
79 if len(root_logger.handlers) != 1:
80 raise Exception('expected 1 root logger handler')
81 if not isinstance(root_logger.handlers[0], logging.NullHandler):
82 raise Exception('expected logging.NullHandler')
88 process = subprocess.Popen([INTERPRETER,
'-c', script],
89 stdout=subprocess.PIPE,
90 stderr=subprocess.PIPE)
91 out, err = process.communicate()
93 0, process.returncode,
94 'process failed with exit code %d (stdout: %s, stderr: %s)' %
95 (process.returncode, out, err))
99 if __name__ ==
'__main__':
100 unittest.main(verbosity=2)