def test_absl_prefix_regex(self): self.record.created = 1226888258.0521369 # Use UTC so the test passes regardless of the local time zone. with mock.patch.object(time, 'localtime', side_effect=time.gmtime): prefix = logging.get_absl_log_prefix(self.record) match = re.search(logging.ABSL_LOGGING_PREFIX_REGEX, prefix) self.assertTrue(match) expect = { 'severity': 'I', 'month': '11', 'day': '17', 'hour': '02', 'minute': '17', 'second': '38', 'microsecond': '052136', 'thread_id': str(logging._get_thread_id()), 'filename': 'source.py', 'line': '13', } actual = {name: match.group(name) for name in expect} self.assertEqual(expect, actual)
def test_get_thread_id(self, mock_get_ident): mock_get_ident.return_value = 12345 self.assertEqual(12345, logging._get_thread_id())