13
13
from astropy import coordinates
14
14
from astropy import units as u
15
15
16
+ from astroquery .exceptions import CorruptDataWarning
16
17
from astroquery .utils .commons import ASTROPY_LT_4_1
17
18
from .. import Alma
18
19
@@ -674,10 +675,10 @@ def test_verify_html_file(alma, caplog):
674
675
675
676
# download the file
676
677
result = alma .download_files (['https://almascience.nao.ac.jp/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html' ])
677
- assert result
678
+ assert 'member.uid___A001_X1284_X1353.qa2_report.html' in result [ 0 ]
678
679
679
680
result = alma .download_files (['https://almascience.nao.ac.jp/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html' ], verify_only = True )
680
- assert result
681
+ assert 'member.uid___A001_X1284_X1353.qa2_report.html' in result [ 0 ]
681
682
local_filepath = result [0 ]
682
683
existing_file_length = 66336
683
684
assert f"Found cached file { local_filepath } with expected size { existing_file_length } ." in caplog .text
@@ -686,24 +687,25 @@ def test_verify_html_file(alma, caplog):
686
687
with open (local_filepath , 'ab' ) as fh :
687
688
fh .write (b"Extra Text" )
688
689
689
- print ("Trying the failed version now" )
690
690
caplog .clear ()
691
- with warnings .catch_warnings (record = True ) as ww :
691
+ length = 66336
692
+ existing_file_length = length + 10
693
+ with pytest .warns (expected_warning = CorruptDataWarning ,
694
+ match = f"Found cached file { local_filepath } with size { existing_file_length } > expected size { length } . The download is likely corrupted." ):
692
695
result = alma .download_files (['https://almascience.nao.ac.jp/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html' ], verify_only = True )
693
- assert result
694
- length = 66336
695
- existing_file_length = length + 10
696
- print (f"WARNING: { str (ww )} " )
697
- print (f"caplog: { caplog .text } " )
698
- assert f"Found cached file { local_filepath } with size { existing_file_length } > expected size { length } . The download is likely corrupted." in str (ww )
696
+ assert 'member.uid___A001_X1284_X1353.qa2_report.html' in result [0 ]
699
697
700
698
# manipulate the file: make it small
701
699
with open (local_filepath , 'wb' ) as fh :
702
700
fh .write (b"Empty Text" )
703
701
704
702
caplog .clear ()
705
703
result = alma .download_files (['https://almascience.nao.ac.jp/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html' ], verify_only = True )
706
- assert result
704
+ assert 'member.uid___A001_X1284_X1353.qa2_report.html' in result [ 0 ]
707
705
length = 66336
708
706
existing_file_length = 10
709
707
assert f"Found cached file { local_filepath } with size { existing_file_length } < expected size { length } . The download should be continued." in caplog .text
708
+
709
+ # cleanup: we don't want `test_download_html_file` to fail if this test is re-run
710
+ if os .path .exists (local_filepath ):
711
+ os .remove (local_filepath )
0 commit comments