[Python-checkins] python/dist/src/Lib/test test_cfgparser.py,1.19,1.20
esr@users.sourceforge.net
esr@users.sourceforge.net
2002年12月31日 07:26:30 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv9977/Lib/test
Modified Files:
test_cfgparser.py
Log Message:
Fixed a bug in writing of continuations that broke the reversibilty of
the write() operation by readfp(). Sections and options are now
guaranteed to be written out in the order they were read in. The
write method is now factored so that a _str_ method is supported.
Added optional capability to handle array values and multiline string
literals. Updated unit test and documentation appropriately.
Index: test_cfgparser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_cfgparser.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** test_cfgparser.py 31 Dec 2002 06:57:25 -0000 1.19
--- test_cfgparser.py 31 Dec 2002 15:26:27 -0000 1.20
***************
*** 14,24 ****
return self.cf
! def fromstring(self, string, defaults=None):
cf = self.newconfig(defaults)
sio = StringIO.StringIO(string)
cf.readfp(sio)
return cf
! def test_basic(self):
cf = self.fromstring(
"[Foo Bar]\n"
--- 14,27 ----
return self.cf
! def fromstring(self, string, defaults=None, enable_extended=0):
cf = self.newconfig(defaults)
sio = StringIO.StringIO(string)
+ if enable_extended:
+ cf.listbrackets = '{}'
+ cf.stringquotes = '\'"'
cf.readfp(sio)
return cf
! def basictest(self, enable_extended=0):
cf = self.fromstring(
"[Foo Bar]\n"
***************
*** 39,44 ****
"[Spaces]\n"
"key with spaces : value\n"
! "another with spaces = splat!\n"
! )
L = cf.sections()
L.sort()
--- 42,47 ----
"[Spaces]\n"
"key with spaces : value\n"
! "another with spaces = splat!\n",
! enable_extended=enable_extended)
L = cf.sections()
L.sort()
***************
*** 80,83 ****
--- 83,136 ----
eq(cf.get('Long Line', 'foo'),
'this line is much, much longer than my editor\nlikes it.')
+
+ def test_basic(self):
+ self.basictest(enable_extended=0)
+
+ def test_basic_with_syntax_extensions(self):
+ self.basictest(enable_extended=1)
+
+ def test_extended(self):
+ cf = self.fromstring(
+ "[DEFAULT]\n"
+ "dfltparam = 17\n"
+ "\n"
+ "[section1]\n"
+ "intparam = 23\n"
+ "floatparam = 3.14\n"
+ "stringparam1 = 'A string containing spaces'\n"
+ "arrayparam1 = {36, 24, 36}\n"
+ "stringparam2 = This string no quotes\n"
+ "multilineparam = '\n"
+ " A sample\n"
+ " multiline string\n"
+ "'\n"
+ "stringparam3 = foo\n"
+ "arrayparam2 = { 'a',\n"
+ " 'b', ; Comment -- to be ignored\n"
+ " 45,\n"
+ "}\n",
+ enable_extended=1)
+ eq = self.assertEqual
+ eq(cf.sections(), ["section1"])
+ opts = cf.options("section1")
+ opts.sort()
+ eq(opts, ["arrayparam1",
+ "arrayparam2",
+ "dfltparam",
+ "floatparam",
+ "intparam",
+ "multilineparam",
+ "stringparam1",
+ "stringparam2",
+ "stringparam3"])
+ eq(cf.getint("section1", "dfltparam"), 17)
+ eq(cf.getint("section1", "intparam"), 23)
+ eq(cf.getfloat("section1", "floatparam"), 3.14)
+ eq(cf.getstring("section1", "stringparam1"), 'A string containing spaces')
+ eq(cf.get("section1", "arrayparam1"), ["36", "24", "36"])
+ eq(cf.get("section1", "stringparam2"), 'This string no quotes')
+ eq(cf.get("section1", "multilineparam"), "'\n A sample\n multiline string\n'")
+ eq(cf.get("section1", "stringparam3"), 'foo')
+ eq(cf.get("section1", "arrayparam2"), ["'a'", "'b'", "45"])
def test_case_sensitivity(self):