@@ -980,6 +980,28 @@ def test_set_nonstring_types(self):
980980 self .assertRaises (TypeError , cf .set , "sect" , 123 , "invalid opt name!" )
981981 self .assertRaises (TypeError , cf .add_section , 123 )
982982
983+ def test_str_and_repr (self ):
984+ self .maxDiff = None
985+ cf = self .config_class (allow_no_value = True , delimiters = ('=' ,), strict = True )
986+
987+ cf .add_section ("sect" )
988+ cf .set ("sect" , "option1" , "foo" )
989+ cf .set ("sect" , "option2" , "bar" )
990+
991+ expected_str = "{'sect': {'option1': 'foo', 'option2': 'bar'}}"
992+ self .assertEqual (str (cf ), expected_str )
993+
994+ dict_type = type (cf ._dict ).__name__
995+
996+ expected_repr = (
997+ f"<{ cf .__class__ .__name__ } ("
998+ f"params={{'dict_type': '{ dict_type } ', 'allow_no_value': True, "
999+ "'delimiters': ('=',), 'strict': True, 'default_section': 'DEFAULT', "
1000+ "'interpolation': 'BasicInterpolation'}, "
1001+ "state={'loaded_files': [], 'sections': 1})>"
1002+ )
1003+ self .assertEqual (repr (cf ), expected_repr )
1004+
9831005 def test_add_section_default (self ):
9841006 cf = self .newconfig ()
9851007 self .assertRaises (ValueError , cf .add_section , self .default_section )
@@ -1153,6 +1175,8 @@ def test_reading(self):
11531175 self .assertEqual (cf .get ("global" , "hosts allow" ), "127." )
11541176 self .assertEqual (cf .get ("tmp" , "echo command" ), "cat %s; rm %s" )
11551177
1178+
1179+
11561180class ConfigParserTestCaseExtendedInterpolation (BasicTestCase , unittest .TestCase ):
11571181 config_class = configparser .ConfigParser
11581182 interpolation = configparser .ExtendedInterpolation ()
@@ -1300,6 +1324,8 @@ def test_case_sensitivity_conflicts(self):
13001324 eq (cf ['random' ]['foo' ], 'value redefined' )
13011325 eq (cf ['random' ]['Foo' ], 'A Better Value Redefined' )
13021326
1327+
1328+
13031329 def test_other_errors (self ):
13041330 cf = self .fromstring ("""
13051331 [interpolation fail]
0 commit comments