def test_Fstdc_fstrwd(self): """Fstdc_fstrwd should reset file pointer to begining of file""" (la,lo) = self.create_basefile() #wrote 2 recs in that order: la, lo f2 = rpnstd.RPNFile(self.fname) la2 = f2[rpnstd.FirstRecord] lo2 = f2[rpnstd.NextMatch] r2none = None try: r2none = f2[rpnstd.NextMatch] except: pass la3 = f2[rpnstd.RPNMeta(nom='LA')] lo3 = f2[rpnstd.RPNMeta(nom='LO')] la4 = f2[rpnstd.RPNMeta(nom='LA')] #r3none = None #try: # r3none = f2[rpnstd.FirstRecord] #except: # pass #TODO f2.rewind() #... looks like fstrwd is not needed... and return an exception! :-( r4 = f2[rpnstd.FirstRecord] f2.close() self.assertEqual(la2.nom,la.nom) self.assertEqual(lo2.nom,lo.nom) self.assertEqual(r2none,None) #self.assertEqual(r3none,None) self.assertEqual(la3.nom,la.nom) self.assertEqual(lo3.nom,lo.nom) self.assertEqual(la4.nom,la.nom) self.assertEqual(r4.nom,la.nom) self.erase_testfile()
def test_RPNFileRead_KnownValues(self): """RPNFile should give known result with known input""" (la,lo) = self.create_basefile() #wrote 2 recs in that order: la, lo #print "============ Read Test ===============" f2 = rpnstd.RPNFile(self.fname) la2 = f2[rpnstd.FirstRecord] lo2 = f2[rpnstd.NextMatch] r2none = None try: r2none = f2[rpnstd.NextMatch] except: pass f2.close() self.assertEqual(la2.nom,la.nom) self.assertEqual(lo2.nom,lo.nom) self.assertEqual(r2none,None) if numpy.any(la2.d!=la.d): print 'la2:',la2.d print 'la :',la.d self.assertFalse(numpy.any(la2.d!=la.d)) if numpy.any(lo2.d!=lo.d): print 'lo2:',lo2.d print 'lo :',lo.d self.assertFalse(numpy.any(lo2.d!=lo.d)) self.erase_testfile()
def create_basefile(self): """create a basic test file for RPNFile tests""" #print("============ Create Base File ===============") self.erase_testfile() f = rpnstd.RPNFile(self.fname) (ig1, ig2, ig3, ig4) = rpnstd.cxgaig(self.grtyp, self.xg14) r0 = rpnstd.RPNMeta() r0.update(r0.defaultKeysVals()) r0m = rpnstd.RPNMeta(r0, nom='LA', type='C', ni=self.lad.shape[0], nj=self.lad.shape[1], nk=1, grtyp=self.grtyp, ig1=ig1, ig2=ig2, ig3=ig3, ig4=ig4) self.la = rpnstd.RPNRec(data=self.lad, meta=r0m) r0m.nom = 'LO' self.lo = rpnstd.RPNRec(data=self.lod, meta=r0m) f.write(self.la) f.write(self.lo) f.close() return (self.la, self.lo)
def test_RPNFileErase_KnownValues(self): """RPNFile.erase should give known result with known input""" (la,lo) = self.create_basefile() #wrote 2 recs in that order: la, lo #print "============ Erase ===============" f3 = rpnstd.RPNFile(self.fname) f3[la] = None #Erase la (1st rec) - 1st rec is now lo, no 2nd rec f3.close() #print "============ Check Erase ===============" f2 = rpnstd.RPNFile(self.fname) lo2 = f2[rpnstd.FirstRecord] r2none = None try: r2none = f2[rpnstd.NextMatch] except: pass f2.close() self.assertEqual(lo2.nom,lo.nom) self.assertEqual(r2none,None) self.erase_testfile()
def test_RPNFileRewrite_KnownValues(self): """RPNFile.rewrite should give known result with known input""" (la,lo) = self.create_basefile() #print "============ ReWrite/Append ===============" f3 = rpnstd.RPNFile(self.fname) f3.rewrite(lo) #overwrite 2nd rec (lo)... no changes f3.append(la) #append a 3rd rec (la), file now has 3 rec: la, lo, la f3.close() #print "============ Check ReWrite/Append ===============" f2 = rpnstd.RPNFile(self.fname) la2 = f2[rpnstd.FirstRecord] lo2 = f2[rpnstd.NextMatch] la2b= f2[rpnstd.NextMatch] r2none = None try: r2none = f2[rpnstd.NextMatch] except: pass f2.close() self.assertEqual(la2.nom,la.nom) self.assertEqual(lo2.nom,lo.nom) self.assertEqual(la2b.nom,la.nom) self.assertEqual(r2none,None) self.erase_testfile()