Skip to content
Snippets Groups Projects
Commit 70898457 authored by Corné Lukken's avatar Corné Lukken
Browse files

L2SS-572: Raise exceptions instead of using assert

parent 909640a2
No related branches found
No related tags found
1 merge request!396Resolve L2SS-572 "Refactor delays"
......@@ -14,8 +14,8 @@ class Delays:
measure = casacore.measures.measures()
frame_location = measure.position("ITRF", *[f"{x}m" for x in itrf])
result = measure.do_frame(frame_location)
assert result == True , f"measure.do_frame failed for ITRF location {itrf}"
if not measure.do_frame(frame_location):
raise ValueError(f"measure.do_frame failed for ITRF location {itrf}")
self.reference_itrf = itrf
self.measure = measure
......@@ -26,8 +26,8 @@ class Delays:
utc_time_str = utc_time.isoformat(' ')
frame_time = self.measure.epoch("UTC", utc_time_str)
result = self.measure.do_frame(frame_time)
assert result == True , f"measure.do_frame failed for UTC time {utc_time_str}"
if not self.measure.do_frame(frame_time):
raise ValueError(f"measure.do_frame failed for UTC time {utc_time_str}")
def get_direction_vector(self, pointing: numpy.ndarray) -> numpy.ndarray:
""" Compute direction vector for a given pointing, relative to the measure. """
......
import datetime
import time
import logging
import mock
import numpy
import numpy.testing
import casacore
from tangostationcontrol.beam.delays import Delays
from tangostationcontrol.test import base
......@@ -10,15 +13,21 @@ from tangostationcontrol.test import base
class TestDelays(base.TestCase):
def test_init(self):
"""
Fail condition is simply the object creation failing
"""
"""Fail condition is simply the object creation failing"""
reference_itrf = [3826577.066, 461022.948, 5064892.786] # CS002LBA, in ITRF2005 epoch 2012.5
d = Delays(reference_itrf)
self.assertIsNotNone(d)
def test_init_fails(self):
"""Test do_measure returning false is correctly caught"""
with mock.patch.object(casacore.measures, "measures") as m_measure:
m_measure.return_value.do_frame.return_value = False
self.assertRaises(ValueError, Delays, [0, 0, 0])
def test_is_valid_direction(self):
d = Delays([0, 0, 0])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment