def test_compute_uhs_task_pi(self): # Test that progress indicators are working properly for # `compute_uhs_task`. # Mock out the two 'heavy' functions called by this task; # we don't need to do these and we don't want to waste the cycles. cmpt_uhs = '%s.%s' % (self.UHS_CORE_MODULE, 'compute_uhs') write_uhs_data = '%s.%s' % (self.UHS_CORE_MODULE, 'write_uhs_spectrum_data') with helpers.patch(cmpt_uhs): with helpers.patch(write_uhs_data): get_counter = lambda: stats.get_counter( self.job_id, 'h', 'compute_uhs_task', 'i') # First, check that the counter for `compute_uhs_task` is # `None`: self.assertIsNone(get_counter()) realization = 0 site = Site(0.0, 0.0) # execute the task as a plain old function compute_uhs_task(self.job_id, realization, site) self.assertEqual(1, get_counter()) compute_uhs_task(self.job_id, realization, site) self.assertEqual(2, get_counter())
def test_compute_uhs_task_pi(self): # Test that progress indicators are working properly for # `compute_uhs_task`. # Mock out the two 'heavy' functions called by this task; # we don't need to do these and we don't want to waste the cycles. cmpt_uhs = '%s.%s' % (self.UHS_CORE_MODULE, 'compute_uhs') write_uhs_data = '%s.%s' % (self.UHS_CORE_MODULE, 'write_uhs_spectrum_data') with helpers.patch(cmpt_uhs): with helpers.patch(write_uhs_data): get_counter = lambda: stats.get_counter( self.job_id, 'h', 'compute_uhs_task', 'i') # First, check that the counter for `compute_uhs_task` is # `None`: self.assertIsNone(get_counter()) realization = 0 site = Site(0.0, 0.0) # execute the task as a plain old function compute_uhs_task(self.job_id, realization, site) self.assertEqual(1, get_counter()) compute_uhs_task(self.job_id, realization, site) self.assertEqual(2, get_counter())
def test_compute_uhs_task_calls_compute_and_write(self): # The celery task `compute_uhs_task` basically just calls a few other # functions to do the calculation and write results. Those functions # have their own test coverage; in this test, we just want to make # sure they get called. cmpt_uhs = '%s.%s' % (self.UHS_CORE_MODULE, 'compute_uhs') write_uhs_data = '%s.%s' % (self.UHS_CORE_MODULE, 'write_uhs_spectrum_data') with helpers.patch(cmpt_uhs) as compute_mock: with helpers.patch(write_uhs_data) as write_mock: # Call the function under test as a normal function, not a # @task: compute_uhs_task(self.job_id, 0, Site(0.0, 0.0)) self.assertEqual(1, compute_mock.call_count) self.assertEqual(1, write_mock.call_count)
def test_compute_uhs_task_calls_compute_and_write(self): # The celery task `compute_uhs_task` basically just calls a few other # functions to do the calculation and write results. Those functions # have their own test coverage; in this test, we just want to make # sure they get called. cmpt_uhs = '%s.%s' % (self.UHS_CORE_MODULE, 'compute_uhs') write_uhs_data = '%s.%s' % (self.UHS_CORE_MODULE, 'write_uhs_spectrum_data') with helpers.patch(cmpt_uhs) as compute_mock: with helpers.patch(write_uhs_data) as write_mock: # Call the function under test as a normal function, not a # @task: compute_uhs_task(self.job_id, 0, Site(0.0, 0.0)) self.assertEqual(1, compute_mock.call_count) self.assertEqual(1, write_mock.call_count)