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

Method test_defaults_parameter

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

Source from the content-addressed store, hash-verified

4801 self.assertRaises(ValueError, logging.Formatter, '${asctime', style='$')
4802
4803 def test_defaults_parameter(self):
4804 fmts = ['%(custom)s %(message)s', '{custom} {message}', '$custom $message']
4805 styles = ['%', '{', '$']
4806 for fmt, style in zip(fmts, styles):
4807 f = logging.Formatter(fmt, style=style, defaults={'custom': 'Default'})
4808 r = self.get_record()
4809 self.assertEqual(f.format(r), 'Default Message with 2 placeholders')
4810 r = self.get_record("custom")
4811 self.assertEqual(f.format(r), '1234 Message with 2 placeholders')
4812
4813 # Without default
4814 f = logging.Formatter(fmt, style=style)
4815 r = self.get_record()
4816 self.assertRaises(ValueError, f.format, r)
4817
4818 # Non-existing default is ignored
4819 f = logging.Formatter(fmt, style=style, defaults={'Non-existing': 'Default'})
4820 r = self.get_record("custom")
4821 self.assertEqual(f.format(r), '1234 Message with 2 placeholders')
4822
4823 def test_invalid_style(self):
4824 self.assertRaises(ValueError, logging.Formatter, None, None, 'x')

Callers

nothing calls this directly

Calls 4

get_recordMethod · 0.95
formatMethod · 0.95
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected