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 unittest
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
class DopplerTrackingTest(unittest.TestCase):
def setUp(self):
telescope_patch = patch('telescope.telescope')
self.telescope_mock = telescope_mock.start()
self.addCleanUp(telescope_patcher.stop)
local_oscillator_patch = patch('camrasdevices.LocalOscillator')
self.local_oscillator_mock = local_oscillator_patch.start()
self.addCleanUp(local_oscillator_patcher.stop)
def test_something(self):
pass
class DummyTelescope():
def __init__(self):
fake_pointing = SkyCoord(ra=0.*u.deg, dec=31.*u.deg)
self.radec = fake_pointing
pass
def getJ2000(self):
for i in range(3):
yield {'radec': self.radec}
class DummyLocalOscillator(object):
def __init__(self):
self._frequency = 0
pass
@property
def frequency(self):
return self._frequency
@frequency.setter
def frequency(self, freq):
self._frequency = freq
print("Dummy LO set to 1GHz {:+.3f}".format((self._frequency-1*u.GHz).to(u.kHz)))
track_doppler.track_doppler(DummyTelescope(), DummyLocalOscillator())
#track_doppler.track_doppler(DummyTelescope(), DummyLocalOscillator(), doppler_function=doppler_frequency)
telescope_patcher = patch('telescope.telescope')
self.telescope_mock = telescope_patcher.start()
self.addCleanup(telescope_patcher.stop)
self.event_called = 0
local_oscillator_patcher = patch('camrasdevices.LocalOscillator')
self.local_oscillator_mock = local_oscillator_patcher.start()
self.addCleanup(local_oscillator_patcher.stop)
self.test_time = Time("2018-06-21T12:00:00", scale="utc", format="isot")
self.test_skycoord = SkyCoord(ra=0. * u.deg, dec=31. * u.deg)
self.test_location = EarthLocation.from_geodetic(lat=52 * u.deg, lon=6 * u.deg, height=0 * u.m)
self.telescope_mock.radec = self.test_skycoord
@mock.patch('subprocess.Popen')
def test_doppler_harm_mb(self, mock_subproc_popen):
track_doppler.doppler_harm_mb(self.test_skycoord,
self.test_time,
track_doppler.freq_hi,
self.test_location)
command = '/home/harm/bin/doppler_mb 0.0 0.5410520681182421 2000 1529582400.0 0.9075712110370514 0.1047197551196598 7.75077158168676e-10 1420.405751'
self.assertTrue(mock_subproc_popen.called_with(call(command, shell=True, stdout=-1)))
@mock.patch('subprocess.Popen')
def test_doppler_harm_bl(self, mock_subproc_popen):
track_doppler.doppler_harm_bl(self.test_skycoord,
self.test_time,
track_doppler.freq_hi,
self.test_location)
command = '/home/harm/bin/doppler_bl 0.0 0.5410520681182421 2000 1529582400.0 0.9075712110370514 0.1047197551196598 7.75077158168676e-10 1420.405751'
self.assertTrue(mock_subproc_popen.called_with(call(command, shell=True, stdout=-1)))
def test_track_doppler(self):
exit_event = threading.Event()
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__':
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