'Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/79
Tests that when a FITS file is modified in update mode, the file
permissions are preserved.'

def test_updated_file_permissions(self):

    filename = self.temp('test.fits')
    hdul = [fits.PrimaryHDU(), fits.ImageHDU()]
    hdul = fits.HDUList(hdul)
    hdul.writeto(filename)
    old_mode = os.stat(filename).st_mode
    hdul = fits.open(filename, mode='update')
    hdul.insert(1, fits.ImageHDU())
    hdul.flush()
    hdul.close()
    assert (old_mode == os.stat(filename).st_mode)
