コード例 #1
0
    def test_build_xml(self):
        xml3 = """<?xml version='1.0' encoding='UTF-8'?>
                    <property>
                        <id></id>
                        <type></type>
                        <propertyType></propertyType>
                        <salePriority></salePriority>
                        <image></image>
                    </property>
                """

        obj3 = parse(xml3, mode='rw')

        obj3.set_value_by_path('property.id', '353324')
        obj3.set_value_by_path('property.type', 'house')
        obj3.set_value_by_path('property.propertyType', 'house')
        obj3.set_value_by_path('property.salePriority', 'high')
        obj3.set_value_by_path('property.image', 'https://img.599245196.jpg')

        obj3 = parse(dump_str(obj3))
        paths = {
            'property.id', 'property.type', 'property.propertyType',
            'property.salePriority', 'property.image'
        }
        self.assertEqual(obj3.paths, paths)

        value_mapping = {
            'property.image': 'https://img.599245196.jpg',
            'property.id': '353324',
            'property.propertyType': 'house',
            'property.type': 'house',
            'property.salePriority': 'high'
        }

        self.assertEqual(obj3.value_mapping, value_mapping)
コード例 #2
0
ファイル: __init__.py プロジェクト: alexxi0213/xmapper
    def __init__(self, input, output):
        self.input_obj = parse(input)
        self.output_obj = parse(output)

        # default mapping format
        self.MAPPER = {
            'exact_match': {},
            'multiple_match': {},
            'human_intervention': {}
        }
コード例 #3
0
    def test_basic(self):
        xml1 = """<?xml version='1.0' encoding='UTF-8'?>
                    <property>
                        <id>353324</id>
                        <type>house</type>
                        <propertyType>house</propertyType>
                        <salePriority>high</salePriority>
                        <image>https://img.599245196.jpg</image>
                    </property>
                """

        obj1 = parse(xml1, mode='r')
        paths = {
            'property.id', 'property.type', 'property.propertyType',
            'property.salePriority', 'property.image'
        }
        self.assertEqual(obj1.paths, paths)

        value_mapping = {
            'property.image': 'https://img.599245196.jpg',
            'property.id': '353324',
            'property.propertyType': 'house',
            'property.type': 'house',
            'property.salePriority': 'high'
        }

        self.assertEqual(obj1.value_mapping, value_mapping)
コード例 #4
0
    def test_complex(self):
        xml2 = """<?xml version="1.0" encoding="UTF-8"?>
                    <bookstore>
                        <book category="cooking">
                            <title lang="en">Everyday Italian</title>
                            <author>Giada De Laurentiis</author>
                            <year>2005</year>
                            <price>30.00</price>
                        </book>
                        <book category="children">
                            <title lang="en">Harry Potter</title>
                            <author>J K. Rowling</author>
                            <year>2005</year>
                            <price>29.99</price>
                        </book>
                        <book category="web">
                            <title lang="en">Learning XML</title>
                            <author>Erik T. Ray</author>
                            <year>2003</year>
                            <price>39.95</price>
                        </book>
                    </bookstore>"""

        obj2 = parse(xml2, mode='r')
        paths = {
            'bookstore.book.0.title', 'bookstore.book.0.price',
            'bookstore.book.1.price', 'bookstore.book.1.year',
            'bookstore.book.0.year', 'bookstore.book.1.author',
            'bookstore.book.2.title', 'bookstore.book.2.price',
            'bookstore.book.2.year', 'bookstore.book.0.author',
            'bookstore.book.2.author', 'bookstore.book.1.title'
        }
        self.assertEqual(obj2.paths, paths)

        self.assertEqual(obj2.get_value_by_path('bookstore.book.0.title'),
                         'Everyday Italian')
        self.assertEqual(obj2.get_value_by_path('bookstore.book.2.year'),
                         '2003')
        self.assertEqual(obj2.get_attr_by_path('bookstore.book.0.title'),
                         {'lang': 'en'})
        self.assertEqual(obj2.get_attr_by_path('bookstore.book.2'),
                         {'category': 'web'})
コード例 #5
0
 def test_special_tag_name(self):
     xml_str = """<?xml version='1.0' encoding='utf-8'?>
     <properties>
         <java.version>11</java.version>
         <mybatisplus-maven-plugin.version>1.0</mybatisplus-maven-plugin.version>
         <shedlock-provider-jdbc_template.version>4.0.1</shedlock-provider-jdbc_template.version>
     </properties>"""
     obj = parse(xml_str, mode='r')
     expected_value_mapping = {
         'properties.java!version': '11',
         'properties.shedlock~provider~jdbc_template!version': '4.0.1',
         'properties.mybatisplus~maven~plugin!version': '1.0'
     }
     self.assertEqual(expected_value_mapping, obj.value_mapping)
     self.assertEqual(obj.get_value_by_path('properties.java!version'),
                      '11')
     self.assertEqual(
         obj.get_value_by_path(
             'properties.shedlock~provider~jdbc_template!version'), '4.0.1')
     output_xml_str = dump_str(obj)
     self.assertTrue(
         '<shedlock-provider-jdbc_template.version>' in output_xml_str)
     self.assertTrue('<java.version>' in output_xml_str)
コード例 #6
0
ファイル: __init__.py プロジェクト: alexxi0213/xmapper
 def __init__(self, file_one, file_two):
     self.obj_file_one = parse(file_one)
     self.obj_file_two = parse(file_two)