7
7
* Property: European Space Agency (ESA)
8
8
* Developed by: Elecnor Deimos
9
9
* Author: C. Álvaro Arroyo Parejo
10
- * Date: 02-11-2021
10
+ * Date: 21-08-2022
11
11
12
- © Copyright [European Space Agency][2021 ]
12
+ © Copyright [European Space Agency][2022 ]
13
13
All rights reserved
14
14
"""
15
15
16
-
17
16
import io
18
17
import os
19
18
import re
20
-
21
19
import random
22
20
import pytest
21
+ import astropy
22
+
23
+ from astropy .table import Table
23
24
import pandas as pd
24
25
import pandas .testing as pdtesting
25
26
import pandas .api .types as ptypes
28
29
from astroquery .esa .neocc .__init__ import conf
29
30
from astroquery .esa .neocc import neocc , lists , tabs
30
31
31
- import astropy
32
-
33
32
# Import BASE URL and TIMEOUT
34
33
API_URL = conf .API_URL
35
34
DATA_DIR = os .path .join (os .path .dirname (__file__ ), 'data' )
@@ -52,7 +51,7 @@ class TestLists:
52
51
"priority_list" : 'esa_priority_neo_list' ,
53
52
"priority_list_faint" : 'esa_faint_neo_list' ,
54
53
"close_encounter" : 'close_encounter2.txt' ,
55
- "impacted_objects" : 'impactedObjectsList.txt ' ,
54
+ "impacted_objects" : 'past_impactors_list ' ,
56
55
"neo_catalogue_current" : 'neo_kc.cat' ,
57
56
"neo_catalogue_middle" : 'neo_km.cat'
58
57
}
@@ -127,8 +126,11 @@ def test_parse_list(self):
127
126
verify = VERIFICATION ).content
128
127
# Decode the data using UTF-8
129
128
data_list_d = io .StringIO (data_list .decode ('utf-8' ))
130
-
131
- assert isinstance (lists .parse_list (url , data_list_d ),
129
+ if url == 'impacted_objects' :
130
+ assert isinstance (lists .parse_list (url , data_list_d ),
131
+ Table )
132
+ else :
133
+ assert isinstance (lists .parse_list (url , data_list_d ),
132
134
pd .DataFrame )
133
135
# Invalid inputs
134
136
bad_names = ["ASedfe" , "%&$" , "ÁftR+" , 154 ]
@@ -222,9 +224,22 @@ def test_parse_risk(self):
222
224
new_list ['Date/Time' ])
223
225
224
226
else :
225
- # Currently risk special list is empty
226
- assert new_list .empty
227
+ # Assert dataframe is not empty, columns names
228
+ assert not new_list .empty
227
229
assert (new_list .columns == risk_special_columns ).all ()
230
+ # Assert columns data types
231
+ # Floats
232
+ float_cols = ['IP max' , 'PS max' , 'Vel in km/s' ]
233
+ assert all (ptypes .is_float_dtype (new_list [cols1 ])\
234
+ for cols1 in float_cols )
235
+ # int64
236
+ int_cols = ['Diameter in m' ]
237
+ assert all (ptypes .is_int64_dtype (new_list [cols2 ])\
238
+ for cols2 in int_cols )
239
+ # Object
240
+ object_cols = ['Object Name' , '*=Y' , 'TS' ]
241
+ assert all (ptypes .is_object_dtype (new_list [cols3 ])\
242
+ for cols3 in object_cols )
228
243
229
244
230
245
def test_parse_clo (self ):
@@ -254,7 +269,7 @@ def test_parse_clo(self):
254
269
# Assert dataframe is not empty, columns names and length
255
270
assert not new_list .empty
256
271
assert (new_list .columns == close_columns ).all ()
257
- assert len (new_list .index ) > 100
272
+ assert len (new_list .index ) > 10
258
273
# Assert Connection Error. In case of internal server error
259
274
# the request provided an empty file
260
275
foo_error = io .StringIO ('This site cant be reached\n '
@@ -383,15 +398,11 @@ def test_parse_impacted(self):
383
398
# Parse using parse_nea
384
399
new_list = lists .parse_impacted (data_list_d )
385
400
# Assert is a pandas DataFrame
386
- assert isinstance (new_list , pd . DataFrame )
401
+ assert isinstance (new_list , Table )
387
402
# Assert dataframe is not empty and length
388
- assert not new_list .empty
389
- assert len (new_list .index ) < 100
390
- # Assert columns data types
391
- # Object
392
- assert ptypes .is_object_dtype (new_list [0 ])
393
- # Datetime
394
- assert ptypes .is_datetime64_ns_dtype (new_list [1 ])
403
+ # Assert dataframe is not empty, columns names and length
404
+ assert len (new_list ) != 0
405
+ assert len (new_list ) < 100
395
406
396
407
397
408
def test_parse_neo_catalogue (self ):
@@ -460,14 +471,16 @@ def test_get_object_url(self):
460
471
'observations' , 'orbit_properties' , '&cefrgfe' ,
461
472
4851 ]
462
473
# Possible additional argument
474
+ orbital_element = ['keplerian' , 'equinoctial' ]
463
475
orbit_epoch = ['present' , 'middle' ]
464
476
# Iterate to obtain all possible urls
465
477
for tab in object_tabs :
466
478
if tab == 'orbit_properties' :
467
- for epoch in orbit_epoch :
468
- with pytest .raises (ValueError ):
469
- tabs .get_object_url (rnd_object , tab ,
470
- orbital_elements = None , orbit_epoch = epoch )
479
+ for element in orbital_element :
480
+ for epoch in orbit_epoch :
481
+ with pytest .raises (ValueError ):
482
+ tabs .get_object_url (rnd_object , tab ,
483
+ orbital_elements = None , orbit_epoch = epoch )
471
484
elif tab in ['&cefrgfe' , 4851 ]:
472
485
with pytest .raises (KeyError ):
473
486
tabs .get_object_url (rnd_object , tab )
0 commit comments