Exemple #1
0
    def assert_xml_equal(self, a, b):
        """
        Compare two XML artifacts for equality.

        :param a, b:
            Paths to XML files, or a file-like object containing the XML
            contents.
        """
        contents_a = tostring(et.parse(a).getroot(), nsmap=PARSE_NS_MAP)
        contents_b = tostring(et.parse(b).getroot(), nsmap=PARSE_NS_MAP)
        self.assertEqual(contents_a, contents_b)
Exemple #2
0
def assert_xml_equal(a, b):
    """
    Compare two XML artifacts for equality.

    :param a, b:
        Paths to XML files, or a file-like object containing the XML
        contents.
    """
    path_a = get_path(a)
    path_b = get_path(b)
    content_a = tostring(parse(a).getroot())
    content_b = tostring(parse(b).getroot())
    if content_a != content_b:
        raise AssertionError('The files %s and %s are different!' %
                             (path_a, path_b))
Exemple #3
0
    def test_tostring(self):
        nrml = etree.Element(
            'nrml', {'xmlns': 'http://openquake.org/xmlns/nrml/0.4'})
        em = etree.SubElement(
            nrml, 'exposureModel',
            {'id': "my_exposure_model_for_population",
             'category': "population",
             'taxonomySource': "fake population datasource"})

        descr = etree.SubElement(em, 'description')
        descr.text = 'Sample population'
        etree.SubElement(em, 'assets')
        self.assertEqual(tostring(nrml), '''\
<nrml
xmlns="http://openquake.org/xmlns/nrml/0.4"
>
    <exposureModel
    category="population"
    id="my_exposure_model_for_population"
    taxonomySource="fake population datasource"
    >
        <description>
            Sample population
        </description>
        <assets />
    </exposureModel>
</nrml>
''')
Exemple #4
0
    def test_tostring(self):
        nrml = etree.Element('nrml',
                             {'xmlns': 'http://openquake.org/xmlns/nrml/0.4'})
        em = etree.SubElement(
            nrml, 'exposureModel', {
                'id': "my_exposure_model_for_population",
                'category': "population",
                'taxonomySource': "fake population datasource"
            })

        descr = etree.SubElement(em, 'description')
        descr.text = 'Sample population'
        etree.SubElement(em, 'assets')
        self.assertEqual(
            tostring(nrml), '''\
<nrml
xmlns="http://openquake.org/xmlns/nrml/0.4"
>
    <exposureModel
    category="population"
    id="my_exposure_model_for_population"
    taxonomySource="fake population datasource"
    >
        <description>
            Sample population
        </description>
        <assets />
    </exposureModel>
</nrml>
''')
    def test_tostring(self):
        nrml = etree.Element("nrml", {"xmlns": "http://openquake.org/xmlns/nrml/0.4"})
        em = etree.SubElement(
            nrml,
            "exposureModel",
            {
                "id": "my_exposure_model_for_population",
                "category": "population",
                "taxonomySource": "fake population datasource",
            },
        )

        descr = etree.SubElement(em, "description")
        descr.text = "Sample population"
        etree.SubElement(em, "assets")
        self.assertEqual(
            tostring(nrml),
            """\
<nrml
xmlns="http://openquake.org/xmlns/nrml/0.4"
>
    <exposureModel
    category="population"
    id="my_exposure_model_for_population"
    taxonomySource="fake population datasource"
    >
        <description>
            Sample population
        </description>
        <assets />
    </exposureModel>
</nrml>
""",
        )
Exemple #6
0
def assert_xml_equal(a, b):
    """
    Compare two XML artifacts for equality.

    :param a, b:
        Paths to XML files, or a file-like object containing the XML
        contents.
    """
    path_a = get_path(a)
    path_b = get_path(b)
    content_a = tostring(parse(a).getroot(), nsmap=PARSE_NS_MAP)
    content_b = tostring(parse(b).getroot(), nsmap=PARSE_NS_MAP)
    if content_a != content_b:
        # uncomment this to see the differences
        # warnings.warn(content_a, stacklevel=2)
        raise AssertionError('The files %s and %s are different!' %
                             (path_a, path_b))