|
28 | 28 | import copy |
29 | 29 | import numpy as np |
30 | 30 | import esutil |
| 31 | +import os |
| 32 | +import requests |
31 | 33 |
|
32 | 34 | import lsst.afw.image as afwImage |
33 | 35 | import lsst.afw.math as afwMath |
|
44 | 46 | import lsst.pipe.base.testUtils |
45 | 47 | from lsst.pipe.tasks.calibrateImage import CalibrateImageTask, \ |
46 | 48 | NoPsfStarsToStarsMatchError, AllCentroidsFlaggedError |
| 49 | +import lsst.pex.config as pexConfig |
47 | 50 | import lsst.utils.tests |
48 | 51 |
|
49 | 52 |
|
@@ -120,6 +123,7 @@ def setUp(self): |
120 | 123 | # We don't have many test points, so can't match on complicated shapes. |
121 | 124 | self.config.astrometry.sourceSelector["science"].flags.good = [] |
122 | 125 | self.config.astrometry.matcher.numPointsForShape = 3 |
| 126 | + self.config.run_sattle = False |
123 | 127 | # ApFlux has more noise than PsfFlux (the latter unrealistically small |
124 | 128 | # in this test data), so we need to do magnitude rejection at higher |
125 | 129 | # sigma, otherwise we can lose otherwise good sources. |
@@ -584,6 +588,42 @@ def test_calibrate_image_illumcorr(self): |
584 | 588 | self.assertIn(key, result.exposure.metadata) |
585 | 589 | self.assertEqual(result.exposure.metadata[key], True) |
586 | 590 |
|
| 591 | + @mock.patch.dict(os.environ, {"SATTLE_URI_BASE": ""}) |
| 592 | + def test_fail_on_sattle_miconfiguration(self): |
| 593 | + """Test for failure if sattle is requested without appropriate configurations. |
| 594 | + """ |
| 595 | + self.config.run_sattle = True |
| 596 | + with self.assertRaises(pexConfig.FieldValidationError): |
| 597 | + CalibrateImageTask(config=self.config) |
| 598 | + |
| 599 | + @mock.patch.dict(os.environ, {"SATTLE_URI_BASE": "fake_host:1234"}) |
| 600 | + def test_continue_on_sattle_failure(self): |
| 601 | + """Processing should continue when sattle returns status codes other than 200. |
| 602 | + """ |
| 603 | + response = MockResponse({}, 500, "internal sattle error") |
| 604 | + |
| 605 | + self.config.run_sattle = True |
| 606 | + calibrate = CalibrateImageTask(config=self.config) |
| 607 | + calibrate.astrometry.setRefObjLoader(self.ref_loader) |
| 608 | + calibrate.photometry.match.setRefObjLoader(self.ref_loader) |
| 609 | + with mock.patch('requests.put', return_value=response) as mock_put: |
| 610 | + calibrate.run(exposures=self.exposure) |
| 611 | + mock_put.assert_called_once() |
| 612 | + |
| 613 | + @mock.patch.dict(os.environ, {"SATTLE_URI_BASE": "fake_host:1234"}) |
| 614 | + def test_sattle(self): |
| 615 | + """Test for successful completion when sattle call returns successfully. |
| 616 | + """ |
| 617 | + response = MockResponse({}, 200, "success") |
| 618 | + |
| 619 | + self.config.run_sattle = True |
| 620 | + calibrate = CalibrateImageTask(config=self.config) |
| 621 | + calibrate.astrometry.setRefObjLoader(self.ref_loader) |
| 622 | + calibrate.photometry.match.setRefObjLoader(self.ref_loader) |
| 623 | + with mock.patch('requests.put', return_value=response) as mock_put: |
| 624 | + calibrate.run(exposures=self.exposure) |
| 625 | + mock_put.assert_called_once() |
| 626 | + |
587 | 627 |
|
588 | 628 | class CalibrateImageTaskRunQuantumTests(lsst.utils.tests.TestCase): |
589 | 629 | """Tests of ``CalibrateImageTask.runQuantum``, which need a test butler, |
@@ -955,6 +995,21 @@ def mock_run( |
955 | 995 | self.butler.get("initial_stars_footprints_detector", self.visit_id) |
956 | 996 |
|
957 | 997 |
|
| 998 | +class MockResponse: |
| 999 | + """Provide a mock for requests.put calls""" |
| 1000 | + def __init__(self, json_data, status_code, text): |
| 1001 | + self.json_data = json_data |
| 1002 | + self.status_code = status_code |
| 1003 | + self.text = text |
| 1004 | + |
| 1005 | + def json(self): |
| 1006 | + return self.json_data |
| 1007 | + |
| 1008 | + def raise_for_status(self): |
| 1009 | + if self.status_code != 200: |
| 1010 | + raise requests.exceptions.HTTPError |
| 1011 | + |
| 1012 | + |
958 | 1013 | def setup_module(module): |
959 | 1014 | lsst.utils.tests.init() |
960 | 1015 |
|
|
0 commit comments