from test import support
+
class SortedDict(collections.UserDict):
def items(self):
cf.read_string(string)
return cf
+
class BasicTestCase(CfgParserTestCaseClass):
def basic_test(self, cf):
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
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 "
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
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 = ('#', ';', '----')
class ConfigParserTestCaseNoValue(ConfigParserTestCase):
allow_no_value = True
+
class ConfigParserTestCaseTrickyFile(CfgParserTestCaseClass, unittest.TestCase):
config_class = configparser.ConfigParser
delimiters = {'='}