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


Python DataHandler.get_xsd2方法代码示例

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


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

示例1: RendererMainTestSuite

# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd2 [as 别名]
class RendererMainTestSuite(TestCase):
    """
    """

    def setUp(self):
        schema_data = join('utils', 'XSDParser', 'tests', 'data', 'parser')
        self.schema_data_handler = DataHandler(schema_data)

        self.request = HttpRequest()
        engine = import_module('django.contrib.sessions.backends.db')
        session_key = None
        self.request.session = engine.SessionStore(session_key)

        self.request.session['curate_edit'] = False  # Data edition

        form_data = FormData()
        form_data.name = ''
        form_data.user = ''
        form_data.template = ''

        form_data.save()

        self.request.session['curateFormData'] = form_data.pk

    def test_list_renderer(self):
        main_directory = self.schema_data_handler.dirname
        main_dir_len = len(main_directory) + 1

        filepath_list = []

        for root, dirs, files in walk(main_directory):
            for filename in files:
                file_ext = splitext(filename)

                if file_ext[1] == '.xsd':
                    full_path = join(root, file_ext[0])
                    filepath_list.append(full_path[main_dir_len:])

        report_content = []
        error_count = 0

        for filepath in filepath_list:
            report_line = filepath

            try:
                xsd_data = self.schema_data_handler.get_xsd2(filepath)
                self.request.session['xmlDocTree'] = etree.tostring(xsd_data)

                root_pk = generate_form(self.request)
                root_element = SchemaElement.objects.get(pk=root_pk)

                renderer = ListRenderer(root_element)
                renderer.render()

                if len(renderer.warnings) != 0:
                    report_line += ',NOK,' + ','.join(renderer.warnings) + '\n'
                    error_count += 1
                else:  # No warnings yielded by the renderer
                    report_line += ',OK\n'
            except Exception as e:
                report_line += ',NOK,' + e.message + '\n'
                error_count += 1

            report_content.append(report_line)

        with open(join(SITE_ROOT, 'full_tests_report.csv'), 'w') as report_file:
            report_file.writelines(report_content)

        self.assertEqual(error_count, 0)

    def test_xml_renderer(self):
        main_directory = self.schema_data_handler.dirname
        main_dir_len = len(main_directory) + 1

        filepath_list = []

        for root, dirs, files in walk(main_directory):
            for filename in files:
                file_ext = splitext(filename)

                if file_ext[1] == '.xsd':
                    full_path = join(root, file_ext[0])
                    filepath_list.append(full_path[main_dir_len:])

        report_content = []
        error_count = 0

        for filepath in filepath_list:
            report_line = filepath

            try:
                xsd_data = self.schema_data_handler.get_xsd2(filepath)
                self.request.session['xmlDocTree'] = etree.tostring(xsd_data)

                root_pk = generate_form(self.request)
                root_element = SchemaElement.objects.get(pk=root_pk)

                renderer = XmlRenderer(root_element)
                renderer.render()

#.........这里部分代码省略.........
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:103,代码来源:__init__.py


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