Skip to content

Commit

Permalink
Fix floating point round tripping
Browse files Browse the repository at this point in the history
The schema is f32, so we have to use that in the test data to make it
round trip.
The assert in the test itself needs to be exact equality.
  • Loading branch information
parejkoj authored and bsmartradio committed Feb 28, 2024
1 parent 2393433 commit 2270892
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tests/test_packageAlerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,16 @@ def mock_alert(alert_id):
"band": 'g',
"ra": 12.5,
"dec": -16.9,
"x": 15.7,
"y": 89.8,
"apFlux": 54.85,
"apFluxErr": 70.0,
"snr": 6.7,
"psfFlux": 700.0,
"psfFluxErr": 90.0,
"flags": 0,
# These types are 32-bit floats in the avro schema, so we have to
# make them that type here, so that they round trip appropriately.
"x": np.float32(15.7),
"y": np.float32(89.8),
"apFlux": np.float32(54.85),
"apFluxErr": np.float32(70.0),
"snr": np.float32(6.7),
"psfFlux": np.float32(700.0),
"psfFluxErr": np.float32(90.0),
"flags": 12345,
}
}

Expand Down Expand Up @@ -527,8 +529,9 @@ def testRun_without_produce_or_write(self):
self.exposure,
self.exposure)

def test_serialize_alert_round_trip(self, **kwargs):

def test_serialize_alert_round_trip(self):
"""Test that values in the alert packet exactly round trip.
"""
ConfigClass = PackageAlertsConfig()
packageAlerts = PackageAlertsTask(config=ConfigClass)

Expand All @@ -537,7 +540,7 @@ def test_serialize_alert_round_trip(self, **kwargs):
deserialized = PackageAlertsTask._deserialize_alert(packageAlerts, serialized)

for field in alert['diaSource']:
self.assertAlmostEqual(alert['diaSource'][field], deserialized['diaSource'][field], places=5)
self.assertEqual(alert['diaSource'][field], deserialized['diaSource'][field])
self.assertEqual(1, deserialized["alertId"])


Expand Down

0 comments on commit 2270892

Please sign in to comment.