def test_occurrence_bin_doesnt_not_exist_event_set_isnt_specified___bin_is_copied_from_static( self): with TemporaryDirectory() as d: self.make_fake_bins(d) with io.open(os.path.join(d, 'static', 'occurrence.bin'), 'w', encoding='utf-8') as occurrence_file: occurrence_file.write('occurrence bin') occurrence_file.flush() settings = { "gul_summaries": [{ "lec_output": True, "leccalc": { "full_uncertainty_aep": True }, }] } prepare_run_inputs(settings, d) with io.open(os.path.join(d, 'input', 'occurrence.bin'), 'r', encoding='utf-8') as new_occurrence_file: self.assertEqual('occurrence bin', new_occurrence_file.read())
def test_occurrence_bin_doesnt_not_exist_event_set_is_specified___event_occurrence_id_specific_bin_is_copied_from_static( self): with TemporaryDirectory() as d: self.make_fake_bins(d) with io.open(os.path.join(d, 'static', 'occurrence_occurrence_id.bin'), 'w', encoding='utf-8') as occurrence_file: occurrence_file.write('occurrence occurrence id bin') occurrence_file.flush() settings = { "gul_summaries": [{ "lec_output": True }], 'model_settings': { 'event_occurrence_id': 'occurrence id' } } prepare_run_inputs(settings, d) with io.open(os.path.join(d, 'input', 'occurrence.bin'), 'r', encoding='utf-8') as new_occurrence_file: self.assertEqual('occurrence occurrence id bin', new_occurrence_file.read())
def test_no_events_bin_exists___oasis_exception_is_raised(self): with TemporaryDirectory() as d: self.make_fake_bins(d) os.remove(os.path.join(d, 'static', 'events.bin')) with self.assertRaises(OasisException): prepare_run_inputs({}, d)
def test_ord_returnperiods_bin_doesnt_not_exist_event_set_isnt_specified___bin_is_copied_from_static( self): with TemporaryDirectory() as d: self.make_fake_bins(d) with io.open(os.path.join(d, 'static', 'returnperiods.bin'), 'w', encoding='utf-8') as returnperiods_file: returnperiods_file.write('returnperiods bin') returnperiods_file.flush() settings = { "gul_summaries": [{ "ord_output": { "psept_oep": True }, }] } prepare_run_inputs(settings, d) with io.open(os.path.join(d, 'input', 'returnperiods.bin'), 'r', encoding='utf-8') as new_returnperiods_file: self.assertEqual('returnperiods bin', new_returnperiods_file.read())
def test_no_returnperiods_bin_exists___oasis_exception_is_raised(self): with TemporaryDirectory() as d: self.make_fake_bins(d) os.remove(os.path.join(d, 'static', 'returnperiods.bin')) with self.assertRaises(OasisException): settings = {"gul_summaries": [{"lec_output": True}]} prepare_run_inputs(settings, d)
def test_periods_bin_doesnt_not_exist_event_set_isnt_specified___bin_is_copied_from_static(self): with TemporaryDirectory() as d: self.make_fake_bins(d) with io_open(os.path.join(d, 'static', 'periods.bin'), 'w', encoding='utf-8') as periods_file: periods_file.write('periods bin') periods_file.flush() prepare_run_inputs({}, d) with io_open(os.path.join(d, 'input', 'periods.bin'), 'r', encoding='utf-8') as new_periods_file: self.assertEqual('periods bin', new_periods_file.read())
def test_periods_bin_already_exists___existing_bin_is_uncahnged(self): with TemporaryDirectory() as d: self.make_fake_bins(d) with io_open(os.path.join(d, 'input', 'periods.bin'), 'w', encoding='utf-8') as periods_file: periods_file.write('periods bin') periods_file.flush() prepare_run_inputs({}, d) with io_open(os.path.join(d, 'input', 'periods.bin'), 'r', encoding='utf-8') as new_periods_file: self.assertEqual('periods bin', new_periods_file.read())
def test_events_bin_doesnt_not_exist_event_set_is_specified___event_set_specific_bin_is_copied_from_static(self): with TemporaryDirectory() as d: self.make_fake_bins(d) with io_open(os.path.join(d, 'static', 'events_from_set.bin'), 'w', encoding='utf-8') as events_file: events_file.write('events from set bin') events_file.flush() prepare_run_inputs({'model_settings': {'event_set': 'from set'}}, d) with io_open(os.path.join(d, 'input', 'events.bin'), 'r', encoding='utf-8') as new_events_file: self.assertEqual('events from set bin', new_events_file.read())
def test_no_occurrence_bin_exists___oasis_exception_is_raised(self): with TemporaryDirectory() as d: self.make_fake_bins(d) os.remove(os.path.join(d, 'static', 'occurrence.bin')) with self.assertRaises(OasisException): settings = { "gul_summaries": [{ "eltcalc": True, "aalcalc": True, "pltcalc": True, "lec_output": True, }] } prepare_run_inputs(settings, d)
def test_periods_bin_already_exists___existing_bin_is_unchanged(self): with TemporaryDirectory() as d: self.make_fake_bins(d) with io.open(os.path.join(d, 'input', 'periods.bin'), 'w', encoding='utf-8') as periods_file: periods_file.write('periods bin') periods_file.flush() settings = { "gul_summaries": [{ "eltcalc": True, "aalcalc": True, "pltcalc": True, "lec_output": True, }] } prepare_run_inputs(settings, d) with io.open(os.path.join(d, 'input', 'periods.bin'), 'r', encoding='utf-8') as new_periods_file: self.assertEqual('periods bin', new_periods_file.read())
def test_prepare_input_bin_raises___oasis_exception_is_raised(self): with patch('oasislmf.model_execution.bin._prepare_input_bin', Mock(side_effect=OSError('os error'))): with self.assertRaises(OasisException): prepare_run_inputs({}, 'some_dir')