diff options
author | ?ukasz Langa <lukasz@langa.pl> | 2016-11-26 14:00:39 -0800 |
---|---|---|
committer | ?ukasz Langa <lukasz@langa.pl> | 2016-11-26 14:00:39 -0800 |
commit | a8ec74e46a87e2351144ae73c941a623938ae21f (patch) | |
tree | dde29fd73a315747bdd28e98c83f5efaa9a4fda0 /Lib/test/test_configparser.py | |
parent | fbba40fe8e290707d35b8c99d4e84cc42b7df7a0 (diff) | |
download | cpython-a8ec74e46a87e2351144ae73c941a623938ae21f.tar.gz |
Fixes #24142: [configparser] always join multiline values to not leave the parser in an invalid state
Diffstat (limited to 'Lib/test/test_configparser.py')
-rw-r--r-- | Lib/test/test_configparser.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py index 71a8f3f8d9..864a1d0802 100644 --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -9,6 +9,7 @@ import warnings from test import support + class SortedDict(collections.UserDict): def items(self): @@ -64,6 +65,7 @@ class CfgParserTestCaseClass: cf.read_string(string) return cf + class BasicTestCase(CfgParserTestCaseClass): def basic_test(self, cf): @@ -828,6 +830,21 @@ boolean {0[0]} NO self.assertEqual(set(cf['section3'].keys()), set()) self.assertEqual(cf.sections(), ['section1', 'section2', 'section3']) + def test_invalid_multiline_value(self): + if self.allow_no_value: + self.skipTest('if no_value is allowed, ParsingError is not raised') + + invalid = textwrap.dedent("""\ + [DEFAULT] + test {0} test + invalid""".format(self.delimiters[0]) + ) + cf = self.newconfig() + with self.assertRaises(configparser.ParsingError): + cf.read_string(invalid) + self.assertEqual(cf.get('DEFAULT', 'test'), 'test') + self.assertEqual(cf['DEFAULT']['test'], 'test') + class StrictTestCase(BasicTestCase, unittest.TestCase): config_class = configparser.RawConfigParser @@ -981,14 +998,17 @@ class ConfigParserTestCaseLegacyInterpolation(ConfigParserTestCase): cf.set("sect", "option2", "foo%%bar") self.assertEqual(cf.get("sect", "option2"), "foo%%bar") + class ConfigParserTestCaseNonStandardDelimiters(ConfigParserTestCase): delimiters = (':=', '$') comment_prefixes = ('//', '"') inline_comment_prefixes = ('//', '"') + class ConfigParserTestCaseNonStandardDefaultSection(ConfigParserTestCase): default_section = 'general' + class MultilineValuesTestCase(BasicTestCase, unittest.TestCase): config_class = configparser.ConfigParser wonderful_spam = ("I'm having spam spam spam spam " @@ -1017,6 +1037,7 @@ class MultilineValuesTestCase(BasicTestCase, unittest.TestCase): self.assertEqual(cf_from_file.get('section8', 'lovely_spam4'), self.wonderful_spam.replace('\t\n', '\n')) + class RawConfigParserTestCase(BasicTestCase, unittest.TestCase): config_class = configparser.RawConfigParser @@ -1059,11 +1080,13 @@ class RawConfigParserTestCase(BasicTestCase, unittest.TestCase): cf.set('non-string', 1, 1) self.assertEqual(cf.get('non-string', 1), 1) + class RawConfigParserTestCaseNonStandardDelimiters(RawConfigParserTestCase): delimiters = (':=', '$') comment_prefixes = ('//', '"') inline_comment_prefixes = ('//', '"') + class RawConfigParserTestSambaConf(CfgParserTestCaseClass, unittest.TestCase): config_class = configparser.RawConfigParser comment_prefixes = ('#', ';', '----') @@ -1258,6 +1281,7 @@ class ConfigParserTestCaseExtendedInterpolation(BasicTestCase, unittest.TestCase class ConfigParserTestCaseNoValue(ConfigParserTestCase): allow_no_value = True + class ConfigParserTestCaseTrickyFile(CfgParserTestCaseClass, unittest.TestCase): config_class = configparser.ConfigParser delimiters = {'='} |