mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
[3.13] gh-130941: Fix configparser
parsing values with allow_no_value
and interpolation
set (GH-130949) (#132588)
gh-130941: Fix `configparser` parsing values with `allow_no_value` and `interpolation` set (GH-130949)
(cherry picked from commit c35c7353eb
)
Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
parent
8128bcfa08
commit
ee8f681252
3 changed files with 45 additions and 0 deletions
|
@ -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 = {'='}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue