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


Python _utils.assert_xml_equal函数代码示例

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


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

示例1: test_serialize

    def test_serialize(self):
        expected = StringIO.StringIO('''<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
  <totalDmgDist>
    <damageStates>no_damage slight moderate extensive complete</damageStates>
    <damage ds="no_damage" mean="1.0" stddev="1.6"/>
    <damage ds="slight" mean="34.8" stddev="18.3"/>
    <damage ds="moderate" mean="64.2" stddev="19.8"/>
    <damage ds="extensive" mean="64.3" stddev="19.7"/>
    <damage ds="complete" mean="64.3" stddev="19.7"/>
  </totalDmgDist>
</nrml>''')

        damage_states = 'no_damage slight moderate extensive complete'.split()
        writer = writers.DmgDistTotalXMLWriter(self.filename, damage_states)
        data = [
            (NO_DAMAGE, 1.0, 1.6),
            (SLIGHT, 34.8, 18.3),
            (MODERATE, 64.2, 19.8),
            (EXTENSIVE, 64.3, 19.7),
            (COMPLETE, 64.3, 19.7),
        ]
        writer.serialize(_starmap(DMG_DIST_TOTAL, data))

        _utils.assert_xml_equal(expected, self.filename)
        self.assertTrue(_utils.validates_against_xml_schema(self.filename))
开发者ID:GEMStudents,项目名称:oq-nrmllib,代码行数:26,代码来源:writers_test.py

示例2: test_serialize_optional_metadata_xml

    def test_serialize_optional_metadata_xml(self):
        expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml"
      xmlns="http://openquake.org/xmlns/nrml/0.4">
  <lossMap investigationTime="10.0" poE="0.8" statistics="quantile"
        quantileValue="0.5" lossCategory="economic" unit="USD">
    <node>
      <gml:Point>
        <gml:pos>1.0 1.5</gml:pos>
      </gml:Point>
      <loss assetRef="asset_1" mean="15.23" stdDev="2"/>
    </node>
  </lossMap>
</nrml>
""")

        writer = writers.LossMapXMLWriter(
            self.filename,
            investigation_time=10.0, poe=0.80, statistics="quantile",
            quantile_value=0.50, unit="USD", loss_category="economic"
        )

        data = [LOSS_NODE(
                asset_ref="asset_1", location=Point(1.0, 1.5), value=15.23,
                std_dev=2)]

        writer.serialize(data)

        _utils.assert_xml_equal(expected, self.filename)
        self.assertTrue(_utils.validates_against_xml_schema(self.filename))
开发者ID:GEMStudents,项目名称:oq-nrmllib,代码行数:31,代码来源:writers_test.py

示例3: test_serialize_using_hazard_realization_xml

    def test_serialize_using_hazard_realization_xml(self):
        expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml"
      xmlns="http://openquake.org/xmlns/nrml/0.4">
  <lossMap investigationTime="10.0" poE="0.8"
           sourceModelTreePath="b1|b2" gsimTreePath="b3|b4"
           lossCategory="economic" unit="USD">
    <node>
      <gml:Point>
        <gml:pos>1.0 1.5</gml:pos>
      </gml:Point>
      <loss assetRef="asset_1" value="15.23"/>
    </node>
  </lossMap>
</nrml>
""")

        writer = writers.LossMapXMLWriter(
            self.filename,
            investigation_time=10.0, poe=0.80, source_model_tree_path="b1|b2",
            gsim_tree_path="b3|b4", unit="USD", loss_category="economic")

        data = [LOSS_NODE(asset_ref="asset_1",
                          location=Point(1.0, 1.5), value=15.23, std_dev=None)]

        writer.serialize(data)

        _utils.assert_xml_equal(expected, self.filename)
        self.assertTrue(_utils.validates_against_xml_schema(self.filename))
开发者ID:GEMStudents,项目名称:oq-nrmllib,代码行数:30,代码来源:writers_test.py

示例4: test_serialize_statistics_metadata

    def test_serialize_statistics_metadata(self):
        expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml
  xmlns:gml="http://www.opengis.net/gml"
  xmlns="http://openquake.org/xmlns/nrml/0.4">
  <aggregateLossCurve
    investigationTime="10.0"
    statistics="quantile"
    quantileValue="0.5">
    <poEs>1.0 0.5 0.1</poEs>
    <losses>10.0000 20.0000 30.0000</losses>
    <averageLoss>2.0000e+00</averageLoss>
  </aggregateLossCurve>
</nrml>
""")

        writer = writers.AggregateLossCurveXMLWriter(
            self.filename,
            investigation_time=10.0, statistics="quantile",
            quantile_value=0.50)

        data = AGGREGATE_LOSS_CURVE(
            poes=[1.0, 0.5, 0.1], losses=[10.0, 20.0, 30.0], average_loss=2.)

        writer.serialize(data)

        _utils.assert_xml_equal(expected, self.filename)
        self.assertTrue(_utils.validates_against_xml_schema(self.filename))
开发者ID:GEMStudents,项目名称:oq-nrmllib,代码行数:29,代码来源:writers_test.py

示例5: test_serialize_a_model_xml

    def test_serialize_a_model_xml(self):
        expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml"
      xmlns="http://openquake.org/xmlns/nrml/0.4">
  <lossMap investigationTime="10.0" poE="0.8" statistics="mean">
    <node>
      <gml:Point>
        <gml:pos>1.0 1.5</gml:pos>
      </gml:Point>
      <loss assetRef="asset_1" value="15.23"/>
      <loss assetRef="asset_2" value="16.23"/>
    </node>
    <node>
      <gml:Point>
        <gml:pos>2.0 2.5</gml:pos>
      </gml:Point>
      <loss assetRef="asset_3" value="17.23"/>
    </node>
  </lossMap>
</nrml>
""")

        writer = writers.LossMapXMLWriter(
            self.filename, investigation_time=10.0, poe=0.8,
            statistics="mean"
        )

        writer.serialize(self.data)

        _utils.assert_xml_equal(expected, self.filename)
        self.assertTrue(_utils.validates_against_xml_schema(self.filename))
开发者ID:GEMStudents,项目名称:oq-nrmllib,代码行数:32,代码来源:writers_test.py

示例6: test_serialize_a_model

    def test_serialize_a_model(self):
        expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml
  xmlns:gml="http://www.opengis.net/gml"
  xmlns="http://openquake.org/xmlns/nrml/0.4">
  <aggregateLossCurve
    investigationTime="10.0"
    sourceModelTreePath="b1_b2_b3"
    gsimTreePath="b1_b2"
    unit="USD">
    <poEs>1.0 0.5 0.1</poEs>
    <losses>10.0000 20.0000 30.0000</losses>
    <averageLoss>3.0000e+00</averageLoss>
  </aggregateLossCurve>
</nrml>
""")

        writer = writers.AggregateLossCurveXMLWriter(
            self.filename,
            investigation_time=10.0, source_model_tree_path="b1_b2_b3",
            gsim_tree_path="b1_b2", unit="USD")

        data = AGGREGATE_LOSS_CURVE(
            poes=[1.0, 0.5, 0.1], losses=[10.0, 20.0, 30.0], average_loss=3.)

        writer.serialize(data)

        _utils.assert_xml_equal(expected, self.filename)
        self.assertTrue(_utils.validates_against_xml_schema(self.filename))
开发者ID:GEMStudents,项目名称:oq-nrmllib,代码行数:30,代码来源:writers_test.py

示例7: test_serialize_using_hazard_realization

    def test_serialize_using_hazard_realization(self):
        expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
  <bcrMap interestRate="10.0" assetLifeExpectancy="50.0" sourceModelTreePath="b1|b2" gsimTreePath="b1|b2" lossCategory="economic" unit="USD">
    <node>
      <gml:Point>
        <gml:pos>1.0 1.5</gml:pos>
      </gml:Point>
      <bcr assetRef="asset_1" ratio="15.23" aalOrig="10.5" aalRetr="20.5"/>
    </node>
  </bcrMap>
</nrml>
""")

        writer = writers.BCRMapXMLWriter(
            self.filename,
            interest_rate=10.0, asset_life_expectancy=50.0,
            source_model_tree_path="b1|b2", gsim_tree_path="b1|b2",
            unit="USD", loss_category="economic")

        data = [BCR_NODE(
                asset_ref="asset_1", location=Point(1.0, 1.5),
                bcr=15.23, average_annual_loss_original=10.5,
                average_annual_loss_retrofitted=20.5)]

        writer.serialize(data)

        _utils.assert_xml_equal(expected, self.filename)
        self.assertTrue(_utils.validates_against_xml_schema(self.filename))
开发者ID:GEMStudents,项目名称:oq-nrmllib,代码行数:30,代码来源:writers_test.py

