1
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
- import os . path
2
+ from pathlib import Path
3
3
import os
4
4
import sys
5
5
import pytest
20
20
from ...xmatch import XMatch
21
21
22
22
23
- DATA_DIR = os . path . join ( os . path . dirname ( __file__ ), ' data' )
23
+ DATA_DIR = Path ( __file__ ). parent / " data"
24
24
25
25
26
26
@pytest .mark .remote_data
@@ -32,6 +32,18 @@ def test_is_xmatch_up():
32
32
pytest .xfail ("XMATCH appears to be down. Exception was: {0}" .format (ex ))
33
33
34
34
35
+ @pytest .fixture (scope = "module" )
36
+ def remote_table (tmp_path_factory ):
37
+ # this can be used to check that the API is still functional & doing as expected
38
+ infile = DATA_DIR / "posList.csv"
39
+ outfile = tmp_path_factory .mktemp ("remote_data" ) / "http_result.csv"
40
+ os .system ("curl -X POST -F request=xmatch -F distMaxArcsec=5 -F RESPONSEFORMAT=csv "
41
+ "-F cat1=@{1} -F colRA1=ra -F colDec1=dec -F cat2=vizier:II/246/out "
42
+ "http://cdsxmatch.u-strasbg.fr/xmatch/api/v1/sync > {0}" .
43
+ format (outfile , infile ))
44
+ return ascii .read (outfile , format = "csv" , fast_reader = False )
45
+
46
+
35
47
@pytest .mark .remote_data
36
48
@pytest .mark .dependency (depends = ["xmatch_up" ])
37
49
class TestXMatch :
@@ -55,8 +67,8 @@ def test_xmatch_is_avail_table(self, xmatch):
55
67
assert xmatch .is_table_available ('vizier:II/311/wise' )
56
68
assert not xmatch .is_table_available ('blablabla' )
57
69
58
- def test_xmatch_query (self , xmatch ):
59
- with open (os . path . join ( DATA_DIR , ' posList.csv' ), 'r' ) as pos_list :
70
+ def test_xmatch_query (self , xmatch , remote_table ):
71
+ with open (DATA_DIR / " posList.csv" , "r" ) as pos_list :
60
72
try :
61
73
table = xmatch .query (
62
74
cat1 = pos_list , cat2 = 'vizier:II/246/out' , max_distance = 5 * arcsec ,
@@ -70,12 +82,10 @@ def test_xmatch_query(self, xmatch):
70
82
'e_Jmag' , 'e_Hmag' , 'e_Kmag' , 'Qfl' , 'Rfl' , 'X' , 'MeasureJD' ]
71
83
assert len (table ) == 11
72
84
73
- http_test_table = self .http_test ()
74
- assert all (table == http_test_table )
85
+ assert all (table == remote_table )
75
86
76
- def test_xmatch_query_astropy_table (self , xmatch ):
77
- datapath = os .path .join (DATA_DIR , 'posList.csv' )
78
- input_table = Table .read (datapath , format = 'ascii.csv' )
87
+ def test_xmatch_query_astropy_table (self , xmatch , remote_table ):
88
+ input_table = Table .read (DATA_DIR / "posList.csv" , format = "ascii.csv" )
79
89
try :
80
90
table = xmatch .query (
81
91
cat1 = input_table , cat2 = 'vizier:II/246/out' , max_distance = 5 * arcsec ,
@@ -89,8 +99,7 @@ def test_xmatch_query_astropy_table(self, xmatch):
89
99
'e_Jmag' , 'e_Hmag' , 'e_Kmag' , 'Qfl' , 'Rfl' , 'X' , 'MeasureJD' ]
90
100
assert len (table ) == 11
91
101
92
- http_test_table = self .http_test ()
93
- assert all (table == http_test_table )
102
+ assert all (table == remote_table )
94
103
95
104
@pytest .mark .skipif ('regions' not in sys .modules ,
96
105
reason = "requires astropy-regions" )
@@ -102,14 +111,3 @@ def test_xmatch_query_with_cone_area(self, xmatch):
102
111
except ReadTimeout :
103
112
pytest .xfail ("xmatch query timed out." )
104
113
assert len (table ) == 185
105
-
106
- def http_test (self ):
107
- # this can be used to check that the API is still functional & doing as expected
108
- infile = os .path .join (DATA_DIR , 'posList.csv' )
109
- outfile = os .path .join (DATA_DIR , 'http_result.csv' )
110
- os .system ('curl -X POST -F request=xmatch -F distMaxArcsec=5 -F RESPONSEFORMAT=csv '
111
- '-F cat1=@{1} -F colRA1=ra -F colDec1=dec -F cat2=vizier:II/246/out '
112
- 'http://cdsxmatch.u-strasbg.fr/xmatch/api/v1/sync > {0}' .
113
- format (outfile , infile ))
114
- table = ascii .read (outfile , format = 'csv' , fast_reader = False )
115
- return table
0 commit comments