diff options
author | Ćukasz Langa <lukasz@langa.pl> | 2017-08-24 16:43:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-24 16:43:53 (GMT) |
commit | a5fab17fc11433b2418f626dc51e8a3d07b198ca (patch) | |
tree | 173aeb5a7491a9bd0956fcbc2d5f8818a7f6fb41 /Lib/test/test_configparser.py | |
parent | a6296d34a478b4f697ea9db798146195075d496c (diff) | |
download | cpython-a5fab17fc11433b2418f626dc51e8a3d07b198ca.zip cpython-a5fab17fc11433b2418f626dc51e8a3d07b198ca.tar.gz cpython-a5fab17fc11433b2418f626dc51e8a3d07b198ca.tar.bz2 |
bpo-23835: Restore legacy defaults= behavior for RawConfigParser (#3191)
The fix for bpo-23835 fixed ConfigParser behavior in defaults= handling.
Unfortunately, it caused a backwards compatibility regression with
RawConfigParser objects which allow for non-string values.
This commit restores the legacy behavior for RawConfigParser only.
Diffstat (limited to 'Lib/test/test_configparser.py')
-rw-r--r-- | Lib/test/test_configparser.py | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py index be22fa4..d8969ef 100644 --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -855,15 +855,6 @@ boolean {0[0]} NO self.assertEqual(cf.get('DEFAULT', 'test'), 'test') self.assertEqual(cf['DEFAULT']['test'], 'test') - def test_defaults_keyword(self): - # test that bpo-23835 is fixed - cf = self.newconfig(defaults={1: 2.4}) - self.assertEqual(cf[self.default_section]['1'], '2.4') - self.assertAlmostEqual(cf[self.default_section].getfloat('1'), 2.4) - cf = self.newconfig(defaults={"A": 5.2}) - self.assertEqual(cf[self.default_section]['a'], '5.2') - self.assertAlmostEqual(cf[self.default_section].getfloat('a'), 5.2) - class StrictTestCase(BasicTestCase, unittest.TestCase): config_class = configparser.RawConfigParser @@ -959,6 +950,15 @@ class ConfigParserTestCase(BasicTestCase, unittest.TestCase): cf = self.newconfig() self.assertRaises(ValueError, cf.add_section, self.default_section) + def test_defaults_keyword(self): + """bpo-23835 fix for ConfigParser""" + cf = self.newconfig(defaults={1: 2.4}) + self.assertEqual(cf[self.default_section]['1'], '2.4') + self.assertAlmostEqual(cf[self.default_section].getfloat('1'), 2.4) + cf = self.newconfig(defaults={"A": 5.2}) + self.assertEqual(cf[self.default_section]['a'], '5.2') + self.assertAlmostEqual(cf[self.default_section].getfloat('a'), 5.2) + class ConfigParserTestCaseNoInterpolation(BasicTestCase, unittest.TestCase): config_class = configparser.ConfigParser @@ -1099,6 +1099,15 @@ class RawConfigParserTestCase(BasicTestCase, unittest.TestCase): cf.set('non-string', 1, 1) self.assertEqual(cf.get('non-string', 1), 1) + def test_defaults_keyword(self): + """bpo-23835 legacy behavior for RawConfigParser""" + with self.assertRaises(AttributeError) as ctx: + self.newconfig(defaults={1: 2.4}) + err = ctx.exception + self.assertEqual(str(err), "'int' object has no attribute 'lower'") + cf = self.newconfig(defaults={"A": 5.2}) + self.assertAlmostEqual(cf[self.default_section]['a'], 5.2) + class RawConfigParserTestCaseNonStandardDelimiters(RawConfigParserTestCase): delimiters = (':=', '$') |