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


Python Template.build_mir_from_data方法代码示例

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


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

示例1: TemplateTest

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import build_mir_from_data [as 别名]
class TemplateTest(unittest.TestCase):

    """ unit test for template """

    def setUp(self):
        """ set up data """
        self.spec_yaml = """
            001: id
            200: [ authors, { a: name, b: firstname } ]
            300: { a: title, b: subtitle }
            700: [ auth_author, { a: name, b: firstname } ]
            701: [ auth_author, { a: name, b: firstname } ]
            002: code 
            400: { a: ville, b: adresse }
        """
        self.mir_yaml = """
            - [001, PPNxxxx ]
            - [002, toto ]
            - [200, [ [a, Doe], [b, elias], [b, frederik], [b, john] ]]
            - [200, [ [a, Doe], [b, jane]                            ]]
            - [300, [ [a, "i can haz title"], [b, "also subs"]       ]]
            - [400, [ [a, "Strasbourg"], [b, "rue 1"], [b, "rue 2"]       ]]
        """
        self.data_yaml = """
            authors:
                - { name: Doe, firstname: [elias, frederik, john] }
                - { name: Doe, firstname: jane }
            title: "i can haz title"
            subtitle: "also subs"
            id: PPNxxxx
            code: toto
            adresse: [rue 1, rue 2]
            ville: Strasbourg
        """
        self.template = Template(yaml.safe_load(self.spec_yaml))

    def test_build_data_from_mir(self):
        """ test to build data from mir """
        self.template.build_data_from_mir(yaml.safe_load(self.mir_yaml))
        template_data_dump = yaml.dump(self.template.data)
        test_data_dump = yaml.dump(yaml.safe_load(self.data_yaml))
        self.assertEqual(template_data_dump, test_data_dump)

    def test_build_mir_from_data(self):
        """ test to build mir from data """
        self.template.build_mir_from_data(yaml.safe_load(self.data_yaml))
        template_mir_dump = yaml.dump(self.template.mir)
        test_mir_dump = yaml.dump(yaml.safe_load(self.mir_yaml))
        self.assertEqual(template_mir_dump, test_mir_dump)
开发者ID:dotmobo,项目名称:pyromarc-template,代码行数:51,代码来源:test.py

示例2: open

# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import build_mir_from_data [as 别名]
    - [400, [ [a, "Strasbourg"], [b, "rue 1"], [b, "rue 2"]       ]]
    """

    data_yaml = """
    authors:
        - { name: Doe, firstname: [elias, frederik, john] }
        - { name: Doe, firstname: jane }
    title: "i can haz title"
    subtitle: "also subs"
    id: PPNxxxx
    code: toto
    adresse: [rue 1, rue 2]
    ville: Strasbourg
    """

    with open(url) as f:
        template = Template(yaml.safe_load(f))
        log.logger.info("Spec: %s\n----------\n", template.spec)
        template.build_data_from_mir(yaml.safe_load(mir_yaml))
        log.logger.info("BUILD DATA FROM MIR\n----------")
        log.logger.info("Mir: %s\n----------", template.mir)
        log.logger.info("Mir Yaml: %s\n----------", yaml.dump(template.mir))
        log.logger.info("Data: %s\n\n", template.data)
        log.logger.info("Data Yaml: %s\n\n", yaml.dump(template.data))
        template.build_mir_from_data(yaml.safe_load(data_yaml))
        log.logger.info("BUILD MIR FROM DATA\n----------")
        log.logger.info("Mir: %s\n----------", template.mir)
        log.logger.info("Mir Yaml: %s\n----------", yaml.dump(template.mir))
        log.logger.info("Data: %s\n\n", template.data)
        log.logger.info("Data Yaml: %s\n\n", yaml.dump(template.data))
开发者ID:dotmobo,项目名称:pyromarc-template,代码行数:32,代码来源:main.py


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