• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python yamlparser.simple_parse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中toscaparser.utils.yamlparser.simple_parse函数的典型用法代码示例。如果您正苦于以下问题:Python simple_parse函数的具体用法?Python simple_parse怎么用?Python simple_parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_built_in_datatype

    def test_built_in_datatype(self):
        value_snippet = '''
        private_network:
          network_name: private
          network_id: 3e54214f-5c09-1bc9-9999-44100326da1b
          addresses: [ 10.111.128.10 ]
        '''
        value = yamlparser.simple_parse(value_snippet)
        data = DataEntity('tosca.datatypes.network.NetworkInfo',
                          value.get('private_network'))
        self.assertIsNotNone(data.validate())

        value_snippet = '''
        portspec_valid:
          protocol: tcp
        '''
        value = yamlparser.simple_parse(value_snippet)
        data = DataEntity('tosca.datatypes.network.PortSpec',
                          value.get('portspec_valid'))
        self.assertIsNotNone(data.validate())

        value_snippet = '''
        portspec_invalid:
          protocol: xyz
        '''
        value = yamlparser.simple_parse(value_snippet)
        data = DataEntity('tosca.datatypes.network.PortSpec',
                          value.get('portspec_invalid'))
        err = self.assertRaises(exception.ValidationError, data.validate)
        self.assertEqual(_('The value "xyz" of property "protocol" is not '
                           'valid. Expected a value from "[udp, tcp, igmp]".'
                           ),
                         err.__str__())
开发者ID:neogoku,项目名称:nfv_api,代码行数:33,代码来源:test_datatypes.py


示例2: test_constraint_for_scalar_unit

    def test_constraint_for_scalar_unit(self):
        tpl_snippet = '''
        server:
          type: tosca.my.nodes.Compute
          properties:
            cpu_frequency: 0.05 GHz
            disk_size: 500 MB
            mem_size: 1 MB
        '''
        nodetemplates = yamlparser.simple_parse(tpl_snippet)
        nodetemplate = NodeTemplate('server', nodetemplates, self.custom_def)
        props = nodetemplate.get_properties()
        if 'cpu_frequency' in props.keys():
            error = self.assertRaises(exception.ValidationError,
                                      props['cpu_frequency'].validate)
            self.assertEqual('cpu_frequency: 0.05 GHz must be greater or '
                             'equal to "0.1 GHz".', error.__str__())
        if 'disk_size' in props.keys():
            error = self.assertRaises(exception.ValidationError,
                                      props['disk_size'].validate)
            self.assertEqual('disk_size: 500 MB must be greater or '
                             'equal to "1 GB".', error.__str__())

        if 'mem_size' in props.keys():
            error = self.assertRaises(exception.ValidationError,
                                      props['mem_size'].validate)
            self.assertEqual('mem_size: 1 MB is out of range '
                             '(min:1 MiB, '
                             'max:1 GiB).', error.__str__())
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:29,代码来源:test_scalarunit.py


示例3: test_incorrect_field_in_datatype

    def test_incorrect_field_in_datatype(self):
        tpl_snippet = '''
        tosca_definitions_version: tosca_simple_yaml_1_0
        topology_template:
          node_templates:
            server:
              type: tosca.nodes.Compute

            webserver:
              type: tosca.nodes.WebServer
              properties:
                admin_credential:
                  user: username
                  token: some_pass
                  some_field: value
              requirements:
                - host: server
        '''
        tpl = yamlparser.simple_parse(tpl_snippet)
        err = self.assertRaises(exception.ValidationError, ToscaTemplate,
                                None, None, None, tpl)
        self.assertIn(_('The pre-parsed input failed validation with the '
                        'following error(s): \n\n\tUnknownFieldError: Data '
                        'value of type "tosca.datatypes.Credential" contains'
                        ' unknown field "some_field". Refer to the definition'
                        ' to verify valid values'), err.__str__())
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:26,代码来源:test_datatypes.py


示例4: test_proprety_inheritance

    def test_proprety_inheritance(self):
        from toscaparser.nodetemplate import NodeTemplate

        tosca_custom_def = '''
          tosca.nodes.SoftwareComponent.MySoftware:
            derived_from: SoftwareComponent
            properties:
              install_path:
                required: false
                type: string
                default: /opt/mysoftware
        '''

        tosca_node_template = '''
          node_templates:
            mysoftware_instance:
              type: tosca.nodes.SoftwareComponent.MySoftware
              properties:
                component_version: 3.1
        '''

        expected_properties = ['component_version',
                               'install_path']

        nodetemplates = yamlparser.\
            simple_parse(tosca_node_template)['node_templates']
        custom_def = yamlparser.simple_parse(tosca_custom_def)
        name = list(nodetemplates.keys())[0]
        tpl = NodeTemplate(name, nodetemplates, custom_def)
        self.assertIsNone(tpl.validate())
        self.assertEqual(expected_properties,
                         sorted(tpl.get_properties().keys()))
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:32,代码来源:test_properties.py


