本文整理汇总了Python中Shine.Configuration.ModelFile.ModelFile.load方法的典型用法代码示例。如果您正苦于以下问题:Python ModelFile.load方法的具体用法?Python ModelFile.load怎么用?Python ModelFile.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shine.Configuration.ModelFile.ModelFile
的用法示例。
在下文中一共展示了ModelFile.load方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSaveModelToFile
# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import load [as 别名]
def testSaveModelToFile(self):
"""save a ModelFile to a file"""
testfile = makeTempFile("""foo: my test
bar: 3
foo: another
bar: 1
bar: 2""")
# Create a model
model = ModelFile()
model.add_element("foo", check="string", multiple=True)
model.add_element("bar", check="digit", multiple=True)
# Load a test file
model.load(testfile.name)
# Save it to a new file
filename = makeTempFilename()
model.save(filename, "# Some header")
# Reload the file in another model
model2 = model.emptycopy()
model2.load(filename)
os.unlink(filename)
# Compare the two files. They should have no difference
added, changed, removed = model.diff(model2)
self.assertTrue(len(changed) == len(added) == len(removed) == 0)
示例2: testLoadModelFromFile
# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import load [as 别名]
def testLoadModelFromFile(self):
"""load a ModelFile from file"""
model = ModelFile()
model.add_element("foo", check="string", multiple=True)
model.add_element("bar", check="digit", multiple=True)
testfile = makeTempFile("""foo: my test
bar: 3
foo: another
bar: 1
bar: 2""")
model.load(testfile.name)
self.assertEqual(model.get('foo'), ['my test', 'another'])
self.assertEqual(model.get('bar'), [3, 1, 2])
# Bad file syntax
testfile = makeTempFile("""foo bad file""")
self.assertRaises(ModelFileValueError, model.load, testfile.name)