@@ -918,45 +918,34 @@ def test_proper_error_raised_on_non_fits_file_with_unicode(self):
918918 # Avoid a spurious pyflakes warning about an unused import
919919 # of six by adding a reason string
920920 @pytest .mark .skipif (six .PY2 , reason = 'six.PY2' )
921- @pytest .mark .parametrize (('ignore' , ), [(False , ), (True , )])
922- def test_no_resource_warning_raised_on_non_fits_file (self , ignore ):
921+ @pytest .mark .parametrize ('ignore' , [False , True ])
922+ @pytest .mark .parametrize ('fileobj' , [False , True ])
923+ def test_no_resource_warning_raised_on_non_fits_file (self , ignore , fileobj ):
923924 """
924925 Regression test for https://github.com/astropy/astropy/issues/6168
925926
926927 The ResourceWarning shows up when (in python 3+) you try to
927- open a non-FITS file.
928+ open a non-FITS file when using a filename .
928929 """
930+
929931 filename = self .temp ('not-fits.fits' )
930932 with open (filename , mode = 'w' ) as f :
931933 f .write ('# header line\n ' )
932934 f .write ('0.1 0.2\n ' )
933935
934936 # This should raise an IOError because there is no end card.
935937 with catch_warnings (ResourceWarning ) as ws :
936- with pytest .raises (IOError ):
937- fits .open (filename , ignore_missing_end = ignore )
938-
939- assert len (ws ) == 0
940-
941- @pytest .mark .skipif (six .PY2 , reason = 'six.PY2' )
942- def test_no_resource_warning_raised_on_non_fits_file_as_fileobj (self ):
943- """
944- Regression test for https://github.com/astropy/astropy/issues/6168
945938
946- This is to check that the file is not closed when a file object
947- is sent in to fits.open.
948- """
949- filename = self .temp ('not-fits.fits' )
950- with open (filename , mode = 'w' ) as f :
951- f .write ('# header line\n ' )
952- f .write ('0.1 0.2\n ' )
939+ if fileobj :
940+ # Make sure that files opened by the user are not closed
941+ with open (filename , mode = 'rb' ) as f :
942+ with pytest .raises (OSError ):
943+ fits .open (f , ignore_missing_end = ignore )
953944
954- # This should raise an IOError because there is no end card.
955- with catch_warnings (ResourceWarning ) as ws :
956- with open (filename , mode = 'rb' ) as f :
957- with pytest .raises (IOError ):
958- fits .open (f )
945+ assert not f .closed
959946
960- assert not f .closed
947+ else :
948+ with pytest .raises (OSError ):
949+ fits .open (filename , ignore_missing_end = ignore )
961950
962951 assert len (ws ) == 0
0 commit comments