Browse Source

Improved pytests

master
Benito Marcote 8 months ago
parent
commit
c13aee0908
  1. 41
      tests/test_observation.py
  2. 14
      tests/test_stations.py

41
tests/test_observation.py

@ -0,0 +1,41 @@
import pytest
import configparser
from importlib import resources
import numpy as np
# from vlbiplanobs import stations
from vlbiplanobs import observation as obs
from astropy import coordinates as coord
from astropy import units as u
from astropy.time import Time
from astroplan import Observer, FixedTarget
def test_source():
"""Tests the Source class
"""
with pytest.raises(AssertionError):
obs.Source()
with pytest.raises(ValueError):
obs.Source('coordinates', 'a_name')
obs.Source('00h00m00s xxhqqmees', 'a_name')
obs.Source('40h00m00s 10d10m10s', 'a_name')
obs.Source('00:00:00 100:00:00', 'a_name')
obs.Source('-30:00:00 10:00:00', 'a_name')
obs.Source('WQQWE')
obs.Source('Cyg X-1')
with pytest.raises(coord.name_resolve.NameResolveError):
obs.Source(name='WQQWE')
s1 = obs.Source('10h20m10s 40d30m10s', 'a_name')
# s2 = obs.Source('10:20:10 40:30:10', 'a_name', unit=(u.hourangle, u.deg))
s3 = obs.Source(name='Cyg X-1')
assert s1.name == 'a_name'
# assert s2.name == 'a_name'
# assert s1.coordinates == s2.coordinates
assert s3.name == 'Cyg X-1'

14
tests/test_stations.py

@ -39,6 +39,19 @@ def test_station_functions():
sefds = {'18': 100, '6': 40, '0.1': 200}
a_station = stations.Station('name', 'Nm', 'VLBI',
coord.EarthLocation(3839348.973*u.m, 430403.51*u.m, 5057990.099*u.m), sefds, 20)
assert isinstance(a_station.name, str)
assert isinstance(a_station.fullname, str)
assert a_station.fullname == a_station.name
assert a_station.network == 'VLBI'
assert a_station.all_networks == a_station.network
assert isinstance(a_station.country, str)
assert isinstance(a_station.diameter, str)
assert isinstance(a_station.real_time, bool)
assert isinstance(a_station.location, coord.EarthLocation)
assert a_station.location == coord.EarthLocation(3839348.973*u.m, 430403.51*u.m, 5057990.099*u.m)
assert list(a_station.bands) == ['18', '6', '0.1']
assert isinstance(a_station.sefds, dict)
assert a_station.sefds == sefds
assert a_station.has_band('18')
assert not a_station.has_band('45')
assert a_station.sefd('18') == 100
@ -53,6 +66,7 @@ def test_station_functions():
assert len(a_station.is_visible(times1, src1)[0]) == 0
assert len(a_station.is_visible(times2, src1)[0]) == 10
assert len(a_station.elevation(times2, src1)) == len(times1)
assert np.equal(a_station.elevation(times2, src1).value, a_station.altaz(times2, src1).alt.value)[0]

Loading…
Cancel
Save