def __repr__(self):
level = getLevelName(self.level)
name = getattr(self.stream, 'name', '')
+ # bpo-36015: name can be an int
+ name = str(name)
if name:
name += ' '
return '<%s %s(%s)>' % (self.__class__.__name__, name, level)
def handleError(self, record):
self.error_record = record
+class StreamWithIntName(object):
+ level = logging.NOTSET
+ name = 2
+
class StreamHandlerTest(BaseTest):
def test_error_handling(self):
h = TestStreamHandler(BadStream())
actual = h.setStream(old)
self.assertIsNone(actual)
+ def test_can_represent_stream_with_int_name(self):
+ h = logging.StreamHandler(StreamWithIntName())
+ self.assertEqual(repr(h), '<StreamHandler 2 (NOTSET)>')
+
# -- The following section could be moved into a server_helper.py module
# -- if it proves to be of wider utility than just test_logging