This file is indexed.

/usr/share/pyshared/pyfits/tests/testPyfitsChecksum.py is in python-pyfits 1:2.4.0-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
from __future__ import division # confidence high

import unittest
import warnings 

import pyfits
import numpy
import numpy as np
import exceptions,os,sys
import os.path

test_dir = os.path.dirname(__file__) + "/"

# Define a junk file for redirection of stdout
jfile = "junkfile.fits"

class TestPyfitsChecksumFunctions(unittest.TestCase):

    def setUp(self):
        # Perform set up actions (if any)
        pass

    def tearDown(self):
        # Perform clean-up actions (if any)
        try:
            os.remove('tmp.fits')
        except:
            pass

    def testSampleFile(self):
        hdul=pyfits.open(test_dir+'checksum.fits',checksum=True)
        hdul.close()

    def testImageCreate(self):
        n=np.arange(100)
        hdu=pyfits.PrimaryHDU(n)
        hdu.writeto('tmp.fits',clobber=True,checksum=True)
        hdul=pyfits.open('tmp.fits',checksum=True)
        hdul.close()
        os.remove('tmp.fits')
        
    def testNonstandardChecksum(self):
        warnings.filterwarnings("error", message="Warning:  Checksum verification failed")
        warnings.filterwarnings("error", message="Warning:  Datasum verification failed")
        hdu = pyfits.PrimaryHDU(np.arange(10.**6))
        hdu.writeto('tmp.fits', clobber=True, checksum="nonstandard")
        del hdu      
        hdul = pyfits.open("tmp.fits", checksum="nonstandard")   # should pass
        self.assertRaises(UserWarning, pyfits.open, "tmp.fits", checksum=True)
        self.assertRaises(UserWarning, pyfits.open, "tmp.fits", checksum="standard")
        warnings.filterwarnings("default", message="Warning:  Checksum verification failed")
        warnings.filterwarnings("default", message="Warning:  Datasum verification failed")
        os.remove("tmp.fits")
    
    def testScaledData(self):
        hdul=pyfits.open(test_dir+'scale.fits')
        hdul[0].scale('int16','old')
        hdul.writeto('tmp.fits',clobber=True,checksum=True)
        hdul1=pyfits.open('tmp.fits',checksum=True)
        hdul.close()
        hdul1.close()
        os.remove('tmp.fits')

    def testUint16Data(self):
        hdul=pyfits.open(test_dir+'o4sp040b0_raw.fits',uint16=1)
        hdul.writeto('tmp.fits',clobber=True,checksum=True)
        hdul1=pyfits.open('tmp.fits',uint16=1,checksum=True)
        hdul.close()
        hdul1.close()
        os.remove('tmp.fits')

    def testGroupsHDUData(self):
        imdata = np.arange(100.)
        imdata.shape=(10,1,1,2,5)
        pdata1 = np.arange(10)+0.1
        pdata2 = 42
        x = pyfits.GroupData(imdata,parnames=['abc','xyz'],
                             pardata=[pdata1,pdata2],bitpix=-32)
        hdu=pyfits.GroupsHDU(x)
        hdu.writeto('tmp.fits',clobber=True,checksum=True)
        hdul1=pyfits.open('tmp.fits',checksum=True)
        hdul1.close()
        os.remove('tmp.fits')

    def testBinaryTableData(self):
        a1 = np.array(['NGC1001','NGC1002','NGC1003'])
        a2 = np.array([11.1,12.3,15.2])
        col1 = pyfits.Column(name='target',format='20A',array=a1)
        col2=pyfits.Column(name='V_mag',format='E',array=a2)
        cols=pyfits.ColDefs([col1, col2])
        tbhdu=pyfits.new_table(cols)
        tbhdu.writeto('tmp.fits',clobber=True,checksum=True)
        hdul=pyfits.open('tmp.fits',checksum=True)
        hdul.close()
        os.remove('tmp.fits')

    def testVariableLengthTableData(self):
        c1 = pyfits.Column(name='var',format='PJ()',\
             array=np.array([[45.,56],np.array([11,12,13])],'O'))
        c2 = pyfits.Column(name='xyz',format='2I',array=[[11,3],[12,4]])
        tbhdu=pyfits.new_table([c1,c2])
        tbhdu.writeto('tmp.fits',clobber=True,checksum=True)
        hdul=pyfits.open('tmp.fits',checksum=True)
        hdul.close()
        os.remove('tmp.fits')

    def testAsciiTableData(self):
        a1 = np.array(['abc','def'])
        r1 = np.array([11.,12.])
        c1 = pyfits.Column(name='abc', format='A3', array=a1)
        c2 = pyfits.Column(name='def', format='E', array=r1, bscale=2.3,
                           bzero=0.6)
        c3 = pyfits.Column(name='t1', format='I', array=[91,92,93])
        x = pyfits.ColDefs([c1,c2,c3], tbtype='TableHDU')
        hdu = pyfits.new_table(x, tbtype='TableHDU')
        hdu.writeto('tmp.fits', clobber=True, checksum=True)
        hdul=pyfits.open('tmp.fits', checksum=True)
        hdul.close()
        os.remove('tmp.fits')

    def testCompressedImageData(self):
        hdul=pyfits.open(test_dir+'comp.fits')
        hdul.writeto('tmp.fits',clobber=True,checksum=True)
        hdul1=pyfits.open('tmp.fits',checksum=True)
        hdul1.close()
        os.remove('tmp.fits')
        n=np.arange(100,dtype='int16')
        hdu=pyfits.ImageHDU(n)
        comp_hdu = pyfits.CompImageHDU(hdu.data, hdu.header)
        comp_hdu.writeto('tmp.fits',checksum=True)
        hdul.close()
        hdul=pyfits.open('tmp.fits',checksum=True)
        hdul.close()
        os.remove('tmp.fits')
        n=np.arange(100, dtype='float32')
        comp_hdu = pyfits.CompImageHDU(n)
        comp_hdu.writeto('tmp.fits',checksum=True)
        hdul.close()
        hdul=pyfits.open('tmp.fits',checksum=True)
        hdul.close()
        os.remove('tmp.fits')

    def testOpenWithNoKeywords(self):
        hdul=pyfits.open(test_dir+'arange.fits',checksum=True)
        hdul.close()

    def testAppend(self):
        hdul=pyfits.open(test_dir+'tb.fits')
        hdul.writeto('tmp.fits', clobber=True)
        n=np.arange(100)
        pyfits.append('tmp.fits',n,checksum=True)
        hdul.close()
        hdul=pyfits.open('tmp.fits',checksum=True)
        self.assertEqual(hdul[0]._checksum, None)
        hdul.close()
        os.remove('tmp.fits')

    def testWritetoConvenience(self):
        n=np.arange(100)
        pyfits.writeto('tmp.fits',n,clobber=True,checksum=True)
        hdul=pyfits.open('tmp.fits',checksum=True)

        if not hasattr(hdul[0], '_datasum') or not hdul[0]._datasum:
            os.remove('tmp.fits')
            self.fail(msg="Missing DATASUM keyword")

        if not hasattr(hdul[0], '_checksum') or not hdul[0]._checksum:
            os.remove('tmp.fits')
            self.fail(msg="Missing CHECKSUM keyword")

        if not hasattr(hdul[0], '_datasum_comment') or \
           not hdul[0]._datasum_comment:
            os.remove('tmp.fits')
            self.fail(msg="Missing DATASUM Card comment")

        if not hasattr(hdul[0], '_checksum_comment') or \
           not hdul[0]._checksum_comment:
            os.remove('tmp.fits')
            self.fail(msg="Missing CHECKSUM Card comment")

        hdul.close()
        os.remove('tmp.fits')

    def testHduWriteto(self):
        n=np.arange(100,dtype='int16')
        hdu=pyfits.ImageHDU(n)
        hdu.writeto('tmp.fits',checksum=True)
        hdul=pyfits.open('tmp.fits',checksum=True)

        if not hasattr(hdul[0], '_datasum') or not hdul[0]._datasum:
            os.remove('tmp.fits')
            self.fail(msg="Missing DATASUM keyword")

        if not hasattr(hdul[0], '_checksum') or not hdul[0]._checksum:
            os.remove('tmp.fits')
            self.fail(msg="Missing CHECKSUM keyword")

        if not hasattr(hdul[0], '_datasum_comment') or \
           not hdul[0]._datasum_comment:
            os.remove('tmp.fits')
            self.fail(msg="Missing DATASUM Card comment")

        if not hasattr(hdul[0], '_checksum_comment') or \
           not hdul[0]._checksum_comment:
            os.remove('tmp.fits')
            self.fail(msg="Missing CHECKSUM Card comment")

        hdul.close()
        os.remove('tmp.fits')

    def testDatasumOnly(self):
        n=np.arange(100,dtype='int16')
        hdu=pyfits.ImageHDU(n)
        hdu.writeto('tmp.fits',clobber=True,checksum='datasum')
        hdul=pyfits.open('tmp.fits',checksum=True)

        if not hasattr(hdul[0], '_datasum') or not hdul[0]._datasum:
            os.remove('tmp.fits')
            self.fail(msg="Missing DATASUM keyword")

        if not hasattr(hdul[0], '_checksum') or hdul[0]._checksum:
            os.remove('tmp.fits')
            self.fail(msg="Missing CHECKSUM keyword")

        if not hasattr(hdul[0], '_datasum_comment') or \
           not hdul[0]._datasum_comment:
            os.remove('tmp.fits')
            self.fail(msg="Missing DATASUM Card comment")

        if not hasattr(hdul[0], '_checksum_comment') or \
           hdul[0]._checksum_comment:
            os.remove('tmp.fits')
            self.fail(msg="Missing CHECKSUM Card comment")

        hdul.close()
        os.remove('tmp.fits')



if __name__ == '__main__':
    unittest.main()