11# Licensed under a 3-clause BSD style license - see LICENSE.rst
22import pytest
3+ import shutil
4+ import tempfile
35
4- import astropy .coordinates as coord
6+ from astropy .coordinates import SkyCoord
57import astropy .units as u
68from astropy .table import Table
7- from ...utils .testing_tools import MockResponse
8- from ... import simbad
9+ from astroquery .utils .testing_tools import MockResponse
10+ from astroquery .simbad import Simbad
11+ # Maybe we need to expose SimbadVOTableResult to be in the public API?
12+ from astroquery .simbad .core import SimbadVOTableResult
913
1014
1115# M42 coordinates
12- ICRS_COORDS_M42 = coord . SkyCoord ("05h35m17.3s -05h23m28s" , frame = 'icrs' )
13- ICRS_COORDS_SgrB2 = coord . SkyCoord (266.835 * u .deg , - 28.38528 * u .deg , frame = 'icrs' )
14- multicoords = coord . SkyCoord ([ICRS_COORDS_M42 , ICRS_COORDS_SgrB2 ])
16+ ICRS_COORDS_M42 = SkyCoord ("05h35m17.3s -05h23m28s" , frame = 'icrs' )
17+ ICRS_COORDS_SgrB2 = SkyCoord (266.835 * u .deg , - 28.38528 * u .deg , frame = 'icrs' )
18+ multicoords = SkyCoord ([ICRS_COORDS_M42 , ICRS_COORDS_SgrB2 ])
1519
1620
1721@pytest .mark .remote_data
1822class TestSimbad :
1923
20- @classmethod
21- def setup_class ( cls ):
22- simbad . core . Simbad . ROW_LIMIT = 5
24+ @pytest . fixture ()
25+ def temp_dir ( self , request ):
26+ my_temp_dir = tempfile . mkdtemp ()
2327
24- def test_query_criteria1 (self ):
25- result = simbad .core .Simbad .query_criteria (
28+ def fin ():
29+ shutil .rmtree (my_temp_dir )
30+ request .addfinalizer (fin )
31+ return my_temp_dir
32+
33+ def test_query_criteria1 (self , temp_dir ):
34+ simbad = Simbad ()
35+ simbad .cache_location = temp_dir
36+ result = simbad .query_criteria (
2637 "region(box, GAL, 49.89 -0.3, 0.5d 0.5d)" , otype = 'HII' )
2738 assert isinstance (result , Table )
2839
29- def test_query_criteria2 (self ):
30- result = simbad .core .Simbad .query_criteria (otype = 'SNR' )
40+ def test_query_criteria2 (self , temp_dir ):
41+ simbad = Simbad ()
42+ simbad .cache_location = temp_dir
43+ result = simbad .query_criteria (otype = 'SNR' )
3144 assert isinstance (result , Table )
3245
33- def test_query_bibcode_async (self ):
34- response = simbad .core .Simbad .query_bibcode_async (
46+ def test_query_bibcode_async (self , temp_dir ):
47+ simbad = Simbad ()
48+ simbad .cache_location = temp_dir
49+ response = simbad .query_bibcode_async (
3550 '2006ApJ*' , wildcard = True )
3651 assert response is not None
3752 response .raise_for_status ()
@@ -43,76 +58,106 @@ def test_query_bibcode_async(self):
4358 assert not isinstance (response , MockResponse )
4459 assert not issubclass (response .__class__ , MockResponse )
4560
46- def test_query_bibcode (self ):
47- result = simbad .core .Simbad .query_bibcode ('2006ApJ*' , wildcard = True )
61+ def test_query_bibcode (self , temp_dir ):
62+ simbad = Simbad ()
63+ simbad .cache_location = temp_dir
64+ result = simbad .query_bibcode ('2006ApJ*' , wildcard = True )
4865 assert isinstance (result , Table )
4966
50- def test_query_bibobj_async (self ):
51- response = simbad .core .Simbad .query_bibobj_async ('2005A&A.430.165F' )
67+ def test_query_bibobj_async (self , temp_dir ):
68+ simbad = Simbad ()
69+ simbad .cache_location = temp_dir
70+ response = simbad .query_bibobj_async ('2006AJ....131.1163S' )
5271 assert response is not None
5372
54- def test_query_bibobj (self ):
55- result = simbad .core .Simbad .query_bibobj ('2005A&A.430.165F' )
73+ def test_query_bibobj (self , temp_dir ):
74+ simbad = Simbad ()
75+ simbad .ROW_LIMIT = 5
76+ simbad .cache_location = temp_dir
77+ result = simbad .query_bibobj ('2005A&A.430.165F' )
5678 assert isinstance (result , Table )
79+ assert len (result ) == 5
5780
58- def test_query_catalog_async (self ):
59- response = simbad .core .Simbad .query_catalog_async ('m' )
81+ def test_query_catalog_async (self , temp_dir ):
82+ simbad = Simbad ()
83+ simbad .cache_location = temp_dir
84+ response = simbad .query_catalog_async ('m' )
6085 assert response is not None
6186
62- def test_query_catalog (self ):
63- result = simbad .core .Simbad .query_catalog ('m' )
87+ def test_query_catalog (self , temp_dir ):
88+ simbad = Simbad ()
89+ simbad .cache_location = temp_dir
90+ result = simbad .query_catalog ('m' )
6491 assert isinstance (result , Table )
6592
66- def test_query_region_async (self ):
67- response = simbad .core .Simbad .query_region_async (
68- ICRS_COORDS_M42 , radius = 5 * u .deg , equinox = 2000.0 , epoch = 'J2000' )
93+ def test_query_region_async (self , temp_dir ):
94+ simbad = Simbad ()
95+ # TODO: rewise once ROW_LIMIT is working
96+ simbad .TIMEOUT = 100
97+ simbad .cache_location = temp_dir
98+ response = simbad .query_region_async (
99+ ICRS_COORDS_M42 , radius = 2 * u .deg , equinox = 2000.0 , epoch = 'J2000' )
69100
70101 assert response is not None
71102
72- def test_query_region_async_vector (self ):
73- response1 = simbad .core .Simbad .query_region_async (multicoords ,
74- radius = 0.5 * u .arcsec )
103+ def test_query_region_async_vector (self , temp_dir ):
104+ simbad = Simbad ()
105+ simbad .cache_location = temp_dir
106+ response1 = simbad .query_region_async (multicoords , radius = 0.5 * u .arcsec )
75107 assert response1 .request .body == 'script=votable+%7Bmain_id%2Ccoordinates%7D%0Avotable+open%0Aquery+coo+5%3A35%3A17.3+-80%3A52%3A00+radius%3D0.5s+frame%3DICRS+equi%3D2000.0%0Aquery+coo+17%3A47%3A20.4+-28%3A23%3A07.008+radius%3D0.5s+frame%3DICRS+equi%3D2000.0%0Avotable+close' # noqa
76108
77- def test_query_region (self ):
78- result = simbad .core .Simbad .query_region (ICRS_COORDS_M42 , radius = 5 * u .deg ,
79- equinox = 2000.0 , epoch = 'J2000' )
109+ def test_query_region (self , temp_dir ):
110+ simbad = Simbad ()
111+ # TODO: rewise once ROW_LIMIT is working
112+ simbad .TIMEOUT = 100
113+ simbad .cache_location = temp_dir
114+ result = simbad .query_region (ICRS_COORDS_M42 , radius = 2 * u .deg ,
115+ equinox = 2000.0 , epoch = 'J2000' )
80116 assert isinstance (result , Table )
81117
82- def test_query_regions (self ):
83- result = simbad .core .Simbad .query_region (multicoords , radius = 1 * u .arcmin ,
84- equinox = 2000.0 , epoch = 'J2000' )
118+ def test_query_regions (self , temp_dir ):
119+ simbad = Simbad ()
120+ simbad .cache_location = temp_dir
121+ result = simbad .query_region (multicoords , radius = 1 * u .arcmin ,
122+ equinox = 2000.0 , epoch = 'J2000' )
85123 assert isinstance (result , Table )
86124
87- def test_query_object_async (self ):
88- response = simbad .core .Simbad .query_object_async ("m [0-9]" ,
89- wildcard = True )
125+ def test_query_object_async (self , temp_dir ):
126+ simbad = Simbad ()
127+ simbad .cache_location = temp_dir
128+ response = simbad .query_object_async ("m [0-9]" , wildcard = True )
90129 assert response is not None
91130
92- def test_query_object (self ):
93- result = simbad .core .Simbad .query_object ("m [0-9]" , wildcard = True )
131+ def test_query_object (self , temp_dir ):
132+ simbad = Simbad ()
133+ simbad .cache_location = temp_dir
134+ result = simbad .query_object ("m [0-9]" , wildcard = True )
94135 assert isinstance (result , Table )
95136
96- def test_query_multi_object (self ):
97- result = simbad .core .Simbad .query_objects (['M32' , 'M81' ])
137+ def test_query_multi_object (self , temp_dir ):
138+ simbad = Simbad ()
139+ simbad .cache_location = temp_dir
140+ result = simbad .query_objects (['M32' , 'M81' ])
98141 assert len (result ) == 2
99142 assert len (result .errors ) == 0
100143
101- result = simbad .core . Simbad . query_objects (['M32' , 'M81' , 'gHer' ])
144+ result = simbad .query_objects (['M32' , 'M81' , 'gHer' ])
102145 # 'gHer' is not a valid Simbad identifier - it should be 'g Her' to
103146 # get the star
104147 assert len (result ) == 2
105148 assert len (result .errors ) == 1
106149
107150 # test async
108- s = simbad . core . Simbad ()
151+ s = Simbad ()
109152 response = s .query_objects_async (['M32' , 'M81' ])
110153
111- result = s ._parse_result (response , simbad . core . SimbadVOTableResult )
154+ result = s ._parse_result (response , SimbadVOTableResult )
112155 assert len (result ) == 2
113156
114- def test_query_object_ids (self ):
115- result = simbad .core .Simbad .query_objectids ("Polaris" )
157+ def test_query_object_ids (self , temp_dir ):
158+ simbad = Simbad ()
159+ simbad .cache_location = temp_dir
160+ result = simbad .query_objectids ("Polaris" )
116161
117162 # Today, there are 42 names. There could be more in the future
118163 assert len (result ) >= 42
@@ -126,47 +171,53 @@ def test_query_object_ids(self):
126171 ('query_bibobj' ),
127172 ('query_bibcode' ),
128173 ('query_objectids' )])
129- def test_null_response (self , function ):
130- assert (simbad .core .Simbad .__getattribute__ (function )('idonotexist' )
174+ def test_null_response (self , temp_dir , function ):
175+ simbad = Simbad ()
176+ simbad .cache_location = temp_dir
177+ assert (simbad .__getattribute__ (function )('idonotexist' )
131178 is None )
132179
133180 # Special case of null test: list of nonexistent parameters
134- def test_query_objects_null (self ):
135- assert simbad .core .Simbad .query_objects (['idonotexist' ,
136- 'idonotexisteither' ]) is None
181+ def test_query_objects_null (self , temp_dir ):
182+ simbad = Simbad ()
183+ simbad .cache_location = temp_dir
184+ assert simbad .query_objects (['idonotexist' , 'idonotexisteither' ]) is None
137185
138186 # Special case of null test: zero-sized region
139- def test_query_region_null (self ):
140- result = simbad .core .Simbad .query_region (
141- coord .SkyCoord ("00h01m0.0s 00h00m0.0s" ), radius = "0d" ,
142- equinox = 2000.0 , epoch = 'J2000' )
187+ def test_query_region_null (self , temp_dir ):
188+ simbad = Simbad ()
189+ simbad .cache_location = temp_dir
190+ result = simbad .query_region (SkyCoord ("00h01m0.0s 00h00m0.0s" ), radius = "0d" ,
191+ equinox = 2000.0 , epoch = 'J2000' )
143192 assert result is None
144193
145194 # Special case of null test: very small region
146- def test_query_small_region_null (self ):
147- result = simbad .core .Simbad .query_region (
148- coord .SkyCoord ("00h01m0.0s 00h00m0.0s" ), radius = 1.0 * u .marcsec ,
149- equinox = 2000.0 , epoch = 'J2000' )
195+ def test_query_small_region_null (self , temp_dir ):
196+ simbad = Simbad ()
197+ simbad .cache_location = temp_dir
198+ result = simbad .query_region (SkyCoord ("00h01m0.0s 00h00m0.0s" ), radius = 1.0 * u .marcsec ,
199+ equinox = 2000.0 , epoch = 'J2000' )
150200 assert result is None
151201
152202 # Special case : zero-sized region with one object
153- def test_query_zero_sized_region (self ):
154- result = simbad .core .Simbad .query_region (
155- coord .SkyCoord ("20h54m05.6889s 37d01m17.380s" ), radius = "1s" ,
156- equinox = 2000.0 , epoch = 'J2000' )
203+ def test_query_zero_sized_region (self , temp_dir ):
204+ simbad = Simbad ()
205+ simbad .cache_location = temp_dir
206+ result = simbad .query_region (SkyCoord ("20h54m05.6889s 37d01m17.380s" ), radius = "1s" ,
207+ equinox = 2000.0 , epoch = 'J2000' )
157208 # This should find a single star, BD+36 4308
158209 assert len (result ) == 1
159210
160211 def test_simbad_flux_qual (self ):
161212 '''Regression test for issue 680'''
162- request = simbad . core . Simbad ()
213+ request = Simbad ()
163214 request .add_votable_fields ("flux_qual(V)" )
164215 response = request .query_object ('algol' )
165216 assert ("FLUX_QUAL_V" in response .keys ())
166217
167218 def test_multi_vo_fields (self ):
168219 '''Regression test for issue 820'''
169- request = simbad . core . Simbad ()
220+ request = Simbad ()
170221
171222 request .add_votable_fields ("flux_qual(V)" )
172223 request .add_votable_fields ("flux_qual(R)" )
0 commit comments