diff options
author | Bar Harel <bzvi7919@gmail.com> | 2020-06-18 14:18:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-18 14:18:58 (GMT) |
commit | 8f192d12af82c4dc40730bf59814f6a68f68f950 (patch) | |
tree | a7666641789d3aca6f2323b7fc6f0d642eac250b /Lib/test/test_logging.py | |
parent | ddbeb2f3e02a510c5784ffd74c5e09e8c70b5881 (diff) | |
download | cpython-8f192d12af82c4dc40730bf59814f6a68f68f950.zip cpython-8f192d12af82c4dc40730bf59814f6a68f68f950.tar.gz cpython-8f192d12af82c4dc40730bf59814f6a68f68f950.tar.bz2 |
bpo-40884: Added defaults parameter for logging.Formatter (GH-20668)
Docs and tests are underway.
Automerge-Triggered-By: @vsajip
Diffstat (limited to 'Lib/test/test_logging.py')
-rw-r--r-- | Lib/test/test_logging.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index e719d26..2ae00b6 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3710,6 +3710,9 @@ class FormatterTest(unittest.TestCase): 'args': (2, 'placeholders'), } self.variants = { + 'custom': { + 'custom': 1234 + } } def get_record(self, name=None): @@ -3926,6 +3929,26 @@ class FormatterTest(unittest.TestCase): ) self.assertRaises(ValueError, logging.Formatter, '${asctime', style='$') + def test_defaults_parameter(self): + fmts = ['%(custom)s %(message)s', '{custom} {message}', '$custom $message'] + styles = ['%', '{', '$'] + for fmt, style in zip(fmts, styles): + f = logging.Formatter(fmt, style=style, defaults={'custom': 'Default'}) + r = self.get_record() + self.assertEqual(f.format(r), 'Default Message with 2 placeholders') + r = self.get_record("custom") + self.assertEqual(f.format(r), '1234 Message with 2 placeholders') + + # Without default + f = logging.Formatter(fmt, style=style) + r = self.get_record() + self.assertRaises(ValueError, f.format, r) + + # Non-existing default is ignored + f = logging.Formatter(fmt, style=style, defaults={'Non-existing': 'Default'}) + r = self.get_record("custom") + self.assertEqual(f.format(r), '1234 Message with 2 placeholders') + def test_invalid_style(self): self.assertRaises(ValueError, logging.Formatter, None, None, 'x') |