def test_celery_task(self): # Test that the celery task when called properly call the # specific method to write loss curves base_path = 'openquake.engine.calculators.risk.writers' patches = [ helpers.patch('%s.loss_curve' % base_path), helpers.patch('%s.event_loss_curve' % base_path) ] try: mocked_loss_writer, mocked_event_loss_writer = [ p.start() for p in patches ] event_based.event_based(*self.calculator.task_arg_gen( self.calculator.block_size()).next()) # we expect 1 asset being filtered out by the region # constraint, so there are only four loss curves (2 of them # are insured) to be written self.assertEqual(0, mocked_loss_writer.call_count) self.assertEqual(2, mocked_event_loss_writer.call_count) finally: [p.stop() for p in patches]
def test_celery_task(self): # Test that the celery task when called properly call the # specific method to write loss curves base_path = "openquake.engine.calculators.risk.writers" patch = helpers.patch("%s.loss_curve" % base_path) mocked_loss_writer = patch.start() event_based.event_based(*self.calculator.task_arg_gen(self.calculator.block_size()).next()) # we expect 1 asset being filtered out by the region # constraint, so there are only four loss curves (2 of them # are insured) to be written self.assertEqual(2, mocked_loss_writer.call_count) patch.stop()
def test_celery_task(self): # Test that the celery task when called properly call the # specific method to write loss curves base_path = 'openquake.engine.calculators.risk.writers' patches = [ helpers.patch('%s.loss_curve' % base_path), helpers.patch('%s.event_loss_curve' % base_path)] try: mocked_loss_writer, mocked_event_loss_writer = [ p.start() for p in patches] event_based.event_based( *self.calculator.task_arg_gen().next()) # we expect 1 asset being filtered out by the region # constraint, so there are only four loss curves (2 of them # are insured) to be written self.assertEqual(0, mocked_loss_writer.call_count) self.assertEqual(2, mocked_event_loss_writer.call_count) finally: [p.stop() for p in patches]
def test_celery_task(self): # Test that the celery task when called properly call the # specific method to write loss curves patches = [helpers.patch(x) for x in [ 'openquake.engine.calculators.risk.general.write_loss_curve', 'openquake.engine.calculators.risk.general.\ update_aggregate_losses']] mocked_loss_writer = patches[0].start() mocked_agg_loss_writer = patches[1].start() event_based.event_based( *self.calculator.task_arg_gen(self.calculator.block_size()).next()) patches[0].stop() patches[1].stop() # we expect 1 asset being filtered out by the region # constraint, so there are only four loss curves (2 of them # are insured) to be written self.assertEqual(2, mocked_loss_writer.call_count) self.assertEqual(1, mocked_agg_loss_writer.call_count)