• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python _utils.assert_xml_equal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_serialize_complete_lt_ses

    def test_serialize_complete_lt_ses(self):
        ruptures = [
            SESRupture(1,
                5.5, 1.0, 40.0, 10.0, 'Active Shallow Crust',
                False, False,
                top_left_corner=(1.1, 1.01, 10.0),
                top_right_corner=(2.1, 2.01, 20.0),
                bottom_right_corner=(3.1, 3.01, 30.0),
                bottom_left_corner=(4.1, 4.01, 40.0)),
            SESRupture(2,
                6.5, 0.0, 41.0, 0.0, 'Active Shallow Crust',
                True, False,
                lons=[
                    [5.1, 6.1],
                    [7.1, 8.1],
                ],
                lats=[
                    [5.01, 6.01],
                    [7.01, 8.01],
                ],
                depths=[
                    [10.5, 10.6],
                    [10.7, 10.8],
                ]),
            SESRupture(3,
                5.4, 2.0, 42.0, 12.0, 'Stable Shallow Crust',
                False, False,
                top_left_corner=(1.1, 1.01, 10.0),
                top_right_corner=(2.1, 2.01, 20.0),
                bottom_right_corner=(3.1, 3.01, 30.0),
                bottom_left_corner=(4.1, 4.01, 40.0)),
            SESRupture(4,
                6.4, 3.0, 43.0, 13.0, 'Stable Shallow Crust',
                True, False,
                lons=[
                    [5.2, 6.2],
                    [7.2, 8.2],
                ],
                lats=[
                    [5.02, 6.02],
                    [7.02, 8.02],
                ],
                depths=[
                    [10.1, 10.2],
                    [10.3, 10.4],
                ]),

        ]
        complete_lt_ses = SES(1, 250.0, ruptures)

        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">
  <stochasticEventSet id="1" investigationTime="250.0">
    <rupture id="1" magnitude="5.5" strike="1.0" dip="40.0" rake="10.0" tectonicRegion="Active Shallow Crust">
      <planarSurface>
        <topLeft lon="1.1" lat="1.01" depth="10.0"/>
        <topRight lon="2.1" lat="2.01" depth="20.0"/>
        <bottomLeft lon="4.1" lat="4.01" depth="40.0"/>
        <bottomRight lon="3.1" lat="3.01" depth="30.0"/>
      </planarSurface>
    </rupture>
    <rupture id="2" magnitude="6.5" strike="0.0" dip="41.0" rake="0.0" tectonicRegion="Active Shallow Crust">
      <mesh rows="2" cols="2">
        <node row="0" col="0" lon="5.1" lat="5.01" depth="10.5"/>
        <node row="0" col="1" lon="6.1" lat="6.01" depth="10.6"/>
        <node row="1" col="0" lon="7.1" lat="7.01" depth="10.7"/>
        <node row="1" col="1" lon="8.1" lat="8.01" depth="10.8"/>
      </mesh>
    </rupture>
    <rupture id="3" magnitude="5.4" strike="2.0" dip="42.0" rake="12.0" tectonicRegion="Stable Shallow Crust">
      <planarSurface>
        <topLeft lon="1.1" lat="1.01" depth="10.0"/>
        <topRight lon="2.1" lat="2.01" depth="20.0"/>
        <bottomLeft lon="4.1" lat="4.01" depth="40.0"/>
        <bottomRight lon="3.1" lat="3.01" depth="30.0"/>
      </planarSurface>
    </rupture>
    <rupture id="4" magnitude="6.4" strike="3.0" dip="43.0" rake="13.0" tectonicRegion="Stable Shallow Crust">
      <mesh rows="2" cols="2">
        <node row="0" col="0" lon="5.2" lat="5.02" depth="10.1"/>
        <node row="0" col="1" lon="6.2" lat="6.02" depth="10.2"/>
        <node row="1" col="0" lon="7.2" lat="7.02" depth="10.3"/>
        <node row="1" col="1" lon="8.2" lat="8.02" depth="10.4"/>
      </mesh>
    </rupture>
  </stochasticEventSet>
</nrml>
""")

        try:
            _, path = tempfile.mkstemp()
            writer = writers.SESXMLWriter(path, None, None)
            writer.serialize([complete_lt_ses])

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


示例17: test_serialize_complete_lt_gmf

    def test_serialize_complete_lt_gmf(self):
        # Test data is:
        # - 1 gmf set
        # for each set:
        # - 2 ground motion fields
        # for each ground motion field:
        # - 2 nodes
        # Total nodes: 12
        locations = [Location(i * 0.1, i * 0.1) for i in xrange(12)]
        gmf_nodes = [GmfNode(i * 0.2, locations[i]) for i in xrange(12)]
        gmfs = [
            Gmf('SA', 0.1, 5.0, gmf_nodes[:2], 1),
            Gmf('SA', 0.2, 5.0, gmf_nodes[2:4], 2),
            Gmf('SA', 0.3, 5.0, gmf_nodes[4:6], 3),
            Gmf('PGA', None, None, gmf_nodes[6:8], 4),
            Gmf('PGA', None, None, gmf_nodes[8:10], 5),
            Gmf('PGA', None, None, gmf_nodes[10:], 6),
        ]
        gmf_set = GmfSet(gmfs, 350.0, 1)

        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">
  <gmfSet investigationTime="350.0" stochasticEventSetId="1">
    <gmf IMT="SA" saPeriod="0.1" saDamping="5.0" ruptureId="1">
      <node gmv="0.0" lon="0.0" lat="0.0"/>
      <node gmv="0.2" lon="0.1" lat="0.1"/>
    </gmf>
    <gmf IMT="SA" saPeriod="0.2" saDamping="5.0" ruptureId="2">
      <node gmv="0.4" lon="0.2" lat="0.2"/>
      <node gmv="0.6" lon="0.3" lat="0.3"/>
    </gmf>
    <gmf IMT="SA" saPeriod="0.3" saDamping="5.0" ruptureId="3">
      <node gmv="0.8" lon="0.4" lat="0.4"/>
      <node gmv="1.0" lon="0.5" lat="0.5"/>
    </gmf>
    <gmf IMT="PGA" ruptureId="4">
      <node gmv="1.2" lon="0.6" lat="0.6"/>
      <node gmv="1.4" lon="0.7" lat="0.7"/>
    </gmf>
    <gmf IMT="PGA" ruptureId="5">
      <node gmv="1.6" lon="0.8" lat="0.8"/>
      <node gmv="1.8" lon="0.9" lat="0.9"/>
    </gmf>
    <gmf IMT="PGA" ruptureId="6">
      <node gmv="2.0" lon="1.0" lat="1.0"/>
      <node gmv="2.2" lon="1.1" lat="1.1"/>
    </gmf>
  </gmfSet>
</nrml>
""")

        try:
            # Make a temp file to save the results to:
            _, path = tempfile.mkstemp()
            writer = writers.EventBasedGMFXMLWriter(
                path, None, None)
            writer.serialize([gmf_set])

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


示例18: test_serialize

    def test_serialize(self):
        # Test data is:
        # - 1 gmf collection
        # - 3 gmf sets
        # for each set:
        # - 2 ground motion fields
        # for each ground motion field:
        # - 2 nodes
        # Total nodes: 12
        locations = [Location(i * 0.1, i * 0.1) for i in xrange(12)]
        gmf_nodes = [GmfNode(i * 0.2, locations[i]) for i in xrange(12)]
        gmfs = [
            Gmf('SA', 0.1, 5.0, gmf_nodes[:2]),
            Gmf('SA', 0.2, 5.0, gmf_nodes[2:4]),
            Gmf('SA', 0.3, 5.0, gmf_nodes[4:6]),
            Gmf('PGA', None, None, gmf_nodes[6:8]),
            Gmf('PGA', None, None, gmf_nodes[8:10]),
            Gmf('PGA', None, None, gmf_nodes[10:]),
        ]
        gmf_sets = [
            GmfSet(gmfs[:2], 50.0),
            GmfSet(gmfs[2:4], 40.0),
            GmfSet(gmfs[4:], 30.0),
        ]
        gmf_collection = GmfCollection(gmf_sets)

        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">
  <gmfCollection sourceModelTreePath="b1_b2_b3" gsimTreePath="b1_b7_b15">
    <gmfSet investigationTime="50.0">
      <gmf IMT="SA" saPeriod="0.1" saDamping="5.0">
        <node iml="0.0" lon="0.0" lat="0.0"/>
        <node iml="0.2" lon="0.1" lat="0.1"/>
      </gmf>
      <gmf IMT="SA" saPeriod="0.2" saDamping="5.0">
        <node iml="0.4" lon="0.2" lat="0.2"/>
        <node iml="0.6" lon="0.3" lat="0.3"/>
      </gmf>
    </gmfSet>
    <gmfSet investigationTime="40.0">
      <gmf IMT="SA" saPeriod="0.3" saDamping="5.0">
        <node iml="0.8" lon="0.4" lat="0.4"/>
        <node iml="1.0" lon="0.5" lat="0.5"/>
      </gmf>
      <gmf IMT="PGA">
        <node iml="1.2" lon="0.6" lat="0.6"/>
        <node iml="1.4" lon="0.7" lat="0.7"/>
      </gmf>
    </gmfSet>
    <gmfSet investigationTime="30.0">
      <gmf IMT="PGA">
        <node iml="1.6" lon="0.8" lat="0.8"/>
        <node iml="1.8" lon="0.9" lat="0.9"/>
      </gmf>
      <gmf IMT="PGA">
        <node iml="2.0" lon="1.0" lat="1.0"/>
        <node iml="2.2" lon="1.1" lat="1.1"/>
      </gmf>
    </gmfSet>
  </gmfCollection>
</nrml>
""")

        sm_lt_path = 'b1_b2_b3'
        gsim_lt_path = 'b1_b7_b15'

        try:
            # Make a temp file to save the results to:
            _, path = tempfile.mkstemp()
            writer = writers.EventBasedGMFXMLWriter(
                path, sm_lt_path, gsim_lt_path)
            writer.serialize(gmf_collection)

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python _utils.create_pod函数代码示例发布时间:2022-05-27
下一篇:
Python _util.eq_函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap