@@ -46,10 +46,9 @@ def request_mockreturn(method, url, data, **kwargs):
46
46
47
47
48
48
def test_xmatch_query_invalid_max_distance ():
49
- with pytest .raises (ValueError ) as ex :
49
+ with pytest .raises (ValueError ,
50
+ match = 'max_distance argument must not be greater than 180"' ):
50
51
XMatch ().query_async ('' , '' , 181 * arcsec )
51
- assert str (ex .value ) == (
52
- 'max_distance argument must not be greater than 180' )
53
52
54
53
55
54
def test_get_available_tables (monkeypatch ):
@@ -125,3 +124,35 @@ def test_table_not_available(monkeypatch):
125
124
# reproduces #1464
126
125
with pytest .raises (ValueError , match = f"'{ re .escape (cat1 )} ' is not available *" ):
127
126
xm .query_async (cat1 = cat1 , cat2 = cat2 , max_distance = 5 * arcsec )
127
+
128
+
129
+ def test_prepare_sending_tables (monkeypatch ):
130
+ xm = XMatch ()
131
+ monkeypatch .setattr (xm , '_request' , request_mockreturn )
132
+
133
+ # if it's a valid vizier table, prepend vizier:
134
+ payload = {}
135
+ xm ._prepare_sending_table (1 , payload , {}, "II/316/gps6" , None , None )
136
+ assert payload == {'cat1' : 'vizier:II/316/gps6' }
137
+ # also works if vizier: is already given by the user
138
+ payload = {}
139
+ xm ._prepare_sending_table (1 , payload , {}, "vizier:II/316/gps6" , None , None )
140
+ assert payload == {'cat1' : 'vizier:II/316/gps6' }
141
+
142
+ # otherwise colRa1 and colDec1 have to be given
143
+ with pytest .raises (ValueError , match = "'test' is not available on the XMatch server." ):
144
+ xm ._prepare_sending_table (1 , payload , {}, "test" , None , None )
145
+ payload = {}
146
+ # this mimics the url case
147
+ xm ._prepare_sending_table (1 , payload , {}, "test" , "ra" , "dec" )
148
+ assert payload == {'cat1' : 'test' , 'colRA1' : 'ra' , 'colDec1' : 'dec' }
149
+
150
+ # if cat is not a string, then the payload has to include the file
151
+ payload = {}
152
+ kwargs = {}
153
+ cat = Table ({'a' : [0 , 1 , 2 ], 'b' : [3 , 4 , 5 ]})
154
+ xm ._prepare_sending_table (1 , payload , kwargs , cat , "a" , "b" )
155
+ assert payload == {'colRA1' : 'a' , 'colDec1' : 'b' }
156
+ assert (kwargs == {'files' : {'cat1' : ('cat1.csv' , 'a,b\n 0,3\n 1,4\n 2,5\n ' )}}
157
+ # for windows systems
158
+ or kwargs == {'files' : {'cat1' : ('cat1.csv' , 'a,b\r \n 0,3\r \n 1,4\r \n 2,5\r \n ' )}})
0 commit comments