本文整理汇总了Python中configparser.InterpolationMissingOptionError方法的典型用法代码示例。如果您正苦于以下问题:Python configparser.InterpolationMissingOptionError方法的具体用法?Python configparser.InterpolationMissingOptionError怎么用?Python configparser.InterpolationMissingOptionError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类configparser
的用法示例。
在下文中一共展示了configparser.InterpolationMissingOptionError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_strange_options
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import InterpolationMissingOptionError [as 别名]
def test_strange_options(self):
cf = self.fromstring("""
[dollars]
$var = $$value
$var2 = ${$var}
${sick} = cannot interpolate me
[interpolated]
$other = ${dollars:$var}
$trying = ${dollars:${sick}}
""")
self.assertEqual(cf['dollars']['$var'], '$value')
self.assertEqual(cf['interpolated']['$other'], '$value')
self.assertEqual(cf['dollars']['${sick}'], 'cannot interpolate me')
exception_class = configparser.InterpolationMissingOptionError
with self.assertRaises(exception_class) as cm:
cf['interpolated']['$trying']
self.assertEqual(cm.exception.reference, 'dollars:${sick')
self.assertEqual(cm.exception.args[2], '${dollars:${sick}}') #rawval
示例2: test_other_errors
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import InterpolationMissingOptionError [as 别名]
def test_other_errors(self):
cf = self.fromstring("""
[interpolation fail]
case1 = ${where's the brace
case2 = ${does_not_exist}
case3 = ${wrong_section:wrong_value}
case4 = ${i:like:colon:characters}
case5 = $100 for Fail No 5!
""")
with self.assertRaises(configparser.InterpolationSyntaxError):
cf['interpolation fail']['case1']
with self.assertRaises(configparser.InterpolationMissingOptionError):
cf['interpolation fail']['case2']
with self.assertRaises(configparser.InterpolationMissingOptionError):
cf['interpolation fail']['case3']
with self.assertRaises(configparser.InterpolationSyntaxError):
cf['interpolation fail']['case4']
with self.assertRaises(configparser.InterpolationSyntaxError):
cf['interpolation fail']['case5']
with self.assertRaises(ValueError):
cf['interpolation fail']['case6'] = "BLACK $ABBATH"
示例3: _check_config
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import InterpolationMissingOptionError [as 别名]
def _check_config():
parser = luigi.configuration.LuigiConfigParser.instance()
for section in parser.sections():
try:
parser.items(section)
except configparser.InterpolationMissingOptionError as e:
raise luigi.parameter.MissingParameterException(f'Environment variable "{e.args[3]}" must be set.')
示例4: test_interpolation_missing_value
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import InterpolationMissingOptionError [as 别名]
def test_interpolation_missing_value(self):
cf = self.get_interpolation_config()
e = self.get_error(cf, configparser.InterpolationMissingOptionError,
"Interpolation Error", "name")
self.assertEqual(e.reference, "reference")
self.assertEqual(e.section, "Interpolation Error")
self.assertEqual(e.option, "name")
if self.interpolation == configparser._UNSET:
self.assertEqual(e.args, ('name', 'Interpolation Error',
'%(reference)s', 'reference'))
elif isinstance(self.interpolation, configparser.LegacyInterpolation):
self.assertEqual(e.args, ('name', 'Interpolation Error',
'%(reference)s', 'reference'))
示例5: test_cfgparser_dot_3
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import InterpolationMissingOptionError [as 别名]
def test_cfgparser_dot_3(self):
tricky = support.findfile("cfgparser.3")
cf = self.newconfig()
self.assertEqual(len(cf.read(tricky, encoding='utf-8')), 1)
self.assertEqual(cf.sections(), ['strange',
'corruption',
'yeah, sections can be '
'indented as well',
'another one!',
'no values here',
'tricky interpolation',
'more interpolation'])
self.assertEqual(cf.getint(self.default_section, 'go',
vars={'interpolate': '-1'}), -1)
with self.assertRaises(ValueError):
# no interpolation will happen
cf.getint(self.default_section, 'go', raw=True,
vars={'interpolate': '-1'})
self.assertEqual(len(cf.get('strange', 'other').split('\n')), 4)
self.assertEqual(len(cf.get('corruption', 'value').split('\n')), 10)
longname = 'yeah, sections can be indented as well'
self.assertFalse(cf.getboolean(longname, 'are they subsections'))
self.assertEqual(cf.get(longname, 'lets use some Unicode'), '片仮名')
self.assertEqual(len(cf.items('another one!')), 5) # 4 in section and
# `go` from DEFAULT
with self.assertRaises(configparser.InterpolationMissingOptionError):
cf.items('no values here')
self.assertEqual(cf.get('tricky interpolation', 'lets'), 'do this')
self.assertEqual(cf.get('tricky interpolation', 'lets'),
cf.get('tricky interpolation', 'go'))
self.assertEqual(cf.get('more interpolation', 'lets'), 'go shopping')
示例6: test_interpolationmissingoptionerror
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import InterpolationMissingOptionError [as 别名]
def test_interpolationmissingoptionerror(self):
import pickle
e1 = configparser.InterpolationMissingOptionError('option', 'section',
'rawval', 'reference')
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
pickled = pickle.dumps(e1, proto)
e2 = pickle.loads(pickled)
self.assertEqual(e1.message, e2.message)
self.assertEqual(e1.args, e2.args)
self.assertEqual(e1.section, e2.section)
self.assertEqual(e1.option, e2.option)
self.assertEqual(e1.reference, e2.reference)
self.assertEqual(repr(e1), repr(e2))
示例7: test_get_extended_interpolation
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import InterpolationMissingOptionError [as 别名]
def test_get_extended_interpolation(self):
parser = configparser.ConfigParser(
interpolation=configparser.ExtendedInterpolation())
parser.read_string("""
[Paths]
home_dir: /Users
my_dir: ${home_dir1}/lumberjack
my_pictures: ${my_dir}/Pictures
""")
cm = self.assertRaises(configparser.InterpolationMissingOptionError)
with cm:
parser.get('Paths', 'my_dir')
self.assertIs(cm.exception.__suppress_context__, True)