示例#1
0
    def test_save_backup(self):
        """Test for #121--save backup of file before flushing changes."""

        shutil.copy(self.data('scale.fits'), self.temp('scale.fits'))

        with ignore_warnings():
            with pyfits.open(self.temp('scale.fits'), mode='update',
                             save_backup=True) as hdul:
                # Make some changes to the original file to force its header
                # and data to be rewritten
                hdul[0].header['TEST'] = 'TEST'
                hdul[0].data[0] = 0

        assert_true(os.path.exists(self.temp('scale.fits.bak')))
        with pyfits.open(self.data('scale.fits'),
                         do_not_scale_image_data=True) as hdul1:
            with pyfits.open(self.temp('scale.fits.bak'),
                             do_not_scale_image_data=True) as hdul2:
                assert_equal(hdul1[0].header, hdul2[0].header)
                assert_true((hdul1[0].data == hdul2[0].data).all())

        with ignore_warnings():
            with pyfits.open(self.temp('scale.fits'), mode='update',
                             save_backup=True) as hdul:
                # One more time to see if multiple backups are made
                hdul[0].header['TEST2'] = 'TEST'
                hdul[0].data[0] = 1

        assert_true(os.path.exists(self.temp('scale.fits.bak')))
        assert_true(os.path.exists(self.temp('scale.fits.bak.1')))
示例#2
0
    def test_save_backup(self):
        """Test for https://trac.assembla.com/pyfits/ticket/121

        Save backup of file before flushing changes.
        """

        self.copy_file('scale.fits')

        with ignore_warnings():
            with fits.open(self.temp('scale.fits'), mode='update',
                           save_backup=True) as hdul:
                # Make some changes to the original file to force its header
                # and data to be rewritten
                hdul[0].header['TEST'] = 'TEST'
                hdul[0].data[0] = 0

        assert os.path.exists(self.temp('scale.fits.bak'))
        with fits.open(self.data('scale.fits'),
                       do_not_scale_image_data=True) as hdul1:
            with fits.open(self.temp('scale.fits.bak'),
                           do_not_scale_image_data=True) as hdul2:
                assert hdul1[0].header == hdul2[0].header
                assert (hdul1[0].data == hdul2[0].data).all()

        with ignore_warnings():
            with fits.open(self.temp('scale.fits'), mode='update',
                           save_backup=True) as hdul:
                # One more time to see if multiple backups are made
                hdul[0].header['TEST2'] = 'TEST'
                hdul[0].data[0] = 1

        assert os.path.exists(self.temp('scale.fits.bak'))
        assert os.path.exists(self.temp('scale.fits.bak.1'))
示例#3
0
    def test_rewriting_large_scaled_image_compressed(self):
        """
        Regression test for #88 1.

        Identical to test_rewriting_large_scaled_image() but with a compressed
        image.
        """

        with pyfits.open(self.data('fixed-1890.fits'),
                         do_not_scale_image_data=True) as hdul:
            chdu = pyfits.CompImageHDU(data=hdul[0].data,
                                       header=hdul[0].header)
            chdu.writeto(self.temp('fixed-1890-z.fits'))

        hdul = pyfits.open(self.temp('fixed-1890-z.fits'))
        orig_data = hdul[1].data
        with ignore_warnings():
            hdul.writeto(self.temp('test_new.fits'), clobber=True)
        hdul.close()
        hdul = pyfits.open(self.temp('test_new.fits'))
        assert_true((hdul[1].data == orig_data).all())
        hdul.close()

        # Just as before, but this time don't touch hdul[0].data before writing
        # back out--this is the case that failed in #84
        hdul = pyfits.open(self.temp('fixed-1890-z.fits'))
        with ignore_warnings():
            hdul.writeto(self.temp('test_new.fits'), clobber=True)
        hdul.close()
        hdul = pyfits.open(self.temp('test_new.fits'))
        assert_true((hdul[1].data == orig_data).all())
        hdul.close()

        # Test opening/closing/reopening a scaled file in update mode
        hdul = pyfits.open(self.temp('fixed-1890-z.fits'),
                           do_not_scale_image_data=True)
        hdul.writeto(self.temp('test_new.fits'), clobber=True,
                     output_verify='silentfix')
        hdul.close()
        hdul = pyfits.open(self.temp('test_new.fits'))
        orig_data = hdul[1].data
        hdul.close()
        hdul = pyfits.open(self.temp('test_new.fits'), mode='update')
        hdul.close()
        hdul = pyfits.open(self.temp('test_new.fits'))
        assert_true((hdul[1].data == orig_data).all())
        hdul = pyfits.open(self.temp('test_new.fits'))
        hdul.close()
