本文整理汇总了Python中tests.utils.helpers.default_user函数的典型用法代码示例。如果您正苦于以下问题:Python default_user函数的具体用法?Python default_user怎么用?Python default_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invalid_form
def test_invalid_form(self):
rc = models.RiskCalculation(
calculation_mode="event_based",
owner=helpers.default_user(),
region_constraint=(
'POLYGON((-122.0 38.113, -122.114 38.113, -122.57 38.111, '
'-122.0 38.113))'),
hazard_output=self.job.risk_calculation.hazard_output,
sites_disagg='-180.1 38.113, -122.114 38.113',
coordinate_bin_width=0.0,
loss_curve_resolution=0,
mag_bin_width=0.0,
)
expected_errors = {
'coordinate_bin_width': ['Coordinate bin width must be > 0.0'],
'distance_bin_width': ['Distance bin width must be > 0.0'],
'loss_curve_resolution': ['Loss Curve Resolution must be >= 1'],
'mag_bin_width': ['Magnitude bin width must be > 0.0'],
'sites_disagg': ['Longitude values must in the range [-180, 180]',
'disaggregation requires mag_bin_width, '
'coordinate_bin_width, distance_bin_width'],
}
form = validation.EventBasedRiskForm(
instance=rc, files=None)
self.assertFalse(form.is_valid())
self.assertEqual(expected_errors, dict(form.errors))
示例2: setUp
def setUp(self):
self.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='classical',
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,
truncation_level=0.0,
maximum_distance=100.0,
mean_hazard_curves=True,
quantile_hazard_curves=[0.0, 0.5, 1.0],
poes=[1.0, 0.5, 0.0],
)
示例3: test_hazard_calculation_is_valid_with_site_model
def test_hazard_calculation_is_valid_with_site_model(self):
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='classical',
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,
# The 4 `reference` parameters should be ignored since the site
# model file is specified.
# We can define invalid values here; the validator shouldn't care.
reference_vs30_value=0,
reference_vs30_type=None,
reference_depth_to_2pt5km_per_sec=0,
reference_depth_to_1pt0km_per_sec=0,
investigation_time=1.0,
intensity_measure_types_and_levels=VALID_IML_IMT,
truncation_level=0.0,
maximum_distance=100.0,
mean_hazard_curves=True,
quantile_hazard_curves=[0.0, 0.5, 1.0],
poes_hazard_maps=[1.0, 0.5, 0.0],
)
form = validation.ClassicalHazardForm(
instance=hc, files=dict(site_model_file=object())
)
self.assertTrue(form.is_valid(), dict(form.errors))
示例4: test_valid_disagg_calc
def test_valid_disagg_calc(self):
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.1,
maximum_distance=100.0,
mag_bin_width=0.3,
distance_bin_width=10.0,
coordinate_bin_width=0.02, # decimal degrees
num_epsilon_bins=4,
poes_disagg=[0.02, 0.1],
)
form = validation.DisaggHazardForm(
instance=hc, files=None
)
self.assertTrue(form.is_valid(), dict(form.errors))
示例5: test_hazard_calculation_is_valid_with_no_exports
def test_hazard_calculation_is_valid_with_no_exports(self):
# When the user does not specify '--exports' on the command line the
# 'export_dir' parameter needs not be present in the .ini file.
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='classical',
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,
truncation_level=0.0,
maximum_distance=100.0,
mean_hazard_curves=True,
quantile_hazard_curves=[0.0, 0.5, 1.0],
poes_hazard_maps=[1.0, 0.5, 0.0],
)
form = validation.ClassicalHazardForm(
instance=hc, files=None
)
self.assertTrue(form.is_valid())
示例6: setUpClass
def setUpClass(cls):
default_user = helpers.default_user()
cls.job = models.OqJob(owner=default_user)
cls.job.save()
# dmg dist per asset
cls.ddpa_output = models.Output(
owner=default_user, oq_job=cls.job,
display_name='Test dmg dist per asset',
output_type='dmg_dist_per_asset',
db_backed=True)
cls.ddpa_output.save()
cls.ddpa = models.DmgDistPerAsset(
output=cls.ddpa_output, dmg_states=cls.DMG_STATES)
cls.ddpa.save()
# We also need some sample exposure data records (to satisfy the dmg
# dist per asset FK).
test_input = models.Input(
owner=default_user, input_type='exposure', path='fake', size=0)
test_input.save()
i2j = models.Input2job(input=test_input, oq_job=cls.job)
i2j.save()
exp_model = models.ExposureModel(
owner=default_user, input=test_input, name='test-exp-model',
category='economic loss', stco_type='per_asset', stco_unit='CHF')
exp_model.save()
test_site = shapes.Site(3.14, 2.17)
cls.exp_data = models.ExposureData( # Asset
exposure_model=exp_model, asset_ref=helpers.random_string(),
taxonomy=helpers.random_string(), number_of_units=37,
site=test_site.point.to_wkt(), stco=1234.56)
cls.exp_data.save()
# dmg dist per taxonomy
cls.ddpt_output = models.Output(
owner=default_user, oq_job=cls.job,
display_name='Test dmg dist per taxonomy',
output_type='dmg_dist_per_taxonomy',
db_backed=True)
cls.ddpt_output.save()
cls.ddpt = models.DmgDistPerTaxonomy(
output=cls.ddpt_output, dmg_states=cls.DMG_STATES)
cls.ddpt.save()
# total dmg dist
cls.ddt_output = models.Output(
owner=default_user, oq_job=cls.job,
display_name='Test dmg dist total',
output_type='dmg_dist_total',
db_backed=True)
cls.ddt_output.save()
cls.ddt = models.DmgDistTotal(
output=cls.ddt_output, dmg_states=cls.DMG_STATES)
cls.ddt.save()
示例7: test_hazard_calculation_is_valid_region_only_as_str_list
def test_hazard_calculation_is_valid_region_only_as_str_list(self):
hc = models.HazardCalculation(
owner=helpers.default_user(),
description='',
region='-122.0, 38.113, -122.114, 38.113, -122.57, 38.111',
region_grid_spacing=0.001,
calculation_mode='classical',
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,
truncation_level=0.0,
maximum_distance=100.0,
mean_hazard_curves=True,
quantile_hazard_curves=[0.0, 0.5, 1.0],
poes_hazard_maps=[1.0, 0.5, 0.0],
)
form = validation.ClassicalHazardForm(
instance=hc, files=None
)
self.assertTrue(form.is_valid(), dict(form.errors))
示例8: 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)
示例9: test_hazard_calculation_is_not_valid_missing_geom
def test_hazard_calculation_is_not_valid_missing_geom(self):
expected_errors = {
'region': ['Must specify either `region` or `sites`.'],
'sites': ['Must specify either `region` or `sites`.'],
}
hc = models.HazardCalculation(
owner=helpers.default_user(),
description='',
calculation_mode='classical',
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,
truncation_level=0.0,
maximum_distance=100.0,
mean_hazard_curves=True,
quantile_hazard_curves=[0.0, 0.5, 1.0],
poes_hazard_maps=[1.0, 0.5, 0.0],
)
form = validation.ClassicalHazardForm(
instance=hc, files=None
)
self.assertFalse(form.is_valid())
self.assertEqual(expected_errors, dict(form.errors))
示例10: 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))
示例11: test_a_few_inputs
def test_a_few_inputs(self):
cfg = helpers.get_data_path('simple_fault_demo_hazard/job.ini')
params, files = engine.parse_config(open(cfg, 'r'))
owner = helpers.default_user()
hc = engine.create_hazard_calculation(
owner.user_name, params, files
)
inputs = models.inputs4hcalc(hc.id)
# We expect 3: the two logic trees and one source model
self.assertEqual(3, inputs.count())
示例12: test_valid_form_with_default_resolution
def test_valid_form_with_default_resolution(self):
rc = models.RiskCalculation(
calculation_mode="event_based",
owner=helpers.default_user(),
region_constraint=(
'POLYGON((-122.0 38.113, -122.114 38.113, -122.57 38.111, '
'-122.0 38.113))'),
hazard_output=self.job.risk_calculation.hazard_output)
form = validation.EventBasedRiskForm(
instance=rc, files=None)
self.assertTrue(form.is_valid(), dict(form.errors))
示例13: setUp
def setUp(self):
job, _ = helpers.get_risk_job('classical_psha_based_risk/job.ini',
'simple_fault_demo_hazard/job.ini')
self.compulsory_arguments = dict(
calculation_mode="classical",
lrem_steps_per_interval=5)
self.other_args = dict(
owner=helpers.default_user(),
region_constraint=(
'POLYGON((-122.0 38.113, -122.114 38.113, -122.57 38.111, '
'-122.0 38.113))'),
hazard_output=job.risk_calculation.hazard_output)
示例14: test_with_input_type
def test_with_input_type(self):
cfg = helpers.get_data_path('simple_fault_demo_hazard/job.ini')
params, files = engine.parse_config(open(cfg, 'r'))
owner = helpers.default_user()
hc = engine.create_hazard_calculation(
owner.user_name, params, files
)
inputs = models.inputs4hcalc(
hc.id, input_type='source_model_logic_tree'
)
self.assertEqual(1, inputs.count())
示例15: test_create_risk_calculation
def test_create_risk_calculation(self):
# we need an hazard output to create a risk calculation
hazard_cfg = helpers.get_data_path('simple_fault_demo_hazard/job.ini')
hazard_job = helpers.get_hazard_job(hazard_cfg, 'openquake')
hc = hazard_job.hazard_calculation
rlz = models.LtRealization.objects.create(
hazard_calculation=hazard_job.hazard_calculation,
ordinal=1, seed=1, weight=None,
sm_lt_path="test_sm", gsim_lt_path="test_gsim",
is_complete=False, total_items=1, completed_items=1)
hazard_output = models.HazardCurve.objects.create(
lt_realization=rlz,
output=models.Output.objects.create_output(
hazard_job, "Test Hazard output", "hazard_curve"),
investigation_time=hc.investigation_time,
imt="PGA", imls=[0.1, 0.2, 0.3])
params = {
'hazard_output_id': hazard_output.output.id,
'base_path': 'path/to/job.ini',
'export_dir': '/tmp/xxx',
'calculation_mode': 'classical',
# just some sample params
'lrem_steps_per_interval': 5,
'conditional_loss_poes': '0.01, 0.02, 0.05',
'region_constraint': '-0.5 0.5, 0.5 0.5, 0.5 -0.5, -0.5, -0.5',
}
owner = helpers.default_user()
vuln_file = models.Input(digest='123', path='/foo/bar', size=0,
input_type='structural_vulnerability',
owner=owner)
vuln_file.save()
exposure_file = models.Input(digest='456', path='/foo/baz', size=0,
input_type='exposure', owner=owner)
exposure_file.save()
files = [vuln_file, exposure_file]
rc = engine.create_risk_calculation(owner, params, files)
# Normalize/clean fields by fetching a fresh copy from the db.
rc = models.RiskCalculation.objects.get(id=rc.id)
self.assertEqual(rc.calculation_mode, 'classical')
self.assertEqual(rc.lrem_steps_per_interval, 5)
self.assertEqual(rc.conditional_loss_poes, [0.01, 0.02, 0.05])
self.assertEqual(
rc.region_constraint.wkt,
('POLYGON ((-0.5000000000000000 0.5000000000000000, '
'0.5000000000000000 0.5000000000000000, '
'0.5000000000000000 -0.5000000000000000, '
'-0.5000000000000000 -0.5000000000000000, '
'-0.5000000000000000 0.5000000000000000))'))