Skip to content

Commit 0ed179a

Browse files
committed
Add test
1 parent e60ffe4 commit 0ed179a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Lib/test/test_configparser.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,7 @@ class RawConfigParserTestCase(BasicTestCase, unittest.TestCase):
10801080
config_class = configparser.RawConfigParser
10811081

10821082
def test_interpolation(self):
1083+
10831084
cf = self.get_interpolation_config()
10841085
eq = self.assertEqual
10851086
eq(cf.get("Foo", "bar"),
@@ -1126,6 +1127,34 @@ def test_defaults_keyword(self):
11261127
cf = self.newconfig(defaults={"A": 5.2})
11271128
self.assertAlmostEqual(cf[self.default_section]['a'], 5.2)
11281129

1130+
def test_repr_and_str_representation(self):
1131+
"""Test repr and str representation of RawConfigParser."""
1132+
config_string = """\
1133+
[Section1]
1134+
key1 = value1
1135+
key2 = value2
1136+
1137+
[Section2]
1138+
keyA = valueA
1139+
keyB = valueB
1140+
"""
1141+
cf = self.newconfig()
1142+
cf.read_string(config_string) # Use a left-aligned string to avoid ParsingError
1143+
cf.optionxform = str # Preserve key casing
1144+
1145+
# Test `repr` representation
1146+
expected_repr = (
1147+
"ConfigParser(default_section='DEFAULT', "
1148+
"interpolation=None)"
1149+
)
1150+
self.assertEqual(repr(cf), expected_repr)
1151+
1152+
# Test `str` representation
1153+
expected_str = (
1154+
"{'Section1': {'key1': 'value1', 'key2': 'value2'}, "
1155+
"'Section2': {'keyA': 'valueA', 'keyB': 'valueB'}}"
1156+
)
1157+
self.assertEqual(str(cf), expected_str)
11291158

11301159
class RawConfigParserTestCaseNonStandardDelimiters(RawConfigParserTestCase):
11311160
delimiters = (':=', '$')

0 commit comments

Comments
 (0)