示例#4
0
文件: test_core.py 项目: coleb/PyFITS
    def test_read_file_like_object(self):
        """Test reading a FITS file from a file-like object."""

        filelike = BytesIO()
        with open(self.data('test0.fits'), 'rb') as f:
            filelike.write(f.read())
        filelike.seek(0)
        with ignore_warnings():
            assert len(fits.open(filelike)) == 5
示例#5
0
    def test_read_file_like_object(self):
        """Test reading a FITS file from a file-like object."""

        filelike = BytesIO()
        with open(self.data("test0.fits"), "rb") as f:
            filelike.write(f.read())
        filelike.seek(0)
        with ignore_warnings():
            assert_equal(len(pyfits.open(filelike)), 5)
示例#6
0
    def test_open_file_with_end_padding(self):
        """Regression test for #106; open files with end padding bytes."""

        hdul = pyfits.open(self.data('test0.fits'),
                           do_not_scale_image_data=True)
        info = hdul.info(output=False)
        hdul.writeto(self.temp('temp.fits'))
        with open(self.temp('temp.fits'), 'ab') as f:
            f.seek(0, os.SEEK_END)
            f.write('\0'.encode('latin1') * 2880)
        with ignore_warnings():
            assert_equal(info,
                         pyfits.info(self.temp('temp.fits'), output=False,
                                     do_not_scale_image_data=True))
示例#7
0
    def test_rewriting_large_scaled_image(self):
        """Regression test for #84 and #101."""

        hdul = pyfits.open(self.data('fixed-1890.fits'))
        orig_data = hdul[0].data
        with ignore_warnings():
            hdul.writeto(self.temp('test_new.fits'), clobber=True)
        hdul.close()
        hdul = pyfits.open(self.temp('test_new.fits'))
        assert_true((hdul[0].data == orig_data).all())
        hdul.close()

        # Just as before, but this time don't touch hdul[0].data before writing
        # back out--this is the case that failed in #84
        hdul = pyfits.open(self.data('fixed-1890.fits'))
        with ignore_warnings():
            hdul.writeto(self.temp('test_new.fits'), clobber=True)
        hdul.close()
        hdul = pyfits.open(self.temp('test_new.fits'))
        assert_true((hdul[0].data == orig_data).all())
        hdul.close()

        # Test opening/closing/reopening a scaled file in update mode
        hdul = pyfits.open(self.data('fixed-1890.fits'),
                           do_not_scale_image_data=True)
        hdul.writeto(self.temp('test_new.fits'), clobber=True,
                     output_verify='silentfix')
        hdul.close()
        hdul = pyfits.open(self.temp('test_new.fits'))
        orig_data = hdul[0].data
        hdul.close()
        hdul = pyfits.open(self.temp('test_new.fits'), mode='update')
        hdul.close()
        hdul = pyfits.open(self.temp('test_new.fits'))
        assert_true((hdul[0].data == orig_data).all())
        hdul = pyfits.open(self.temp('test_new.fits'))
        hdul.close()
示例#8
0
文件: test_core.py 项目: coleb/PyFITS
    def test_detect_zipped(self):
        """Test detection of a zip file when the extension is not .zip."""

        zf = self._make_zip_file(filename='test0.fz')
        with ignore_warnings():
            assert len(fits.open(zf)) == 5
示例#9
0
文件: test_core.py 项目: coleb/PyFITS
 def test_open_zipped(self):
     with ignore_warnings():
         assert len(fits.open(self._make_zip_file())) == 5
示例#10
0
文件: test_core.py 项目: coleb/PyFITS
    def test_detect_gzipped(self):
        """Test detection of a gzip file when the extension is not .gz."""

        with ignore_warnings():
            assert len(fits.open(self._make_gzip_file('test0.fz'))) == 5
示例#11
0
 def test_open_zipped(self):
     with ignore_warnings():
         assert_equal(len(pyfits.open(self._make_zip_file())), 5)
示例#12
0
    def test_detect_gzipped(self):
        """Test detection of a gzip file when the extension is not .gz."""

        with ignore_warnings():
            assert_equal(len(pyfits.open(self._make_gzip_file("test0.fz"))), 5)