242
242
co = config.ConfigObj()
243
243
co['test'] = 'foo#bar'
245
co.write(outfile=outfile)
246
lines = outfile.getvalue().splitlines()
245
247
self.assertEqual(lines, ['test = "foo#bar"'])
246
248
co2 = config.ConfigObj(lines)
247
249
self.assertEqual(co2['test'], 'foo#bar')
251
def test_triple_quotes(self):
252
# Bug #710410: if the value string has triple quotes
253
# then ConfigObj versions up to 4.7.2 will quote them wrong
254
# and won't able to read them back
255
triple_quotes_value = '''spam
256
""" that's my spam """
258
co = config.ConfigObj()
259
co['test'] = triple_quotes_value
260
# While writing this test another bug in ConfigObj has been found:
261
# method co.write() without arguments produces list of lines
262
# one option per line, and multiline values are not split
263
# across multiple lines,
264
# and that breaks the parsing these lines back by ConfigObj.
265
# This issue only affects test, but it's better to avoid
266
# `co.write()` construct at all.
267
# [bialix 20110222] bug report sent to ConfigObj's author
269
co.write(outfile=outfile)
270
output = outfile.getvalue()
271
# now we're trying to read it back
272
co2 = config.ConfigObj(StringIO(output))
273
self.assertEquals(triple_quotes_value, co2['test'])
250
276
erroneous_config = """[section] # line 1
251
277
good=good # line 2