示例5: test_constraint_for_scalar_unit

    def test_constraint_for_scalar_unit(self):
        tpl_snippet = '''
        server:
          type: tosca.my.nodes.Compute
          properties:
            cpu_frequency: 0.05 GHz
            disk_size: 500 MB
            mem_size: 1 MB
        '''
        nodetemplates = yamlparser.simple_parse(tpl_snippet)
        nodetemplate = NodeTemplate('server', nodetemplates, self.custom_def)
        props = nodetemplate.get_properties()
        if 'cpu_frequency' in props.keys():
            error = self.assertRaises(exception.ValidationError,
                                      props['cpu_frequency'].validate)
            self.assertEqual(_('The value "0.05 GHz" of property '
                               '"cpu_frequency" must be greater than or equal '
                               'to "0.1 GHz".'), error.__str__())
        if 'disk_size' in props.keys():
            error = self.assertRaises(exception.ValidationError,
                                      props['disk_size'].validate)
            self.assertEqual(_('The value "500 MB" of property "disk_size" '
                               'must be greater than or equal to "1 GB".'),
                             error.__str__())

        if 'mem_size' in props.keys():
            error = self.assertRaises(exception.ValidationError,
                                      props['mem_size'].validate)
            self.assertEqual(_('The value "1 MB" of property "mem_size" is '
                               'out of range "(min:1 MiB, max:1 GiB)".'),
                             error.__str__())
开发者ID:jphilip09,项目名称:tosca-parser,代码行数:31,代码来源:test_scalarunit.py


示例6: test_range_unbounded

 def test_range_unbounded(self):
     value_snippet = '''
     temperature: [-100, 999999]
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('tosca.my.datatypes.TestLab', value,
                       DataTypeTest.custom_type_def)
     self.assertIsNotNone(data.validate())
开发者ID:rickyhai11,项目名称:tosca-parser,代码行数:8,代码来源:test_datatypes.py


示例7: test_schema_none_description

 def test_schema_none_description(self):
     tpl_snippet = '''
     cpus:
       type: integer
     '''
     schema = yamlparser.simple_parse(tpl_snippet)
     cpus_schema = Schema('cpus', schema['cpus'])
     self.assertEqual('', cpus_schema.description)
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:8,代码来源:test_constraints.py


示例8: _get_nodetemplate

 def _get_nodetemplate(self, tpl_snippet,
                       custom_def_snippet=None):
     nodetemplates = yamlparser.\
         simple_parse(tpl_snippet)['node_templates']
     custom_def = yamlparser.simple_parse(custom_def_snippet)
     name = list(nodetemplates.keys())[0]
     tpl = NodeTemplate(name, nodetemplates, custom_def)
     return tpl
开发者ID:santhoshkmr64,项目名称:santhosh,代码行数:8,代码来源:test_properties.py


示例9: test_schema_miss_type

 def test_schema_miss_type(self):
     tpl_snippet = '''
     cpus:
       description: Number of CPUs for the server.
     '''
     schema = yamlparser.simple_parse(tpl_snippet)
     error = self.assertRaises(exception.InvalidSchemaError, Schema,
                               'cpus', schema['cpus'])
     self.assertEqual('Schema cpus must have type.', str(error))
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:9,代码来源:test_constraints.py


示例10: test_custom_datatype

 def test_custom_datatype(self):
     value_snippet = '''
     name: Mike
     gender: male
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('tosca.my.datatypes.PeopleBase', value,
                       DataTypeTest.custom_type_def)
     self.assertIsNotNone(data.validate())
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:9,代码来源:test_datatypes.py


示例11: test_built_in_datatype_without_properties

 def test_built_in_datatype_without_properties(self):
     value_snippet = '''
     2
     '''
     value = yamlparser.simple_parse(value_snippet)
     datatype = DataType('PortDef')
     self.assertEqual('integer', datatype.value_type)
     data = DataEntity('PortDef', value)
     self.assertIsNotNone(data.validate())
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:9,代码来源:test_datatypes.py


