本文整理汇总了Python中Shine.Configuration.ModelFile.ModelFile.elements方法的典型用法代码示例。如果您正苦于以下问题:Python ModelFile.elements方法的具体用法?Python ModelFile.elements怎么用?Python ModelFile.elements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shine.Configuration.ModelFile.ModelFile
的用法示例。
在下文中一共展示了ModelFile.elements方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_various_fold_range
# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import elements [as 别名]
def test_various_fold_range(self):
"""fold complex patterns involving ordering"""
model = ModelFile()
model.add_element("foo", check="string", multiple=True, fold=True)
# Folding without digit is fine
model.parse('foo: cat')
model.parse('foo: dog')
self.assertEqual(len(model.get('foo')), 2)
self.assertEqual(str(model.elements('foo')), 'cat\ndog')
copy = model.emptycopy()
copy.parse(str(model))
self.assertEqual(copy, model)
del model['foo']
# Keeps order
model.parse('foo: foo1')
model.parse('foo: foo3')
model.parse('foo: foo2')
self.assertEqual(len(model.get('foo')), 3)
self.assertEqual(str(model.elements('foo')), 'foo[1,3]\nfoo2')
copy = model.emptycopy()
copy.parse(str(model))
self.assertEqual(copy, model)
del model['foo']
# Complex ordering
model.parse("foo: mine[10-15] second[1-6]")
model.parse("foo: mine[8] second[7]")
model.parse("foo: mine[16] second[8]")
self.assertEqual(len(model.get('foo')), 8)
self.assertEqual(str(model.elements('foo')), 'mine[10-15] second[1-6]\n'
'mine[8,16] second[7-8]')
copy = model.emptycopy()
copy.parse(str(model))
self.assertEqual(copy, model)
del model['foo']
# Static column
model.parse("foo: mine[10-15] second1")
model.parse("foo: mine[16] second1")
model.parse("foo: mine[16] second2")
self.assertEqual(len(model.get('foo')), 8)
self.assertEqual(str(model.elements('foo')), 'mine[10-16] second1\n'
'mine16 second2')
copy = model.emptycopy()
copy.parse(str(model))
self.assertEqual(copy, model)
del model['foo']
示例2: test_expand_fold_range
# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import elements [as 别名]
def test_expand_fold_range(self):
"""parse line with range expand and fold correctly"""
model = ModelFile()
model.add_element("foo", check="string", multiple=True, fold=True)
model.parse("foo: mine[10-15]")
self.assertEqual(len(model.get('foo')), 6)
self.assertEqual(str(model.elements('foo')), 'mine[10-15]')
del model['foo']
model.parse("foo: mine[10-15] second[1-6]")
self.assertEqual(len(model.get('foo')), 6)
self.assertEqual(str(model.elements('foo')), 'mine[10-15] second[1-6]')
del model['foo']
# Range supports padding
model.parse('foo: bar[01-02]')
self.assertEqual(model.get('foo'), ['bar01', 'bar02'])
self.assertEqual(str(model.elements('foo')), 'bar[01-02]')
del model['foo']
# Ranges mismatch
self.assertRaises(ModelFileValueError, model.parse, "foo: five[1-5] two[1-2]")