当前位置: 首页>>代码示例>>Python>>正文


Python ModelFile.get方法代码示例

本文整理汇总了Python中Shine.Configuration.ModelFile.ModelFile.get方法的典型用法代码示例。如果您正苦于以下问题:Python ModelFile.get方法的具体用法?Python ModelFile.get怎么用?Python ModelFile.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Shine.Configuration.ModelFile.ModelFile的用法示例。


在下文中一共展示了ModelFile.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_various_fold_range

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import get [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']
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:51,代码来源:ModelFileTest.py

示例2: testMultipleElement

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import get [as 别名]
    def testMultipleElement(self):
        """ModelFile with MultipleElement"""
        model = ModelFile()
        model.add_element('foos', check='digit', multiple=True)

        # Default
        self.assertEqual(model.get('foos', []), [])

        # Multiple add()
        model.add('foos', 3)
        self.assertEqual(model.get('foos'), [3])
        self.assertEqual(str(model), "foos:3")
        model.add('foos', 5)
        self.assertEqual(model.get('foos'), [3, 5])
        self.assertEqual(str(model), "foos:3\nfoos:5")
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:17,代码来源:ModelFileTest.py

示例3: testExpandRange

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import get [as 别名]
    def testExpandRange(self):
        """parse ranged line expand correctly"""
        model = ModelFile()
        model.add_element("foo", check="string", multiple=True)

        model.parse("foo: mine[10-15]")
        self.assertEqual(len(model.get('foo')), 6)
        del model['foo']

        model.parse("foo: mine[10-15] second[1-6]")
        self.assertEqual(len(model.get('foo')), 6)
        del model['foo']

        # Ranges mismatch
        self.assertRaises(ModelFileValueError, model.parse, "foo: five[1-5] two[1-2]")
开发者ID:kcgthb,项目名称:lustre-shine,代码行数:17,代码来源:ModelFileTest.py

示例4: testModelBaseMethods

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import get [as 别名]
    def testModelBaseMethods(self):
        """test ModelFile base methods"""

        model = ModelFile()

        # content() with a default value
        self.assertEqual(model.content('default'), 'default')

        model.add_element('foo', check='string', multiple=True)

        # get() with a default value
        self.assertEqual(model.get('foo', 'default'), 'default')

        # Only key with non-empty value are taken in account
        self.assertEqual(len(model), 0)

        # parse() 
        self.assertRaises(ModelFileValueError, model.parse, "foo one two")

        # __contains__() False
        self.assertFalse('foo' in model)

        # iter()
        model.add('foo', "5 6")
        model.add('foo', "6 7")
        self.assertEqual(list(iter(model)), ['foo'])

        # __contains__() True
        self.assertTrue('foo' in model)
开发者ID:kcgthb,项目名称:lustre-shine,代码行数:31,代码来源:ModelFileTest.py

示例5: testModelBaseMethods

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import get [as 别名]
    def testModelBaseMethods(self):
        """test ModelFile base methods"""

        model = ModelFile()

        # content() with a default value
        self.assertEqual(model.content('default'), 'default')

        model.add_element('foo', check='string', multiple=True)

        # get() with a default value
        self.assertEqual(model.get('foo', 'default'), 'default')

        # Only key with non-empty value are taken in account
        self.assertEqual(len(model), 0)

        # parse() bad syntax
        self.assertRaises(ModelFileValueError, model.parse, "foo one two")
        # parse() with good syntax, but unknown key
        self.assertRaises(ModelFileValueError, model.parse, "good: syntax")

        # __contains__() False
        self.assertFalse('foo' in model)

        # iter()
        model.add('foo', "5 6")
        model.add('foo', "6 7")
        self.assertEqual(list(iter(model)), ['foo'])

        # __contains__() True
        self.assertTrue('foo' in model)

        # replace()
        model.replace('foo', "other")
        self.assertEqual(model.get('foo'), ['other'])

        # __eq__()
        other = model.emptycopy()
        self.assertNotEqual(model, other)
        other.add("foo", "other")
        self.assertEqual(model, other)
        self.assertNotEqual(model, "bad type object")
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:44,代码来源:ModelFileTest.py

示例6: testCompoundElement

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import get [as 别名]
    def testCompoundElement(self):
        """test a ModelFile with a compound element"""
        class MyCompound(ModelFile):
            def __init__(self, sep='=', linesep=' '):
                ModelFile.__init__(self, sep, linesep)
                self.add_element('dev', check='path')
                self.add_element('index', check='digit')
                self.add_element('jdev', check='path')
                self.add_element('mode', check='enum', default='managed',
                                 values=['managed', 'external'])

        elem = MyCompound()
        elem.parse("dev=/dev/sdb jdev=/dev/sdc index=4")
        self.assertEqual(elem.get('dev'), '/dev/sdb')
        self.assertEqual(elem.get('jdev'), '/dev/sdc')
        self.assertEqual(elem.get('index'), 4)
        self.assertEqual(elem.get('mode'), 'managed')

        model = ModelFile()
        model.add_element('fsname', check='string')
        model.add_custom('mgt', MyCompound(), multiple=True)
        model.add_custom('mdt', MyCompound(), multiple=True)
        model.add_custom('ost', MyCompound(), multiple=True)

        model.parse("ost: dev=/dev/sdb index=4")
        self.assertEqual(len(model.get('ost')), 1)
        self.assertEqual(model.get('ost')[0].get('dev'), '/dev/sdb')
        self.assertEqual(model.get('ost')[0].get('index'), 4)
        model.parse("ost: dev=/dev/sdd index=5")
        self.assertEqual(len(model.get('ost')), 2)
        self.assertEqual(model.get('ost')[1].get('dev'), '/dev/sdd')
        self.assertEqual(model.get('ost')[1].get('index'), 5)

        self.assertEqual(str(model), "ost:index=4 dev=/dev/sdb\n"
                "ost:index=5 dev=/dev/sdd")
开发者ID:kcgthb,项目名称:lustre-shine,代码行数:37,代码来源:ModelFileTest.py

示例7: test_expand_fold_range

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import get [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]")
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:25,代码来源:ModelFileTest.py

示例8: testLoadModelFromFile

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import get [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)
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:20,代码来源:ModelFileTest.py

示例9: testAddCustomElement

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import get [as 别名]
    def testAddCustomElement(self):
        """model file uses a user-defined Element"""
        class ElemNodeSet(SimpleElement):
            def __init__(self, check='string', default=None, values=None):
                SimpleElement.__init__(self, 'string', default, values)

            def _validate(self, value):
                try:
                    return NodeSet(value)
                except:
                    raise ModelFileValueError

        model = ModelFile()
        model.add_custom('nodes', ElemNodeSet(), multiple=True)
        model.add_custom('nids', ElemNodeSet(), multiple=True)

        model.add('nodes', 'foo[1-5]')
        self.assertEqual(str(model), "nodes:foo[1-5]")
        self.assertEqual([str(item) for item in model.get('nodes')],
                [str(NodeSet('foo[1-5]'))])
        self.assertRaises(ModelFileValueError, model.add, 'nodes', 'bad[15')
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:23,代码来源:ModelFileTest.py

示例10: testModelStandardElement

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import get [as 别名]
    def testModelStandardElement(self):
        """ModelFile with simple Element"""
        model = ModelFile()

        # Type string
        model.add_element('name', check='string')
        self.assertEqual(model.get('name', 'mine'), 'mine')
        model.add('name', 'foo')
        self.assertEqual(model.get('name'), 'foo')
        self.assertEqual(str(model), "name:foo")

        # Default value
        model.add_element('bar', check='string', default='barbar')
        self.assertEqual(model.get('bar'), 'barbar')
        self.assertEqual(model.get('bar', 'mine'), 'barbar')
        # Default value are not used for string representation
        self.assertEqual(str(model), "name:foo")

        # Type digit
        model.add_element('stripe_count', check='digit', default=1)
        self.assertEqual(model.get('stripe_count'), 1)
        model.add('stripe_count', 2)
        self.assertEqual(model.get('stripe_count'), 2)
        self.assertEqual(str(model), "name:foo\nstripe_count:2")
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:26,代码来源:ModelFileTest.py


注:本文中的Shine.Configuration.ModelFile.ModelFile.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。