示例8: test_serialize_a_model

    def test_serialize_a_model(self):
        expected = StringIO.StringIO(
            """\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
  <bcrMap interestRate="10.0" assetLifeExpectancy="50.0" statistics="mean">
    <node>
      <gml:Point>
        <gml:pos>1.0 1.5</gml:pos>
      </gml:Point>
      <bcr assetRef="asset_1" ratio="15.23" aalOrig="10.5" aalRetr="20.5"/>
      <bcr assetRef="asset_2" ratio="16.23" aalOrig="11.5" aalRetr="40.5"/>
    </node>
    <node>
      <gml:Point>
        <gml:pos>2.0 2.5</gml:pos>
      </gml:Point>
      <bcr assetRef="asset_3" ratio="17.23" aalOrig="12.5" aalRetr="10.5"/>
    </node>
  </bcrMap>
</nrml>
"""
        )

        writer = writers.BCRMapXMLWriter(
            self.filename, interest_rate=10.0, asset_life_expectancy=50.0, statistics="mean"
        )

        data = [
            BCR_NODE(
                asset_ref="asset_1",
                location=Point(1.0, 1.5),
                bcr=15.23,
                average_annual_loss_original=10.5,
                average_annual_loss_retrofitted=20.5,
            ),
            BCR_NODE(
                asset_ref="asset_2",
                location=Point(1.0, 1.5),
                bcr=16.23,
                average_annual_loss_original=11.5,
                average_annual_loss_retrofitted=40.5,
            ),
            BCR_NODE(
                asset_ref="asset_3",
                location=Point(2.0, 2.5),
                bcr=17.23,
                average_annual_loss_original=12.5,
                average_annual_loss_retrofitted=10.5,
            ),
        ]

        writer.serialize(data)

        _utils.assert_xml_equal(expected, self.filename)
        self.assertTrue(_utils.validates_against_xml_schema(self.filename))
开发者ID:nastasi-oq,项目名称:oq-nrmllib,代码行数:56,代码来源:writers_test.py

示例9: test_serialize

    def test_serialize(self):
        try:
            _, path = tempfile.mkstemp()
            writer = writers.UHSXMLWriter(path, **self.metadata)

            writer.serialize(self.data)

            utils.assert_xml_equal(self.expected_xml, path)
        finally:
            os.unlink(path)
开发者ID:nastasi-oq,项目名称:oq-nrmllib,代码行数:10,代码来源:writers_test.py

示例10: test_serialize_an_insured_loss_curve

    def test_serialize_an_insured_loss_curve(self):
        expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml"
      xmlns="http://openquake.org/xmlns/nrml/0.4">
  <lossCurves  insured="True" investigationTime="10.0"
    sourceModelTreePath="b1_b2_b3" gsimTreePath="b1_b2" unit="USD">
    <lossCurve assetRef="asset_1">
      <gml:Point>
        <gml:pos>1.0 1.5</gml:pos>
      </gml:Point>
      <poEs>1.0 0.5 0.1</poEs>
      <losses>10.0 20.0 30.0</losses>
      <averageLoss>1.0000e+00</averageLoss>
      <stdDevLoss>5.0000e-01</stdDevLoss>
    </lossCurve>
    <lossCurve assetRef="asset_2">
      <gml:Point>
        <gml:pos>2.0 2.5</gml:pos>
      </gml:Point>
      <poEs>1.0 0.3 0.2</poEs>
      <losses>20.0 30.0 40.0</losses>
      <averageLoss>2.0000e+00</averageLoss>
      <stdDevLoss>1.0000e-01</stdDevLoss>
    </lossCurve>
  </lossCurves>
