MCPcopy Index your code
hub / github.com/python/cpython / test_basic

Method test_basic

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

Source from the content-addressed store, hash-verified

7279class NTEventLogHandlerTest(BaseTest):
7280 @unittest.skipUnless(win32evtlog, 'win32evtlog/win32evtlogutil/pywintypes required for this test.')
7281 def test_basic(self):
7282 logtype = 'Application'
7283 elh = win32evtlog.OpenEventLog(None, logtype)
7284 num_recs = win32evtlog.GetNumberOfEventLogRecords(elh)
7285
7286 try:
7287 h = logging.handlers.NTEventLogHandler('test_logging')
7288 except pywintypes.error as e:
7289 if e.winerror == 5: # access denied
7290 raise unittest.SkipTest('Insufficient privileges to run test')
7291 raise
7292
7293 r = logging.makeLogRecord({'msg': 'Test Log Message'})
7294 h.handle(r)
7295 h.close()
7296 # Now see if the event is recorded
7297 self.assertLess(num_recs, win32evtlog.GetNumberOfEventLogRecords(elh))
7298 flags = win32evtlog.EVENTLOG_BACKWARDS_READ | \
7299 win32evtlog.EVENTLOG_SEQUENTIAL_READ
7300 found = False
7301 GO_BACK = 100
7302 events = win32evtlog.ReadEventLog(elh, flags, GO_BACK)
7303 for e in events:
7304 if e.SourceName != 'test_logging':
7305 continue
7306 msg = win32evtlogutil.SafeFormatMessage(e, logtype)
7307 if msg != 'Test Log Message\r\n':
7308 continue
7309 found = True
7310 break
7311 msg = 'Record not found in event log, went back %d records' % GO_BACK
7312 self.assertTrue(found, msg=msg)
7313
7314 @unittest.skipUnless(sys.platform == "win32", "Windows required for this test")
7315 def test_without_pywin32(self):

Callers

nothing calls this directly

Calls 4

closeMethod · 0.95
assertTrueMethod · 0.80
handleMethod · 0.45
assertLessMethod · 0.45

Tested by

no test coverage detected