|
9 | 9 |
|
10 | 10 | from test import support
|
11 | 11 |
|
| 12 | + |
12 | 13 | class SortedDict(collections.UserDict):
|
13 | 14 |
|
14 | 15 | def items(self):
|
@@ -64,6 +65,7 @@ def fromstring(self, string, defaults=None):
|
64 | 65 | cf.read_string(string)
|
65 | 66 | return cf
|
66 | 67 |
|
| 68 | + |
67 | 69 | class BasicTestCase(CfgParserTestCaseClass):
|
68 | 70 |
|
69 | 71 | def basic_test(self, cf):
|
@@ -828,6 +830,21 @@ def test_setitem(self):
|
828 | 830 | self.assertEqual(set(cf['section3'].keys()), set())
|
829 | 831 | self.assertEqual(cf.sections(), ['section1', 'section2', 'section3'])
|
830 | 832 |
|
| 833 | + def test_invalid_multiline_value(self): |
| 834 | + if self.allow_no_value: |
| 835 | + self.skipTest('if no_value is allowed, ParsingError is not raised') |
| 836 | + |
| 837 | + invalid = textwrap.dedent("""\ |
| 838 | + [DEFAULT] |
| 839 | + test {0} test |
| 840 | + invalid""".format(self.delimiters[0]) |
| 841 | + ) |
| 842 | + cf = self.newconfig() |
| 843 | + with self.assertRaises(configparser.ParsingError): |
| 844 | + cf.read_string(invalid) |
| 845 | + self.assertEqual(cf.get('DEFAULT', 'test'), 'test') |
| 846 | + self.assertEqual(cf['DEFAULT']['test'], 'test') |
| 847 | + |
831 | 848 |
|
832 | 849 | class StrictTestCase(BasicTestCase, unittest.TestCase):
|
833 | 850 | config_class = configparser.RawConfigParser
|
@@ -981,14 +998,17 @@ def test_set_malformatted_interpolation(self):
|
981 | 998 | cf.set("sect", "option2", "foo%%bar")
|
982 | 999 | self.assertEqual(cf.get("sect", "option2"), "foo%%bar")
|
983 | 1000 |
|
| 1001 | + |
984 | 1002 | class ConfigParserTestCaseNonStandardDelimiters(ConfigParserTestCase):
|
985 | 1003 | delimiters = (':=', '$')
|
986 | 1004 | comment_prefixes = ('//', '"')
|
987 | 1005 | inline_comment_prefixes = ('//', '"')
|
988 | 1006 |
|
| 1007 | + |
989 | 1008 | class ConfigParserTestCaseNonStandardDefaultSection(ConfigParserTestCase):
|
990 | 1009 | default_section = 'general'
|
991 | 1010 |
|
| 1011 | + |
992 | 1012 | class MultilineValuesTestCase(BasicTestCase, unittest.TestCase):
|
993 | 1013 | config_class = configparser.ConfigParser
|
994 | 1014 | wonderful_spam = ("I'm having spam spam spam spam "
|
@@ -1017,6 +1037,7 @@ def test_dominating_multiline_values(self):
|
1017 | 1037 | self.assertEqual(cf_from_file.get('section8', 'lovely_spam4'),
|
1018 | 1038 | self.wonderful_spam.replace('\t\n', '\n'))
|
1019 | 1039 |
|
| 1040 | + |
1020 | 1041 | class RawConfigParserTestCase(BasicTestCase, unittest.TestCase):
|
1021 | 1042 | config_class = configparser.RawConfigParser
|
1022 | 1043 |
|
@@ -1059,11 +1080,13 @@ def test_set_nonstring_types(self):
|
1059 | 1080 | cf.set('non-string', 1, 1)
|
1060 | 1081 | self.assertEqual(cf.get('non-string', 1), 1)
|
1061 | 1082 |
|
| 1083 | + |
1062 | 1084 | class RawConfigParserTestCaseNonStandardDelimiters(RawConfigParserTestCase):
|
1063 | 1085 | delimiters = (':=', '$')
|
1064 | 1086 | comment_prefixes = ('//', '"')
|
1065 | 1087 | inline_comment_prefixes = ('//', '"')
|
1066 | 1088 |
|
| 1089 | + |
1067 | 1090 | class RawConfigParserTestSambaConf(CfgParserTestCaseClass, unittest.TestCase):
|
1068 | 1091 | config_class = configparser.RawConfigParser
|
1069 | 1092 | comment_prefixes = ('#', ';', '----')
|
@@ -1258,6 +1281,7 @@ def test_other_errors(self):
|
1258 | 1281 | class ConfigParserTestCaseNoValue(ConfigParserTestCase):
|
1259 | 1282 | allow_no_value = True
|
1260 | 1283 |
|
| 1284 | + |
1261 | 1285 | class ConfigParserTestCaseTrickyFile(CfgParserTestCaseClass, unittest.TestCase):
|
1262 | 1286 | config_class = configparser.ConfigParser
|
1263 | 1287 | delimiters = {'='}
|
|
0 commit comments