</nrml>
""")

        writer = writers.LossCurveXMLWriter(
            self.filename,
            investigation_time=10.0, source_model_tree_path="b1_b2_b3",
            gsim_tree_path="b1_b2", unit="USD", insured=True)

        data = [
            LOSS_CURVE(
                asset_ref="asset_1", location=Point(1.0, 1.5),
                poes=[1.0, 0.5, 0.1], losses=[10.0, 20.0, 30.0],
                loss_ratios=None, average_loss=1., stddev_loss=0.5),

            LOSS_CURVE(
                asset_ref="asset_2", location=Point(2.0, 2.5),
                poes=[1.0, 0.3, 0.2], losses=[20.0, 30.0, 40.0],
                loss_ratios=None, average_loss=2., stddev_loss=0.1),
        ]

        writer.serialize(data)

        _utils.assert_xml_equal(expected, self.filename)
        self.assertTrue(_utils.validates_against_xml_schema(self.filename))
开发者ID:MaksimEritov,项目名称:oq-nrmllib,代码行数:50,代码来源:writers_test.py

示例11: test_serialize_mean

    def test_serialize_mean(self):
        del self.metadata['smlt_path']
        del self.metadata['gsimlt_path']
        self.metadata['statistics'] = 'mean'

        try:
            _, path = tempfile.mkstemp()
            writer = writers.UHSXMLWriter(path, **self.metadata)

            writer.serialize(self.data)

            utils.assert_xml_equal(self.expected_mean_xml, path)
        finally:
            os.unlink(path)
开发者ID:nastasi-oq,项目名称:oq-nrmllib,代码行数:14,代码来源:writers_test.py

示例12: test_chain_parse_serialize

    def test_chain_parse_serialize(self):
        # Chain a parser together to with a serializer and test that the
        # produced XML is unchanged.
        for example in ('hazard-curves-mean.xml', 'hazard-curves-pga.xml',
                        'hazard-curves-quantile.xml', 'hazard-curves-sa.xml'):
            infile = os.path.join('tests/data', example)
            hcp = parsers.HazardCurveXMLParser(infile)
            parsed_model = hcp.parse()
            _, outfile = tempfile.mkstemp()
            try:
                hcw = writers.HazardCurveXMLWriter(
                    outfile, **parsed_model.metadata
                )
                hcw.serialize(parsed_model)

                _utils.assert_xml_equal(infile, outfile)
            finally:
                os.unlink(outfile)
开发者ID:MaksimEritov,项目名称:oq-nrmllib,代码行数:18,代码来源:parsers_test.py

示例13: test_serialize_taxonomies

    def test_serialize_taxonomies(self):
        expected = file(os.path.join(os.path.dirname(__file__), "../../examples/loss-fractions-taxonomies.xml"))

        writers.LossFractionsWriter(
            self.filename,
            "taxonomy",
            loss_unit="EUR",
            loss_category="building",
            hazard_metadata=HazardMetadata(
                investigation_time=50.0, statistics=None, quantile=None, sm_path="b1_b2_b4", gsim_path="b1_b2"
            ),
            poe=0.1,
        ).serialize(
            dict(RC=(400, 0.2), RM=(1600, 0.8)),
            {(0.0, 0.0): dict(RC=(200, 0.5), RM=(200, 0.5)), (1.0, 1.0): dict(RC=(200, 0.25), RM=(1400, 0.75))},
        )

        etree.XMLSchema(etree.parse(nrmllib.nrml_schema_file())).assert_(etree.parse(self.filename))
        _utils.assert_xml_equal(expected, self.filename)
开发者ID:nastasi-oq,项目名称:oq-nrmllib,代码行数:19,代码来源:writers_test.py

示例14: test_serialize_optional_metadata

    def test_serialize_optional_metadata(self):
        expected = StringIO.StringIO(
            """\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
  <bcrMap interestRate="10.0" assetLifeExpectancy="50.0" statistics="quantile" quantileValue="0.5" lossCategory="economic" unit="USD">
    <node>
      <gml:Point>
        <gml:pos>1.0 1.5</gml:pos>
      </gml:Point>
      <bcr assetRef="asset_1" ratio="15.23" aalOrig="10.5" aalRetr="20.5"/>
    </node>
  </bcrMap>
</nrml>
"""
        )

        writer = writers.BCRMapXMLWriter(
            self.filename,
            interest_rate=10.0,
            asset_life_expectancy=50.0,
            statistics="quantile",
            quantile_value=0.50,
            unit="USD",
            loss_category="economic",
        )

        data = [
            BCR_NODE(
                asset_ref="asset_1",
                location=Point(1.0, 1.5),
                bcr=15.23,
                average_annual_loss_original=10.5,
                average_annual_loss_retrofitted=20.5,
            )
        ]

        writer.serialize(data)

        _utils.assert_xml_equal(expected, self.filename)
        self.assertTrue(_utils.validates_against_xml_schema(self.filename))
开发者ID:nastasi-oq,项目名称:oq-nrmllib,代码行数:41,代码来源:writers_test.py

示例15: test_serialize_quantile

    def test_serialize_quantile(self):
        # Test serialization of qunatile curves.
        expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
  <hazardCurves statistics="quantile" quantileValue="0.15" IMT="SA" investigationTime="50.0" saPeriod="0.025" saDamping="5.0">
    <IMLs>0.005 0.007 0.0098</IMLs>
    <hazardCurve>
      <gml:Point>
        <gml:pos>38.0 -20.1</gml:pos>
      </gml:Point>
      <poEs>0.1 0.2 0.3</poEs>
    </hazardCurve>
    <hazardCurve>
      <gml:Point>
        <gml:pos>38.1 -20.2</gml:pos>
      </gml:Point>
      <poEs>0.4 0.5 0.6</poEs>
    </hazardCurve>
    <hazardCurve>
      <gml:Point>
        <gml:pos>38.2 -20.3</gml:pos>
      </gml:Point>
      <poEs>0.7 0.8 0.8</poEs>
    </hazardCurve>
  </hazardCurves>
</nrml>
""")

        metadata = dict(
            investigation_time=self.TIME, imt='SA', imls=self.IMLS,
            sa_period=0.025, sa_damping=5.0, statistics='quantile',
            quantile_value=0.15
        )
        writer = writers.HazardCurveXMLWriter(self.path, **metadata)
        writer.serialize(self.data)

        utils.assert_xml_equal(expected, self.path)
        self.assertTrue(utils.validates_against_xml_schema(self.path))
开发者ID:nastasi-oq,项目名称:oq-nrmllib,代码行数:39,代码来源:writers_test.py


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