示例12: test_default_field_in_dataentity

 def test_default_field_in_dataentity(self):
     value_snippet = '''
     name: Mike
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('tosca.my.datatypes.PeopleBase', value,
                       DataTypeTest.custom_type_def)
     data = data.validate()
     self.assertEqual('unknown', data.get('gender'))
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:9,代码来源:test_datatypes.py


示例13: test_built_in_nested_datatype

 def test_built_in_nested_datatype(self):
     value_snippet = '''
     user_port:
       protocol: tcp
       target: [50000]
       source: [9000]
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('PortSpec', value.get('user_port'))
     self.assertIsNotNone(data.validate())
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:10,代码来源:test_datatypes.py


示例14: test_valid_ranges_against_constraints

    def test_valid_ranges_against_constraints(self):

        # The TestLab range type has max=UNBOUNDED
        value_snippet = '''
        temperature1: [-255, 999999]
        '''
        value = yamlparser.simple_parse(value_snippet)
        data = DataEntity('tosca.my.datatypes.TestLab', value,
                          DataTypeTest.custom_type_def)
        self.assertIsNotNone(data.validate())

        # The TestLab range type has min=UNBOUNDED
        value_snippet = '''
        temperature2: [-999999, 255]
        '''
        value = yamlparser.simple_parse(value_snippet)
        data = DataEntity('tosca.my.datatypes.TestLab', value,
                          DataTypeTest.custom_type_def)
        self.assertIsNotNone(data.validate())
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:19,代码来源:test_datatypes.py


示例15: test_functions_datatype

 def test_functions_datatype(self):
     value_snippet = '''
     admin_credential:
       user: username
       token: { get_input: password }
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('tosca.datatypes.Credential',
                       value.get('admin_credential'))
     self.assertIsNotNone(data.validate())
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:10,代码来源:test_datatypes.py


示例16: test_schema_not_dict

 def test_schema_not_dict(self):
     tpl_snippet = '''
     cpus:
       - type: integer
       - description: Number of CPUs for the server.
     '''
     schema = yamlparser.simple_parse(tpl_snippet)
     error = self.assertRaises(exception.InvalidSchemaError, Schema,
                               'cpus', schema['cpus'])
     self.assertEqual('Schema cpus must be a dict.', str(error))
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:10,代码来源:test_constraints.py


示例17: test_valid_range_type

 def test_valid_range_type(self):
     value_snippet = '''
     user_port:
       protocol: tcp
       target_range:  [20000, 60000]
       source_range:  [1000, 3000]
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('PortSpec', value.get('user_port'))
     self.assertIsNotNone(data.validate())
开发者ID:rickyhai11,项目名称:tosca-parser,代码行数:10,代码来源:test_datatypes.py


示例18: test_type_error_in_dataentity

 def test_type_error_in_dataentity(self):
     value_snippet = '''
     name: 123
     gender: male
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('tosca.my.datatypes.PeopleBase', value,
                       DataTypeTest.custom_type_def)
     error = self.assertRaises(ValueError, data.validate)
     self.assertEqual('"123" is not a string.', error.__str__())
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:10,代码来源:test_datatypes.py


示例19: test_non_dict_value_for_datatype

 def test_non_dict_value_for_datatype(self):
     value_snippet = '''
     [Tom, Jerry]
     '''
     value = yamlparser.simple_parse(value_snippet)
     data = DataEntity('tosca.my.datatypes.PeopleBase', value,
                       DataTypeTest.custom_type_def)
     error = self.assertRaises(exception.TypeMismatchError, data.validate)
     self.assertEqual('[\'Tom\', \'Jerry\'] must be of type: '
                      '"tosca.my.datatypes.PeopleBase".', error.__str__())
开发者ID:rakesh-cliqr,项目名称:tosca-parser,代码行数:10,代码来源:test_datatypes.py


示例20: test_scenario_scalar_unit_positive

 def test_scenario_scalar_unit_positive(self):
     tpl = self.tpl_snippet
     nodetemplates = yamlparser.simple_parse(tpl)
     nodetemplate = NodeTemplate('server', nodetemplates)
     props = nodetemplate.get_capability('host').get_properties()
     prop_name = self.property
     if props and prop_name in props.keys():
         prop = props[prop_name]
         self.assertIsNone(prop.validate())
         resolved = prop.value
     self.assertEqual(resolved, self.expected)
开发者ID:jphilip09,项目名称:tosca-parser,代码行数:11,代码来源:test_scalarunit.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python provider.ProviderFactory类代码示例发布时间:2022-05-27
下一篇:
Python gettextutils._函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap