diff options
author | sobolevn <mail@sobolevn.me> | 2025-04-16 10:39:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-16 10:39:11 (GMT) |
commit | c35c7353eb8fbccff2d3a6ab664426b31af00d4d (patch) | |
tree | a67b38505aff674505ec4d32affc3a87a913594e /Lib/test/test_configparser.py | |
parent | 8b7cb947c5046d8fb32aad532048de87e09ed3f9 (diff) | |
download | cpython-c35c7353eb8fbccff2d3a6ab664426b31af00d4d.zip cpython-c35c7353eb8fbccff2d3a6ab664426b31af00d4d.tar.gz cpython-c35c7353eb8fbccff2d3a6ab664426b31af00d4d.tar.bz2 |
gh-130941: Fix `configparser` parsing values with `allow_no_value` and `interpolation` set (GH-130949)
Diffstat (limited to 'Lib/test/test_configparser.py')
-rw-r--r-- | Lib/test/test_configparser.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py index 1313ec2..23904d1 100644 --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -1328,6 +1328,47 @@ class ConfigParserTestCaseNoValue(ConfigParserTestCase): allow_no_value = True +class NoValueAndExtendedInterpolation(CfgParserTestCaseClass): + interpolation = configparser.ExtendedInterpolation() + allow_no_value = True + + def test_interpolation_with_allow_no_value(self): + config = textwrap.dedent(""" + [dummy] + a + b = ${a} + """) + cf = self.fromstring(config) + + self.assertIs(cf["dummy"]["a"], None) + self.assertEqual(cf["dummy"]["b"], "") + + def test_explicit_none(self): + config = textwrap.dedent(""" + [dummy] + a = None + b = ${a} + """) + cf = self.fromstring(config) + + self.assertEqual(cf["dummy"]["a"], "None") + self.assertEqual(cf["dummy"]["b"], "None") + + +class ConfigParserNoValueAndExtendedInterpolationTest( + NoValueAndExtendedInterpolation, + unittest.TestCase, +): + config_class = configparser.ConfigParser + + +class RawConfigParserNoValueAndExtendedInterpolationTest( + NoValueAndExtendedInterpolation, + unittest.TestCase, +): + config_class = configparser.RawConfigParser + + class ConfigParserTestCaseTrickyFile(CfgParserTestCaseClass, unittest.TestCase): config_class = configparser.ConfigParser delimiters = {'='} |