[Python-checkins] CVS: python/dist/src/Lib/test test_cfgparser.py,1.4,1.5
Fred L. Drake
fdrake@users.sourceforge.net
Mon, 12 Feb 2001 09:23:22 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv25125/test
Modified Files:
test_cfgparser.py
Log Message:
Added options that use square brackets in their names; this ensures that
GNOME-style internationalized options can be parsed using ConfigParser
(SF bug #131635).
Converted the tests to use test_support.verify() instead of output
comparison to work.
Index: test_cfgparser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_cfgparser.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** test_cfgparser.py 2000/12/04 16:30:40 1.4
--- test_cfgparser.py 2001/02/12 17:23:20 1.5
***************
*** 2,10 ****
import StringIO
! from test_support import TestFailed
def basic(src):
- print
print "Testing basic accessors..."
cf = ConfigParser.ConfigParser()
--- 2,9 ----
import StringIO
! from test_support import TestFailed, verify
def basic(src):
print "Testing basic accessors..."
cf = ConfigParser.ConfigParser()
***************
*** 13,43 ****
L = cf.sections()
L.sort()
! print L
! for s in L:
! print "%s: %s" % (s, cf.options(s))
# The use of spaces in the section names serves as a regression test for
# SourceForge bug #115357.
# http://sourceforge.net/bugs/?func=detailbug&group_id=5470&bug_id=115357
! print `cf.get('Foo Bar', 'foo', raw=1)`
! print `cf.get('Spacey Bar', 'foo', raw=1)`
! print `cf.get('Commented Bar', 'foo', raw=1)`
! if '__name__' in cf.options("Foo Bar"):
! print '__name__ "option" should not be exposed by the API!'
! else:
! print '__name__ "option" properly hidden by the API.'
# Make sure the right things happen for remove_option();
# added to include check for SourceForge bug #123324:
! if not cf.remove_option('Foo Bar', 'foo'):
! raise TestFailed(
! "remove_option() failed to report existance of option")
! if cf.has_option('Foo Bar', 'foo'):
! raise TestFailed("remove_option() failed to remove option")
! if cf.remove_option('Foo Bar', 'foo'):
! raise TestFailed(
! "remove_option() failed to report non-existance of option"
! " that was removed")
try:
cf.remove_option('No Such Section', 'foo')
--- 12,38 ----
L = cf.sections()
L.sort()
! verify(L == ['Commented Bar', 'Foo Bar',
! 'Internationalized Stuff', 'Spacey Bar'],
! "unexpected list of section names")
# The use of spaces in the section names serves as a regression test for
# SourceForge bug #115357.
# http://sourceforge.net/bugs/?func=detailbug&group_id=5470&bug_id=115357
! verify(cf.get('Foo Bar', 'foo', raw=1) == 'bar')
! verify(cf.get('Spacey Bar', 'foo', raw=1) == 'bar')
! verify(cf.get('Commented Bar', 'foo', raw=1) == 'bar')
! verify('__name__' not in cf.options("Foo Bar"),
! '__name__ "option" should not be exposed by the API!')
# Make sure the right things happen for remove_option();
# added to include check for SourceForge bug #123324:
! verify(cf.remove_option('Foo Bar', 'foo'),
! "remove_option() failed to report existance of option")
! verify(not cf.has_option('Foo Bar', 'foo'),
! "remove_option() failed to remove option")
! verify(not cf.remove_option('Foo Bar', 'foo'),
! "remove_option() failed to report non-existance of option"
! " that was removed")
try:
cf.remove_option('No Such Section', 'foo')
***************
*** 51,68 ****
def interpolation(src):
- print
print "Testing value interpolation..."
cf = ConfigParser.ConfigParser({"getname": "%(__name__)s"})
sio = StringIO.StringIO(src)
cf.readfp(sio)
! print `cf.get("Foo", "getname")`
! print `cf.get("Foo", "bar")`
! print `cf.get("Foo", "bar9")`
! print `cf.get("Foo", "bar10")`
expect_get_error(cf, ConfigParser.InterpolationDepthError, "Foo", "bar11")
def parse_errors():
! print
! print "Testing for parsing errors..."
expect_parse_error(ConfigParser.ParsingError,
"""[Foo]\n extra-spaces: splat\n""")
--- 46,64 ----
def interpolation(src):
print "Testing value interpolation..."
cf = ConfigParser.ConfigParser({"getname": "%(__name__)s"})
sio = StringIO.StringIO(src)
cf.readfp(sio)
! verify(cf.get("Foo", "getname") == "Foo")
! verify(cf.get("Foo", "bar") == "something with interpolation (1 step)")
! verify(cf.get("Foo", "bar9")
! == "something with lots of interpolation (9 steps)")
! verify(cf.get("Foo", "bar10")
! == "something with lots of interpolation (10 steps)")
expect_get_error(cf, ConfigParser.InterpolationDepthError, "Foo", "bar11")
+
def parse_errors():
! print "Testing parse errors..."
expect_parse_error(ConfigParser.ParsingError,
"""[Foo]\n extra-spaces: splat\n""")
***************
*** 78,105 ****
"""No Section!\n""")
def query_errors():
- print
print "Testing query interface..."
cf = ConfigParser.ConfigParser()
! print cf.sections()
! print "Has section 'Foo'?", cf.has_section("Foo")
try:
cf.options("Foo")
except ConfigParser.NoSectionError, e:
! print "Caught expected NoSectionError:", e
else:
! print "Failed to catch expected NoSectionError from options()"
try:
cf.set("foo", "bar", "value")
except ConfigParser.NoSectionError, e:
! print "Caught expected NoSectionError:", e
else:
! print "Failed to catch expected NoSectionError from set()"
expect_get_error(cf, ConfigParser.NoSectionError, "foo", "bar")
cf.add_section("foo")
expect_get_error(cf, ConfigParser.NoOptionError, "foo", "bar")
def weird_errors():
- print
print "Testing miscellaneous error conditions..."
cf = ConfigParser.ConfigParser()
--- 74,104 ----
"""No Section!\n""")
+
def query_errors():
print "Testing query interface..."
cf = ConfigParser.ConfigParser()
! verify(cf.sections() == [],
! "new ConfigParser should have no defined sections")
! verify(not cf.has_section("Foo"),
! "new ConfigParser should have no acknowledged sections")
try:
cf.options("Foo")
except ConfigParser.NoSectionError, e:
! pass
else:
! raise TestFailed(
! "Failed to catch expected NoSectionError from options()")
try:
cf.set("foo", "bar", "value")
except ConfigParser.NoSectionError, e:
! pass
else:
! raise TestFailed("Failed to catch expected NoSectionError from set()")
expect_get_error(cf, ConfigParser.NoSectionError, "foo", "bar")
cf.add_section("foo")
expect_get_error(cf, ConfigParser.NoOptionError, "foo", "bar")
+
def weird_errors():
print "Testing miscellaneous error conditions..."
cf = ConfigParser.ConfigParser()
***************
*** 108,114 ****
cf.add_section("Foo")
except ConfigParser.DuplicateSectionError, e:
! print "Caught expected DuplicateSectionError:", e
else:
! print "Failed to catch expected DuplicateSectionError"
def expect_get_error(cf, exctype, section, option, raw=0):
--- 107,114 ----
cf.add_section("Foo")
except ConfigParser.DuplicateSectionError, e:
! pass
else:
! raise TestFailed("Failed to catch expected DuplicateSectionError")
!
def expect_get_error(cf, exctype, section, option, raw=0):
***************
*** 116,123 ****
cf.get(section, option, raw=raw)
except exctype, e:
! print "Caught expected", exctype.__name__, ":"
! print e
else:
! print "Failed to catch expected", exctype.__name__
def expect_parse_error(exctype, src):
--- 116,123 ----
cf.get(section, option, raw=raw)
except exctype, e:
! pass
else:
! raise TestFailed("Failed to catch expected " + exctype.__name__)
!
def expect_parse_error(exctype, src):
***************
*** 127,133 ****
cf.readfp(sio)
except exctype, e:
! print "Caught expected exception:", e
else:
! print "Failed to catch expected", exctype.__name__
basic(r"""
--- 127,134 ----
cf.readfp(sio)
except exctype, e:
! pass
else:
! raise TestFailed("Failed to catch expected " + exctype.__name__)
!
basic(r"""
***************
*** 138,141 ****
--- 139,147 ----
[Commented Bar]
foo: bar ; comment
+ [Internationalized Stuff]
+ foo[bg]: Bulgarian
+ foo=Default
+ foo[en]=English
+ foo[de]=Deutsch
""")
interpolation(r"""