summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cfgparser.py
diff options
context:
space:
mode:
authorŁukasz Langa <lukasz@langa.pl>2010-12-04 17:48:18 (GMT)
committerŁukasz Langa <lukasz@langa.pl>2010-12-04 17:48:18 (GMT)
commit2f0fd0fa4fd0424cee5718bccc826c2ed7220bb2 (patch)
tree0fd102d48811d19b7efb14e1bee3b2538ebb6bbb /Lib/test/test_cfgparser.py
parent1215915045d620d44e14ba12af8949f8ec700b5d (diff)
downloadcpython-2f0fd0fa4fd0424cee5718bccc826c2ed7220bb2.zip
cpython-2f0fd0fa4fd0424cee5718bccc826c2ed7220bb2.tar.gz
cpython-2f0fd0fa4fd0424cee5718bccc826c2ed7220bb2.tar.bz2
configparser: mapping protocol access get() handles configparser-specific arguments as well
Diffstat (limited to 'Lib/test/test_cfgparser.py')
-rw-r--r--Lib/test/test_cfgparser.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/Lib/test/test_cfgparser.py b/Lib/test/test_cfgparser.py
index 2ea80dc..7b91518 100644
--- a/Lib/test/test_cfgparser.py
+++ b/Lib/test/test_cfgparser.py
@@ -160,6 +160,49 @@ class BasicTestCase(CfgParserTestCaseClass):
'this line is much, much longer than my editor\nlikes it.')
if self.allow_no_value:
eq(cf['NoValue']['option-without-value'], None)
+ # test vars= and fallback=
+ eq(cf['Foo Bar'].get('foo', 'baz'), 'bar1')
+ eq(cf['Foo Bar'].get('foo', fallback='baz'), 'bar1')
+ eq(cf['Foo Bar'].get('foo', vars={'foo': 'baz'}), 'baz')
+ with self.assertRaises(KeyError):
+ cf['No Such Foo Bar']['foo']
+ with self.assertRaises(KeyError):
+ cf['Foo Bar']['no-such-foo']
+ with self.assertRaises(KeyError):
+ cf['No Such Foo Bar'].get('foo', fallback='baz')
+ eq(cf['Foo Bar'].get('no-such-foo', 'baz'), 'baz')
+ eq(cf['Foo Bar'].get('no-such-foo', fallback='baz'), 'baz')
+ eq(cf['Spacey Bar'].get('foo', None), 'bar2')
+ eq(cf['Spacey Bar'].get('foo', fallback=None), 'bar2')
+ with self.assertRaises(KeyError):
+ cf['No Such Spacey Bar'].get('foo', None)
+ eq(cf['Types'].getint('int', 18), 42)
+ eq(cf['Types'].getint('int', fallback=18), 42)
+ eq(cf['Types'].getint('no-such-int', 18), 18)
+ eq(cf['Types'].getint('no-such-int', fallback=18), 18)
+ eq(cf['Types'].getint('no-such-int', "18"), "18") # sic!
+ eq(cf['Types'].getint('no-such-int', fallback="18"), "18") # sic!
+ self.assertAlmostEqual(cf['Types'].getfloat('float', 0.0), 0.44)
+ self.assertAlmostEqual(cf['Types'].getfloat('float',
+ fallback=0.0), 0.44)
+ self.assertAlmostEqual(cf['Types'].getfloat('no-such-float', 0.0), 0.0)
+ self.assertAlmostEqual(cf['Types'].getfloat('no-such-float',
+ fallback=0.0), 0.0)
+ eq(cf['Types'].getfloat('no-such-float', "0.0"), "0.0") # sic!
+ eq(cf['Types'].getfloat('no-such-float', fallback="0.0"), "0.0") # sic!
+ eq(cf['Types'].getboolean('boolean', True), False)
+ eq(cf['Types'].getboolean('boolean', fallback=True), False)
+ eq(cf['Types'].getboolean('no-such-boolean', "yes"), "yes") # sic!
+ eq(cf['Types'].getboolean('no-such-boolean', fallback="yes"),
+ "yes") # sic!
+ eq(cf['Types'].getboolean('no-such-boolean', True), True)
+ eq(cf['Types'].getboolean('no-such-boolean', fallback=True), True)
+ if self.allow_no_value:
+ eq(cf['NoValue'].get('option-without-value', False), None)
+ eq(cf['NoValue'].get('option-without-value', fallback=False), None)
+ eq(cf['NoValue'].get('no-such-option-without-value', False), False)
+ eq(cf['NoValue'].get('no-such-option-without-value',
+ fallback=False), False)
# Make sure the right things happen for remove_option();
# added to include check for SourceForge bug #123324: