Commit 4e72b5aa authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Add test for track_doppler

parent 1898dda3
import track_doppler import track_doppler
import unittest import unittest
from mock import call, patch from mock import call, patch
import astropy.units as u import mock
from vlsr import doppler_frequency from astropy.time import Time
import track_doppler
import threading
import astropy.units as u
from astropy.coordinates import SkyCoord from astropy.coordinates import SkyCoord, EarthLocation
import astropy.units as u import astropy.units as u
class DopplerTrackingTest(unittest.TestCase): class DopplerTrackingTest(unittest.TestCase):
def setUp(self): def setUp(self):
telescope_patch = patch('telescope.telescope') telescope_patcher = patch('telescope.telescope')
self.telescope_mock = telescope_mock.start() self.telescope_mock = telescope_patcher.start()
self.addCleanUp(telescope_patcher.stop) self.addCleanup(telescope_patcher.stop)
local_oscillator_patch = patch('camrasdevices.LocalOscillator') self.event_called = 0
self.local_oscillator_mock = local_oscillator_patch.start()
self.addCleanUp(local_oscillator_patcher.stop) local_oscillator_patcher = patch('camrasdevices.LocalOscillator')
self.local_oscillator_mock = local_oscillator_patcher.start()
def test_something(self): self.addCleanup(local_oscillator_patcher.stop)
pass
self.test_time = Time("2018-06-21T12:00:00", scale="utc", format="isot")
class DummyTelescope(): self.test_skycoord = SkyCoord(ra=0. * u.deg, dec=31. * u.deg)
def __init__(self): self.test_location = EarthLocation.from_geodetic(lat=52 * u.deg, lon=6 * u.deg, height=0 * u.m)
fake_pointing = SkyCoord(ra=0.*u.deg, dec=31.*u.deg)
self.radec = fake_pointing self.telescope_mock.radec = self.test_skycoord
pass
@mock.patch('subprocess.Popen')
def getJ2000(self): def test_doppler_harm_mb(self, mock_subproc_popen):
for i in range(3): track_doppler.doppler_harm_mb(self.test_skycoord,
yield {'radec': self.radec} self.test_time,
track_doppler.freq_hi,
class DummyLocalOscillator(object): self.test_location)
def __init__(self): command = '/home/harm/bin/doppler_mb 0.0 0.5410520681182421 2000 1529582400.0 0.9075712110370514 0.1047197551196598 7.75077158168676e-10 1420.405751'
self._frequency = 0 self.assertTrue(mock_subproc_popen.called_with(call(command, shell=True, stdout=-1)))
pass
@mock.patch('subprocess.Popen')
@property def test_doppler_harm_bl(self, mock_subproc_popen):
def frequency(self): track_doppler.doppler_harm_bl(self.test_skycoord,
return self._frequency self.test_time,
track_doppler.freq_hi,
@frequency.setter self.test_location)
def frequency(self, freq): command = '/home/harm/bin/doppler_bl 0.0 0.5410520681182421 2000 1529582400.0 0.9075712110370514 0.1047197551196598 7.75077158168676e-10 1420.405751'
self._frequency = freq self.assertTrue(mock_subproc_popen.called_with(call(command, shell=True, stdout=-1)))
print("Dummy LO set to 1GHz {:+.3f}".format((self._frequency-1*u.GHz).to(u.kHz)))
def test_track_doppler(self):
track_doppler.track_doppler(DummyTelescope(), DummyLocalOscillator()) exit_event = threading.Event()
#track_doppler.track_doppler(DummyTelescope(), DummyLocalOscillator(), doppler_function=doppler_frequency)
def three_times():
self.event_called += 1
return self.event_called >= 3
exit_event.is_set = three_times
track_doppler.track_doppler(self.telescope_mock, self.local_oscillator_mock,
exit_event=exit_event, timeout=0.)
print(self.local_oscillator_mock.mock_calls)
# track_doppler.track_doppler(DummyTelescope(), DummyLocalOscillator())
# track_doppler.track_doppler(DummyTelescope(), DummyLocalOscillator(), doppler_function=doppler_frequency)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment