本文整理汇总了Python中kamaki.cli.config.Config.rescue_old_file方法的典型用法代码示例。如果您正苦于以下问题:Python Config.rescue_old_file方法的具体用法?Python Config.rescue_old_file怎么用?Python Config.rescue_old_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kamaki.cli.config.Config
的用法示例。
在下文中一共展示了Config.rescue_old_file方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rescue_old_file
# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import rescue_old_file [as 别名]
def test_rescue_old_file(self):
from kamaki.cli.config import Config
content0 = list(self.config_file_content)
def make_file(lines):
f = NamedTemporaryFile()
f.writelines(lines)
f.flush()
return f
with make_file(content0) as f:
_cnf = Config(path=f.name)
self.assertEqual([], _cnf.rescue_old_file())
del _cnf
content1, sample = list(content0), 'xyz_cli = XYZ_specs'
content1.insert(2, '%s\n' % sample)
with make_file(content1) as f:
f.seek(0)
_cnf = Config(path=f.name)
self.assertEqual(
sorted(['global.%s' % sample]), sorted(_cnf.rescue_old_file()))
del _cnf
content2, sample = list(content0), 'http://www.example2.org'
content2.insert(2, 'url = %s\n' % sample)
err = StringIO()
with make_file(content2) as f:
_cnf = Config(path=f.name)
self.assertEqual([], _cnf.rescue_old_file(err=err))
self.assertEqual(
'... rescue global.url => cloud.default.url\n', err.getvalue())
self.assertEqual(sample, _cnf.get_cloud('default', 'url'))
del _cnf
content3 = list(content0)
content3.insert(
2, 'url = http://example1.com\nurl = http://example2.com\n')
with make_file(content3) as f:
_cnf = Config(path=f.name)
self.assertEqual([], _cnf.rescue_old_file(err=err))
self.assertEqual(
2 * '... rescue global.url => cloud.default.url\n',
err.getvalue())
self.assertEqual(
'http://example2.com', _cnf.get_cloud('default', 'url'))
del _cnf
content4 = list(content0)
content4.insert(2, 'url = http://example1.com\n')
content4.append('\n[cloud "default"]\nurl=http://example2.com\n')
with make_file(content4) as f:
_cnf = Config(path=f.name)
from kamaki.cli.errors import CLISyntaxError
self.assertRaises(CLISyntaxError, _cnf.rescue_old_file)
del _cnf
content5 = list(content0)
extras = [
('pithos_cli', 'pithos'), ('store_cli', 'pithos'),
('storage_cli', 'pithos'), ('compute_cli', 'cyclades'),
('cyclades_cli', 'cyclades')]
for sample in extras:
content5.insert(2, '%s = %s\n' % sample)
with make_file(content5) as f:
_cnf = Config(path=f.name)
self.assertEqual(
sorted(['global.%s = %s' % sample for sample in extras]),
sorted(_cnf.rescue_old_file()))