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
2024 @classmethod
2125 def setup_class (cls ):
22- simbad . core . Simbad .ROW_LIMIT = 5
26+ Simbad .ROW_LIMIT = 5
2327
24- def test_query_criteria1 (self ):
25- result = simbad .core .Simbad .query_criteria (
28+ @pytest .fixture ()
29+ def temp_dir (self , request ):
30+ my_temp_dir = tempfile .mkdtemp ()
31+
32+ def fin ():
33+ shutil .rmtree (my_temp_dir )
34+ request .addfinalizer (fin )
35+ return my_temp_dir
36+
37+ def test_query_criteria1 (self , temp_dir ):
38+ simbad = Simbad ()
39+ simbad .cache_location = temp_dir
40+ result = simbad .query_criteria (
2641 "region(box, GAL, 49.89 -0.3, 0.5d 0.5d)" , otype = 'HII' )
2742 assert isinstance (result , Table )
2843
29- def test_query_criteria2 (self ):
30- result = simbad .core .Simbad .query_criteria (otype = 'SNR' )
44+ def test_query_criteria2 (self , temp_dir ):
45+ simbad = Simbad ()
46+ simbad .cache_location = temp_dir
47+ result = simbad .query_criteria (otype = 'SNR' )
3148 assert isinstance (result , Table )
3249
33- def test_query_bibcode_async (self ):
34- response = simbad .core .Simbad .query_bibcode_async (
50+ def test_query_bibcode_async (self , temp_dir ):
51+ simbad = Simbad ()
52+ simbad .cache_location = temp_dir
53+ response = simbad .query_bibcode_async (
3554 '2006ApJ*' , wildcard = True )
3655 assert response is not None
3756 response .raise_for_status ()
@@ -43,76 +62,101 @@ def test_query_bibcode_async(self):
4362 assert not isinstance (response , MockResponse )
4463 assert not issubclass (response .__class__ , MockResponse )
4564
46- def test_query_bibcode (self ):
47- result = simbad .core .Simbad .query_bibcode ('2006ApJ*' , wildcard = True )
65+ def test_query_bibcode (self , temp_dir ):
66+ simbad = Simbad ()
67+ simbad .cache_location = temp_dir
68+ result = simbad .query_bibcode ('2006ApJ*' , wildcard = True )
4869 assert isinstance (result , Table )
4970
50- def test_query_bibobj_async (self ):
51- response = simbad .core .Simbad .query_bibobj_async ('2005A&A.430.165F' )
71+ def test_query_bibobj_async (self , temp_dir ):
72+ simbad = Simbad ()
73+ simbad .cache_location = temp_dir
74+ response = simbad .query_bibobj_async ('2005A&A.430.165F' )
5275 assert response is not None
5376
54- def test_query_bibobj (self ):
55- result = simbad .core .Simbad .query_bibobj ('2005A&A.430.165F' )
77+ def test_query_bibobj (self , temp_dir ):
78+ simbad = Simbad ()
79+ simbad .cache_location = temp_dir
80+ result = simbad .query_bibobj ('2005A&A.430.165F' )
5681 assert isinstance (result , Table )
5782
58- def test_query_catalog_async (self ):
59- response = simbad .core .Simbad .query_catalog_async ('m' )
83+ def test_query_catalog_async (self , temp_dir ):
84+ simbad = Simbad ()
85+ simbad .cache_location = temp_dir
86+ response = simbad .query_catalog_async ('m' )
6087 assert response is not None
6188
62- def test_query_catalog (self ):
63- result = simbad .core .Simbad .query_catalog ('m' )
89+ def test_query_catalog (self , temp_dir ):
90+ simbad = Simbad ()
91+ simbad .cache_location = temp_dir
92+ result = simbad .query_catalog ('m' )
6493 assert isinstance (result , Table )
6594
66- def test_query_region_async (self ):
67- response = simbad .core .Simbad .query_region_async (
95+ def test_query_region_async (self , temp_dir ):
96+ simbad = Simbad ()
97+ simbad .cache_location = temp_dir
98+ response = simbad .query_region_async (
6899 ICRS_COORDS_M42 , radius = 5 * 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 ,
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 ,
74107 radius = 0.5 * u .arcsec )
75108 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
76109
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' )
110+ def test_query_region (self , temp_dir ):
111+ simbad = Simbad ()
112+ simbad .cache_location = temp_dir
113+ result = simbad .query_region (ICRS_COORDS_M42 , radius = 5 * u .deg ,
114+ equinox = 2000.0 , epoch = 'J2000' )
80115 assert isinstance (result , Table )
81116
82- def test_query_regions (self ):
83- result = simbad .core .Simbad .query_region (multicoords , radius = 1 * u .arcmin ,
84- equinox = 2000.0 , epoch = 'J2000' )
117+ def test_query_regions (self , temp_dir ):
118+ simbad = Simbad ()
119+ simbad .cache_location = temp_dir
120+ result = simbad .query_region (multicoords , radius = 1 * u .arcmin ,
121+ equinox = 2000.0 , epoch = 'J2000' )
85122 assert isinstance (result , Table )
86123
87- def test_query_object_async (self ):
88- response = simbad .core .Simbad .query_object_async ("m [0-9]" ,
89- wildcard = True )
124+ def test_query_object_async (self , temp_dir ):
125+ simbad = Simbad ()
126+ simbad .cache_location = temp_dir
127+ response = simbad .query_object_async ("m [0-9]" , wildcard = True )
90128 assert response is not None
91129
92- def test_query_object (self ):
93- result = simbad .core .Simbad .query_object ("m [0-9]" , wildcard = True )
130+ def test_query_object (self , temp_dir ):
131+ simbad = Simbad ()
132+ simbad .cache_location = temp_dir
133+ result = simbad .query_object ("m [0-9]" , wildcard = True )
94134 assert isinstance (result , Table )
95135
96- def test_query_multi_object (self ):
97- result = simbad .core .Simbad .query_objects (['M32' , 'M81' ])
136+ def test_query_multi_object (self , temp_dir ):
137+ simbad = Simbad ()
138+ simbad .cache_location = temp_dir
139+ result = simbad .query_objects (['M32' , 'M81' ])
98140 assert len (result ) == 2
99141 assert len (result .errors ) == 0
100142
101- result = simbad .core . Simbad . query_objects (['M32' , 'M81' , 'gHer' ])
143+ result = simbad .query_objects (['M32' , 'M81' , 'gHer' ])
102144 # 'gHer' is not a valid Simbad identifier - it should be 'g Her' to
103145 # get the star
104146 assert len (result ) == 2
105147 assert len (result .errors ) == 1
106148
107149 # test async
108- s = simbad . core . Simbad ()
150+ s = Simbad ()
109151 response = s .query_objects_async (['M32' , 'M81' ])
110152
111- result = s ._parse_result (response , simbad . core . SimbadVOTableResult )
153+ result = s ._parse_result (response , SimbadVOTableResult )
112154 assert len (result ) == 2
113155
114- def test_query_object_ids (self ):
115- result = simbad .core .Simbad .query_objectids ("Polaris" )
156+ def test_query_object_ids (self , temp_dir ):
157+ simbad = Simbad ()
158+ simbad .cache_location = temp_dir
159+ result = simbad .query_objectids ("Polaris" )
116160
117161 # Today, there are 42 names. There could be more in the future
118162 assert len (result ) >= 42
@@ -126,47 +170,53 @@ def test_query_object_ids(self):
126170 ('query_bibobj' ),
127171 ('query_bibcode' ),
128172 ('query_objectids' )])
129- def test_null_response (self , function ):
130- assert (simbad .core .Simbad .__getattribute__ (function )('idonotexist' )
173+ def test_null_response (self , temp_dir , function ):
174+ simbad = Simbad ()
175+ simbad .cache_location = temp_dir
176+ assert (simbad .__getattribute__ (function )('idonotexist' )
131177 is None )
132178
133179 # 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
180+ def test_query_objects_null (self , temp_dir ):
181+ simbad = Simbad ()
182+ simbad .cache_location = temp_dir
183+ assert simbad .query_objects (['idonotexist' , 'idonotexisteither' ]) is None
137184
138185 # 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' )
186+ def test_query_region_null (self , temp_dir ):
187+ simbad = Simbad ()
188+ simbad .cache_location = temp_dir
189+ result = simbad .query_region (SkyCoord ("00h01m0.0s 00h00m0.0s" ), radius = "0d" ,
190+ equinox = 2000.0 , epoch = 'J2000' )
143191 assert result is None
144192
145193 # 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' )
194+ def test_query_small_region_null (self , temp_dir ):
195+ simbad = Simbad ()
196+ simbad .cache_location = temp_dir
197+ result = simbad .query_region (SkyCoord ("00h01m0.0s 00h00m0.0s" ), radius = 1.0 * u .marcsec ,
198+ equinox = 2000.0 , epoch = 'J2000' )
150199 assert result is None
151200
152201 # 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' )
202+ def test_query_zero_sized_region (self , temp_dir ):
203+ simbad = Simbad ()
204+ simbad .cache_location = temp_dir
205+ result = simbad .query_region (SkyCoord ("20h54m05.6889s 37d01m17.380s" ), radius = "1s" ,
206+ equinox = 2000.0 , epoch = 'J2000' )
157207 # This should find a single star, BD+36 4308
158208 assert len (result ) == 1
159209
160210 def test_simbad_flux_qual (self ):
161211 '''Regression test for issue 680'''
162- request = simbad . core . Simbad ()
212+ request = Simbad ()
163213 request .add_votable_fields ("flux_qual(V)" )
164214 response = request .query_object ('algol' )
165215 assert ("FLUX_QUAL_V" in response .keys ())
166216
167217 def test_multi_vo_fields (self ):
168218 '''Regression test for issue 820'''
169- request = simbad . core . Simbad ()
219+ request = Simbad ()
170220
171221 request .add_votable_fields ("flux_qual(V)" )
172222 request .add_votable_fields ("flux_qual(R)" )
0 commit comments