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


Python ModelFile.add方法代码示例

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


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

示例1: testModelBaseMethods

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import add [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

示例2: testDiffMultipleElement

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import add [as 别名]
    def testDiffMultipleElement(self):
        """diff between 2 modelfiles with a MultipleElement"""
        model = ModelFile()
        model.add_element('name', check='string', multiple=True)

        model2 = model.emptycopy()

        # Empty models have no difference
        added, changed, removed = model.diff(model2)
        self.assertEqual(added.as_dict(), {})
        self.assertEqual(removed.as_dict(), {})
        self.assertEqual(changed.as_dict(), {})

        # Same model have no difference
        model.add('name', 'foo')
        model2.add('name', 'foo')
        added, changed, removed = model.diff(model2)
        self.assertEqual(added.as_dict(), {})
        self.assertEqual(removed.as_dict(), {})
        self.assertEqual(changed.as_dict(), {})

        # Add a value
        model2.add('name', 'bar')
        added, changed, removed = model.diff(model2)
        self.assertEqual(added.as_dict(), {'name': ['bar']})
        self.assertEqual(removed.as_dict(), {})
        self.assertEqual(changed.as_dict(), {})

        # Remove a value
        del model2['name']
        model.add('name', 'bar')
        added, changed, removed = model.diff(model2)
        self.assertEqual(added.as_dict(), {})
        self.assertEqual(removed.as_dict(), {'name': ['foo', 'bar']})
        self.assertEqual(changed.as_dict(), {})
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:37,代码来源:ModelFileTest.py

示例3: testMultipleElement

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import add [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

示例4: testModelBaseMethods

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import add [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

示例5: testDiffSimpleElement

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import add [as 别名]
    def testDiffSimpleElement(self):
        """diff between 2 modelfiles with a SimpleElement"""
        model = ModelFile()
        model.add_element('name', check='string')

        model2 = model.emptycopy()

        # Empty models have no difference
        added, changed, removed = model.diff(model2)
        self.assertEqual(added.as_dict(), {})
        self.assertEqual(removed.as_dict(), {})
        self.assertEqual(changed.as_dict(), {})

        # Same model have no difference
        model.add('name', 'foo')
        model2.add('name', 'foo')
        added, changed, removed = model.diff(model2)
        self.assertEqual(added.as_dict(), {})
        self.assertEqual(removed.as_dict(), {})
        self.assertEqual(changed.as_dict(), {})

        # A value changed
        del model2['name']
        model2.add('name', 'bar')
        added, changed, removed = model.diff(model2)
        self.assertEqual(added.as_dict(), {})
        self.assertEqual(removed.as_dict(), {})
        self.assertEqual(changed.as_dict(), {'name': 'bar'})

        # A value added
        del model['name']
        added, changed, removed = model.diff(model2)
        self.assertEqual(added.as_dict(), {'name': 'bar'})
        self.assertEqual(removed.as_dict(), {})
        self.assertEqual(changed.as_dict(), {})

        # A value removed
        added, changed, removed = model2.diff(model)
        self.assertEqual(added.as_dict(), {})
        self.assertEqual(removed.as_dict(), {'name': 'bar'})
        self.assertEqual(changed.as_dict(), {})
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:43,代码来源:ModelFileTest.py

示例6: testAddCustomElement

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import add [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

示例7: testModelStandardElement

# 需要导入模块: from Shine.Configuration.ModelFile import ModelFile [as 别名]
# 或者: from Shine.Configuration.ModelFile.ModelFile import add [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.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。