def test_pre_execute(self): # Simply tests that `pre_execute` calls `write_uh_spectra`. # That's all for now. calc = UHSCalculator(self.job_ctxt) with helpers.patch( '%s.write_uh_spectra' % self.UHS_CORE_MODULE) as write_mock: calc.pre_execute() self.assertEqual(1, write_mock.call_count)
def test_post_execute(self): calc = UHSCalculator(self.job_ctxt) expected_call_args = ((self.job_id,), {}) with helpers.patch( 'openquake.utils.stats.delete_job_counters') as del_mock: calc.post_execute() self.assertEqual(1, del_mock.call_count) self.assertEqual(expected_call_args, del_mock.call_args)
def test_initialize(self): # Test that `initialize` sets the task total counter with the correct # value # First, check that the total counter doesn't exist. task_total = lambda: stats.get_counter( self.job_id, 'h', 'uhs:tasks', 't') self.assertIsNone(task_total()) calc = UHSCalculator(self.job_ctxt) calc.initialize() # In this test file, there is only 1 realization and 1 site. # So, the expected total is 1. self.assertEqual(1, task_total())