MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_builtin_handlers

Method test_builtin_handlers

Lib/test/test_logging.py:607–658  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

605 self.assertRaises(NotImplementedError, h.emit, None)
606
607 def test_builtin_handlers(self):
608 # We can't actually *use* too many handlers in the tests,
609 # but we can try instantiating them with various options
610 if sys.platform in ('linux', 'android', 'darwin'):
611 for existing in (True, False):
612 fn = make_temp_file()
613 if not existing:
614 os.unlink(fn)
615 h = logging.handlers.WatchedFileHandler(fn, encoding='utf-8', delay=True)
616 if existing:
617 dev, ino = h.dev, h.ino
618 self.assertEqual(dev, -1)
619 self.assertEqual(ino, -1)
620 r = logging.makeLogRecord({'msg': 'Test'})
621 h.handle(r)
622 # Now remove the file.
623 os.unlink(fn)
624 self.assertFalse(os.path.exists(fn))
625 # The next call should recreate the file.
626 h.handle(r)
627 self.assertTrue(os.path.exists(fn))
628 else:
629 self.assertEqual(h.dev, -1)
630 self.assertEqual(h.ino, -1)
631 h.close()
632 if existing:
633 os.unlink(fn)
634 if sys.platform == 'darwin':
635 sockname = '/var/run/syslog'
636 else:
637 sockname = '/dev/log'
638 try:
639 h = logging.handlers.SysLogHandler(sockname)
640 self.assertEqual(h.facility, h.LOG_USER)
641 self.assertTrue(h.unixsocket)
642 h.close()
643 except OSError: # syslogd might not be available
644 pass
645 for method in ('GET', 'POST', 'PUT'):
646 if method == 'PUT':
647 self.assertRaises(ValueError, logging.handlers.HTTPHandler,
648 'localhost', '/log', method)
649 else:
650 h = logging.handlers.HTTPHandler('localhost', '/log', method)
651 h.close()
652 h = logging.handlers.BufferingHandler(0)
653 r = logging.makeLogRecord({})
654 self.assertTrue(h.shouldFlush(r))
655 h.close()
656 h = logging.handlers.BufferingHandler(1)
657 self.assertFalse(h.shouldFlush(r))
658 h.close()
659
660 def test_pathlike_objects(self):
661 """

Callers

nothing calls this directly

Calls 10

closeMethod · 0.95
shouldFlushMethod · 0.95
make_temp_fileFunction · 0.85
assertFalseMethod · 0.80
assertTrueMethod · 0.80
unlinkMethod · 0.45
assertEqualMethod · 0.45
handleMethod · 0.45
existsMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected