1313from astropy import coordinates
1414from astropy import units as u
1515
16+ from astroquery .exceptions import CorruptDataWarning
1617from astroquery .utils .commons import ASTROPY_LT_4_1
1718from .. import Alma
1819
@@ -674,10 +675,10 @@ def test_verify_html_file(alma, caplog):
674675
675676 # download the file
676677 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 ]
678679
679680 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 ]
681682 local_filepath = result [0 ]
682683 existing_file_length = 66336
683684 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):
686687 with open (local_filepath , 'ab' ) as fh :
687688 fh .write (b"Extra Text" )
688689
689- print ("Trying the failed version now" )
690690 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." ):
692695 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 ]
699697
700698 # manipulate the file: make it small
701699 with open (local_filepath , 'wb' ) as fh :
702700 fh .write (b"Empty Text" )
703701
704702 caplog .clear ()
705703 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 ]
707705 length = 66336
708706 existing_file_length = 10
709707 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