本文整理匯總了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()))