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


Python helpers.deep_eq函数代码示例

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


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

示例1: test_invalid_disagg_calc

    def test_invalid_disagg_calc(self):
        expected_errors = {
            'mag_bin_width': ['Magnitude bin width must be > 0.0'],
            'distance_bin_width': ['Distance bin width must be > 0.0'],
            'coordinate_bin_width': ['Coordinate bin width must be > 0.0'],
            'num_epsilon_bins': ['Number of epsilon bins must be > 0'],
            'truncation_level': ['Truncation level must be > 0 for'
                                 ' disaggregation calculations'],
            'poes_disagg': ['PoEs for disaggregation must be in the range'
                            ' [0, 1]'],
        }

        self.hc.mag_bin_width = 0.0
        self.hc.distance_bin_width = 0.0
        self.hc.coordinate_bin_width = 0.0  # decimal degrees
        self.hc.num_epsilon_bins = 0
        self.hc.poes_disagg = [1.00001, -0.5, 0.0]
        self.hc.truncation_level = 0.0

        form = validation.DisaggHazardForm(instance=self.hc, files=None)

        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)

        # test with an empty `poes_disagg` list
        self.hc.poes_disagg = []
        form = validation.DisaggHazardForm(instance=self.hc, files=None)
        expected_errors['poes_disagg'] = [(
            '`poes_disagg` must contain at least 1 value')]
        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)
开发者ID:Chunghan,项目名称:oq-engine,代码行数:33,代码来源:validation_test.py

示例2: test_invalid_disagg_calc

    def test_invalid_disagg_calc(self):
        expected_errors = {
            'mag_bin_width': ['Magnitude bin width must be > 0.0'],
            'distance_bin_width': ['Distance bin width must be > 0.0'],
            'coordinate_bin_width': ['Coordinate bin width must be > 0.0'],
            'num_epsilon_bins': ['Number of epsilon bins must be > 0'],
            'truncation_level': ['Truncation level must be > 0 for'
                                 ' disaggregation calculations'],
            'poes_disagg': ['PoEs for disaggregation must be in the range'
                            ' [0, 1]'],
        }

        hc = models.HazardCalculation(
            owner=helpers.default_user(),
            description='',
            sites='MULTIPOINT((-122.114 38.113))',
            calculation_mode='disaggregation',
            random_seed=37,
            number_of_logic_tree_samples=1,
            rupture_mesh_spacing=0.001,
            width_of_mfd_bin=0.001,
            area_source_discretization=0.001,
            reference_vs30_value=0.001,
            reference_vs30_type='measured',
            reference_depth_to_2pt5km_per_sec=0.001,
            reference_depth_to_1pt0km_per_sec=0.001,
            investigation_time=1.0,
            intensity_measure_types_and_levels=VALID_IML_IMT_STR,
            truncation_level=0.0,
            maximum_distance=100.0,
            mag_bin_width=0.0,
            distance_bin_width=0.0,
            coordinate_bin_width=0.0,  # decimal degrees
            num_epsilon_bins=0,
            poes_disagg=[1.00001, -0.5, 0.0],
        )
        form = validation.DisaggHazardForm(instance=hc, files=None)

        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)

        # test with an empty `poes_disagg` list
        hc.poes_disagg = []
        form = validation.DisaggHazardForm(instance=hc, files=None)
        expected_errors['poes_disagg'] = [(
            '`poes_disagg` must contain at least 1 value')]
        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)
开发者ID:4x,项目名称:oq-engine,代码行数:50,代码来源:validation_test.py

示例3: test_invalid_scenario_calc

    def test_invalid_scenario_calc(self):
        expected_errors = {
            'gsim': ["The gsim u'BooreAtkinson208' is not in in \
openquake.hazardlib.gsim"],
            'number_of_ground_motion_fields': [
                'The number_of_ground_motion_fields must be a positive '
                'integer, got -10']
        }

        hc = models.HazardCalculation(
            owner=helpers.default_user(),
            description='',
            sites='MULTIPOINT((-122.114 38.113))',
            calculation_mode='scenario',
            random_seed=37,
            rupture_mesh_spacing=0.001,
            reference_vs30_value=0.001,
            reference_vs30_type='measured',
            reference_depth_to_2pt5km_per_sec=0.001,
            reference_depth_to_1pt0km_per_sec=0.001,
            intensity_measure_types=VALID_IML_IMT.keys(),
            truncation_level=0.1,
            maximum_distance=100.0,
            gsim='BooreAtkinson208',
            ground_motion_correlation_model='JB2009',
            number_of_ground_motion_fields=-10,
        )
        form = validation.ScenarioHazardForm(
            instance=hc, files=None
        )

        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)
开发者ID:4x,项目名称:oq-engine,代码行数:34,代码来源:validation_test.py

示例4: test_complete_logic_tree_gmf_iter

    def test_complete_logic_tree_gmf_iter(self):
        job = models.OqJob.objects.latest('id')
        # Test data:
        td = gmf_set_iter_test_data

        exp_gmfs = itertools.chain(
            td.GMFS_GMF_SET_0, td.GMFS_GMF_SET_1, td.GMFS_GMF_SET_2,
            td.GMFS_GMF_SET_3, td.GMFS_GMF_SET_4, td.GMFS_GMF_SET_5)
        exp_gmf_set = FakeGmfSet(complete_logic_tree_gmf=True,
                                 ses_ordinal=None,
                                 investigation_time=60.0,
                                 gmfs=exp_gmfs)

        [act_gmf_set] = models.GmfSet.objects\
            .filter(gmf_collection__output__oq_job=job.id,
                    gmf_collection__lt_realization__isnull=True)\
            .order_by('id')

        self.assertEqual(len(list(exp_gmf_set)), len(list(act_gmf_set)))

        self.assertEqual(exp_gmf_set.complete_logic_tree_gmf,
                         act_gmf_set.complete_logic_tree_gmf)
        self.assertEqual(exp_gmf_set.ses_ordinal, act_gmf_set.ses_ordinal)
        self.assertEqual(exp_gmf_set.investigation_time,
                         act_gmf_set.investigation_time)

        for i, exp_gmf in enumerate(exp_gmf_set):
            act_gmf = list(act_gmf_set)[i]

            equal, error = helpers.deep_eq(exp_gmf, act_gmf)

            self.assertTrue(equal, error)
开发者ID:matley,项目名称:oq-engine,代码行数:32,代码来源:models_test.py

示例5: test_iter

    def test_iter(self):
        # Test data
        td = gmf_set_iter_test_data

        exp_gmf_sets = [
            FakeGmfSet(complete_logic_tree_gmf=False, ses_ordinal=1, investigation_time=10.0, gmfs=td.GMFS_GMF_SET_0),
            FakeGmfSet(complete_logic_tree_gmf=False, ses_ordinal=2, investigation_time=10.0, gmfs=td.GMFS_GMF_SET_1),
            FakeGmfSet(complete_logic_tree_gmf=False, ses_ordinal=3, investigation_time=10.0, gmfs=td.GMFS_GMF_SET_2),
            FakeGmfSet(complete_logic_tree_gmf=False, ses_ordinal=1, investigation_time=10.0, gmfs=td.GMFS_GMF_SET_3),
            FakeGmfSet(complete_logic_tree_gmf=False, ses_ordinal=2, investigation_time=10.0, gmfs=td.GMFS_GMF_SET_4),
            FakeGmfSet(complete_logic_tree_gmf=False, ses_ordinal=3, investigation_time=10.0, gmfs=td.GMFS_GMF_SET_5),
        ]

        job = models.OqJob.objects.latest("id")

        gmf_sets = models.GmfSet.objects.filter(
            gmf_collection__output__oq_job=job.id, gmf_collection__lt_realization__isnull=False
        ).order_by("gmf_collection", "ses_ordinal")

        for i, exp_gmf_set in enumerate(exp_gmf_sets):
            act_gmf_set = gmf_sets[i]
            self.assertEqual(exp_gmf_set.complete_logic_tree_gmf, act_gmf_set.complete_logic_tree_gmf)
            self.assertEqual(exp_gmf_set.ses_ordinal, act_gmf_set.ses_ordinal)
            self.assertEqual(exp_gmf_set.investigation_time, act_gmf_set.investigation_time)

            for j, exp_gmf in enumerate(exp_gmf_set):
                act_gmf = list(act_gmf_set)[j]

                equal, error = helpers.deep_eq(exp_gmf, act_gmf)

                self.assertTrue(equal, error)
开发者ID:gvallarelli,项目名称:oq-engine,代码行数:31,代码来源:models_test.py

示例6: test_serialize

    def test_serialize(self):
        parser = nrml_parsers.SourceModelParser(MIXED_SRC_MODEL)
        source_model = parser.parse()

        inp = models.Input(
            owner=helpers.default_user(),
            digest='fake',
            path='fake',
            input_type='source',
            size=0
        )
        inp.save()

        db_writer = source_input.SourceDBWriter(
            inp, source_model, MESH_SPACING, BIN_WIDTH, AREA_SRC_DISC
        )
        db_writer.serialize()

        # Check that everything was saved properly.

        # First, check the Input:
        # refresh the record
        [inp] = models.Input.objects.filter(id=inp.id)
        self.assertEquals(source_model.name, inp.name)

        # re-reparse the test file for comparisons:
        nrml_sources = list(
            nrml_parsers.SourceModelParser(MIXED_SRC_MODEL).parse()
        )

        parsed_sources = list(models.ParsedSource.objects.filter(input=inp.id))

        # compare pristine nrml sources to those stored in pickled form in the
        # database (by unpickling them first, of course):
        for i, ns in enumerate(nrml_sources):
            self.assertTrue(*helpers.deep_eq(ns, parsed_sources[i].nrml))

        # now check that the ParsedSource geometry is correct
        # it should be the same as the 'rupture-enclosing' geometry for the
        # nhlib representation of each source
        for i, (ns, ps) in enumerate(zip(nrml_sources, parsed_sources)):
            nhlib_src = source_input.nrml_to_nhlib(
                ns, MESH_SPACING, BIN_WIDTH, AREA_SRC_DISC
            )

            nhlib_poly = nhlib_src.get_rupture_enclosing_polygon()
            # nhlib tests the generation of wkt from a polygon, so we can trust
            # that it is well-formed.

            # Since we save the rupture enclosing polygon as geometry (not wkt)
            # in the database, the WKT we get back from the DB might have
            # slightly different coordinate values (a difference in precision).
            # shapely can help us compare two polygons (generated from wkt)
            # at a specific level of precision (default=6 digits after the
            # decimal point).
            expected_poly = wkt.loads(ps.polygon.wkt)
            actual_poly = wkt.loads(nhlib_poly.wkt)

            self.assertTrue(expected_poly.almost_equals(actual_poly))
开发者ID:angri,项目名称:openquake,代码行数:59,代码来源:source_test.py

示例7: test_characteristic_multi

    def test_characteristic_multi(self):
        exp = self._expected_char_multi
        actual = source_input.nrml_to_hazardlib(
            self.char_multi, MESH_SPACING, BIN_WIDTH, AREA_SRC_DISC
        )

        eq, msg = helpers.deep_eq(exp, actual)

        self.assertTrue(eq, msg)
开发者ID:chenliu0831,项目名称:oq-engine,代码行数:9,代码来源:source_test.py

示例8: test_simple_to_hazardlib

    def test_simple_to_hazardlib(self):
        exp = self._expected_simple
        actual = source_input.nrml_to_hazardlib(
            self.simple, MESH_SPACING, BIN_WIDTH, AREA_SRC_DISC
        )

        eq, msg = helpers.deep_eq(exp, actual)

        self.assertTrue(eq, msg)
开发者ID:4x,项目名称:oq-engine,代码行数:9,代码来源:source_test.py

示例9: test_characteristic_complex

    def test_characteristic_complex(self):
        exp = self._expected_char_complex
        actual = source_input.nrml_to_hazardlib(
            self.char_complex, 10, BIN_WIDTH, AREA_SRC_DISC
        )

        eq, msg = helpers.deep_eq(exp, actual)

        self.assertTrue(eq, msg)
开发者ID:chenliu0831,项目名称:oq-engine,代码行数:9,代码来源:source_test.py

示例10: test_complex_to_nhlib

    def test_complex_to_nhlib(self):
        exp = self._expected_complex
        actual = source_input.nrml_to_nhlib(
            self.cmplx, MESH_SPACING, BIN_WIDTH, AREA_SRC_DISC
        )

        eq, msg = helpers.deep_eq(exp, actual)

        self.assertTrue(eq, msg)
开发者ID:angri,项目名称:openquake,代码行数:9,代码来源:source_test.py

示例11: test_hazard_curves_from_gmf_invalid_iml_imt

    def test_hazard_curves_from_gmf_invalid_iml_imt(self):
        # Test a configuration where the user has requested to post-process
        # GMFs into hazard curves.
        # In this case, the configuration has the required
        # `intensity_measure_types_and_levels`, but the IMTs are not a subset
        # of `intensity_measure_types`.
        expected_errors = {
            'intensity_measure_types_and_levels': [
                'Unknown IMT(s) [SA(0)] in `intensity_measure_types`'],
        }
        iml_imt = VALID_IML_IMT.keys()
        iml_imt.pop()

        hc = models.HazardCalculation(
            owner=helpers.default_user(),
            description='',
            region=(
                'POLYGON((-122.0 38.113, -122.114 38.113, -122.57 38.111, '
                '-122.0 38.113))'
            ),
            region_grid_spacing=0.001,
            calculation_mode='event_based',
            random_seed=37,
            number_of_logic_tree_samples=1,
            rupture_mesh_spacing=0.001,
            width_of_mfd_bin=0.001,
            area_source_discretization=0.001,
            reference_vs30_value=0.001,
            reference_vs30_type='measured',
            reference_depth_to_2pt5km_per_sec=0.001,
            reference_depth_to_1pt0km_per_sec=0.001,
            investigation_time=1.0,
            intensity_measure_types=iml_imt,
            intensity_measure_types_and_levels=VALID_IML_IMT,
            truncation_level=0.0,
            maximum_distance=100.0,
            ses_per_logic_tree_path=5,
            ground_motion_correlation_model='JB2009',
            ground_motion_correlation_params={"vs30_clustering": True},
            complete_logic_tree_ses=False,
            complete_logic_tree_gmf=True,
            ground_motion_fields=True,
            hazard_curves_from_gmfs=True,
        )
        form = validation.EventBasedHazardForm(
            instance=hc, files=None
        )

        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)
开发者ID:4x,项目名称:oq-engine,代码行数:51,代码来源:validation_test.py

示例12: test_invalid_disagg_calc_truncation_not_set

    def test_invalid_disagg_calc_truncation_not_set(self):
        expected_errors = {
            'mag_bin_width': ['Magnitude bin width must be > 0.0'],
            'distance_bin_width': ['Distance bin width must be > 0.0'],
            'coordinate_bin_width': ['Coordinate bin width must be > 0.0'],
            'num_epsilon_bins': ['Number of epsilon bins must be > 0'],
            'truncation_level': ['Truncation level must be set for'
                                 ' disaggregation calculations'],
            'poes_disagg': ['PoEs for disaggregation must be in the range'
                            ' [0, 1]'],
        }

        self.hc.truncation_level = None
        self.hc.mag_bin_width = 0.0
        self.hc.distance_bin_width = 0.0
        self.hc.coordinate_bin_width = 0.0  # decimal degrees
        self.hc.num_epsilon_bins = 0
        self.hc.poes_disagg = [1.00001, -0.5, 0.0]

        form = validation.DisaggHazardForm(instance=self.hc, files=None)

        self.assertFalse(form.is_valid())
        helpers.deep_eq(expected_errors, dict(form.errors))
开发者ID:Chunghan,项目名称:oq-engine,代码行数:23,代码来源:validation_test.py

示例13: test_hazard_calculation_is_not_valid_missing_grid_spacing

    def test_hazard_calculation_is_not_valid_missing_grid_spacing(self):
        expected_errors = {
            'region': ['`region` requires `region_grid_spacing`'],
        }

        self.hc.region_grid_spacing = None

        form = validation.ClassicalHazardForm(
            instance=self.hc, files=None
        )

        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)
开发者ID:Chunghan,项目名称:oq-engine,代码行数:14,代码来源:validation_test.py

示例14: test_hazard_calculation_is_not_valid_region_only

    def test_hazard_calculation_is_not_valid_region_only(self):
        expected_errors = {
            'region_grid_spacing': ['Region grid spacing must be > 0'],
            'region': [
                'Invalid region geomerty: Self-intersection[0 0]',
                'Region geometry can only be a single linear ring',
                'Longitude values must in the range [-180, 180]',
                'Latitude values must be in the range [-90, 90]'],
            'reference_vs30_value': ['Reference VS30 value must be > 0'],
            'reference_vs30_type': [
                'Reference VS30 type must be either "measured" or "inferred"',
            ],
            'reference_depth_to_1pt0km_per_sec': [
                'Reference depth to 1.0 km/sec must be > 0',
            ],
            'reference_depth_to_2pt5km_per_sec': [
                'Reference depth to 2.5 km/sec must be > 0',
            ],
        }

        hc = models.HazardCalculation(
            owner=helpers.default_user(),
            description='',
            region=(
                'POLYGON((-180.001 90.001, 180.001 -90.001, -179.001 -89.001, '
                '179.001 89.001, -180.001 90.001), (1 1, 2 2, 3 3, 4 4, 1 1))'
            ),
            region_grid_spacing=0,
            calculation_mode='classical',
            random_seed=2147483647,
            number_of_logic_tree_samples=1,
            rupture_mesh_spacing=1,
            width_of_mfd_bin=1,
            area_source_discretization=1,
            investigation_time=1,
            intensity_measure_types_and_levels=VALID_IML_IMT,
            truncation_level=0,
            maximum_distance=1,
            quantile_hazard_curves=[0.0, 0.1, 1.0],
            poes_hazard_maps=[1.0, 0.5, 0.0],
        )

        form = validation.ClassicalHazardForm(
            instance=hc, files=None
        )

        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)
开发者ID:4x,项目名称:oq-engine,代码行数:49,代码来源:validation_test.py

示例15: test_ses_per_logic_tree_path_is_not_valid

    def test_ses_per_logic_tree_path_is_not_valid(self):
        expected_errors = {
            'ses_per_logic_tree_path': [
                '`Stochastic Event Sets Per Sample` (ses_per_logic_tree_path) '
                'must be > 0'],
        }

        self.hc.ses_per_logic_tree_path = -1

        form = validation.EventBasedHazardForm(
            instance=self.hc, files=None
        )
        self.assertFalse(form.is_valid())
        equal, err = helpers.deep_eq(expected_errors, dict(form.errors))
        self.assertTrue(equal, err)
开发者ID:Chunghan,项目名称:oq-engine,代码行数:15,代码来源:validation_test.py


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