'A simple test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/120
The scale_back feature for image HDUs.'

def test_scale_back(self):

    self.copy_file('scale.fits')
    with fits.open(self.temp('scale.fits'), mode='update', scale_back=True) as hdul:
        orig_bitpix = hdul[0].header['BITPIX']
        orig_bzero = hdul[0].header['BZERO']
        orig_bscale = hdul[0].header['BSCALE']
        orig_data = hdul[0].data.copy()
        hdul[0].data[0] = 0
    with fits.open(self.temp('scale.fits'), do_not_scale_image_data=True) as hdul:
        assert (hdul[0].header['BITPIX'] == orig_bitpix)
        assert (hdul[0].header['BZERO'] == orig_bzero)
        assert (hdul[0].header['BSCALE'] == orig_bscale)
        zero_point = int(math.floor(((- orig_bzero) / orig_bscale)))
        assert (hdul[0].data[0] == zero_point).all()
    with fits.open(self.temp('scale.fits')) as hdul:
        assert (hdul[0].data[1:] == orig_data[1:]).all()
