2525
2626FILE_NOT_FOUND_ERROR = getattr (__builtins__ , "FileNotFoundError" , OSError )
2727
28- try :
29- iers .IERS_A .open ("finals2000A.all" ) # check if IERS_A is available
30- except OSError :
31- HAS_IERS_A = False
32- else :
33- HAS_IERS_A = True
34-
3528IERS_A_EXCERPT = get_pkg_data_filename (os .path .join ("data" , "iers_a_excerpt" ))
3629
3730
38- def setup_module ():
39- # Need auto_download so that IERS_B won't be loaded and cause tests to
40- # fail. Files to be downloaded are handled appropriately in the tests.
41- iers .conf .auto_download = True
42-
43-
44- def teardown_module ():
45- # This setting is to be consistent with astropy/conftest.py
46- iers .conf .auto_download = False
47-
48-
4931class TestBasic :
5032 """Basic tests that IERS_B returns correct values"""
5133
@@ -216,7 +198,6 @@ def test_simple(self):
216198 assert len (iers_tab [:2 ]) == 2
217199
218200
219- @pytest .mark .skipif (not HAS_IERS_A , reason = "requires IERS_A" )
220201class TestIERS_A :
221202 @classmethod
222203 def teardown_class (self ):
@@ -261,6 +242,14 @@ def setup_class(self):
261242 self .iers_a_url_2 = Path (self .iers_a_file_2 ).as_uri ()
262243 self .t = Time .now () + TimeDelta (10 , format = "jd" ) * np .arange (self .N )
263244
245+ # This group of tests requires auto downloading to be on
246+ iers .conf .auto_download = True
247+
248+ # auto_download = False is tested in test_IERS_B_parameters_loading_into_IERS_Auto()
249+
250+ def teardown_class (self ):
251+ iers .conf .auto_download = False
252+
264253 def teardown_method (self , method ):
265254 """Run this after every test."""
266255 iers .IERS_Auto .close ()
@@ -310,12 +299,6 @@ def test_auto_max_age_minimum(self):
310299 iers_table = iers .IERS_Auto .open ()
311300 _ = iers_table .ut1_utc (self .t .jd1 , self .t .jd2 )
312301
313- def test_no_auto_download (self ):
314- with iers .conf .set_temp ("auto_download" , False ):
315- t = iers .IERS_Auto .open ()
316- assert type (t ) is iers .IERS_B
317-
318- @pytest .mark .remote_data
319302 def test_simple (self ):
320303 with iers .conf .set_temp ("iers_auto_url" , self .iers_a_url_1 ):
321304 dat = iers .IERS_Auto .open ()
@@ -383,8 +366,10 @@ def test_simple(self):
383366 assert dat ["MJD" ][- 1 ] == (57539.0 + 60 ) * u .d
384367
385368
386- @pytest .mark .remote_data
387369def test_IERS_B_parameters_loading_into_IERS_Auto ():
370+ # Double-check that auto downloading is off
371+ assert not iers .conf .auto_download
372+
388373 A = iers .IERS_Auto .open ()
389374 B = iers .IERS_B .open ()
390375
@@ -448,35 +433,31 @@ def test_iers_b_dl():
448433 iers .IERS_B .close ()
449434
450435
451- @pytest .mark .remote_data
452- def test_iers_out_of_range_handling (tmp_path ):
453- # Make sure we don't have IERS-A data available anywhere
454- with set_temp_cache (tmp_path ):
455- iers .IERS_A .close ()
456- iers .IERS_Auto .close ()
457- iers .IERS .close ()
436+ def test_iers_b_out_of_range_handling ():
437+ # The following error/warning applies only to IERS_B, not to the default IERS_Auto
438+ with iers .earth_orientation_table .set (iers .IERS_B .open ()):
458439 now = Time .now ()
459- with iers .conf .set_temp ("auto_download" , False ):
460- # Should be fine with built-in IERS_B
461- (now - 300 * u .day ).ut1
462440
463- # Default is to raise an error
464- match = r"\(some\) times are outside of range covered by IERS table"
465- with pytest .raises (iers .IERSRangeError , match = match ):
466- (now + 100 * u .day ).ut1
441+ # Should be fine with bundled IERS-B
442+ (now - 300 * u .day ).ut1
467443
468- with iers .conf .set_temp ("iers_degraded_accuracy" , "warn" ):
469- with pytest .warns (iers .IERSDegradedAccuracyWarning , match = match ):
470- (now + 100 * u .day ).ut1
444+ # Default is to raise an error
445+ match = r"\(some\) times are outside of range covered by IERS table"
446+ with pytest .raises (iers .IERSRangeError , match = match ):
447+ (now + 100 * u .day ).ut1
471448
472- with iers .conf .set_temp ("iers_degraded_accuracy" , "ignore" ):
449+ with iers .conf .set_temp ("iers_degraded_accuracy" , "warn" ):
450+ with pytest .warns (iers .IERSDegradedAccuracyWarning , match = match ):
473451 (now + 100 * u .day ).ut1
474452
453+ with iers .conf .set_temp ("iers_degraded_accuracy" , "ignore" ):
454+ (now + 100 * u .day ).ut1
455+
475456
476457@pytest .mark .remote_data
477458def test_iers_download_error_handling (tmp_path ):
478- # Make sure we don't have IERS-A data available anywhere
479- with set_temp_cache (tmp_path ):
459+ # Make sure an IERS-A table isn't already loaded
460+ with set_temp_cache (tmp_path ), iers . conf . set_temp ( "auto_download" , True ) :
480461 iers .IERS_A .close ()
481462 iers .IERS_Auto .close ()
482463 iers .IERS .close ()
@@ -488,7 +469,7 @@ def test_iers_download_error_handling(tmp_path):
488469 with iers .conf .set_temp ("iers_auto_url_mirror" , "https://google.com" ):
489470 with pytest .warns (iers .IERSWarning ) as record :
490471 with iers .conf .set_temp ("iers_degraded_accuracy" , "ignore" ):
491- (now + 100 * u .day ).ut1
472+ (now + 400 * u .day ).ut1
492473
493474 assert len (record ) == 3
494475 assert str (record [0 ].message ).startswith (
@@ -498,7 +479,7 @@ def test_iers_download_error_handling(tmp_path):
498479 "malformed IERS table from https://google.com"
499480 )
500481 assert str (record [2 ].message ).startswith (
501- "unable to download valid IERS file, using local IERS-B "
482+ "unable to download valid IERS file, using local IERS-A "
502483 )
503484
504485
0 commit comments