def setUp(self): self.filename = tempfile.mktemp('.txt') self.f = input.EgadsFile(self.filename, 'w') self.strdata1ln = 'testtesttest\n' self.strdata2ln = 'testtesttest\n testtesttest\n' self.intdata = [123, 456]
def setUp(self): self.nafilename = tempfile.mktemp('.na') f = input.EgadsFile(self.nafilename, 'w') f.write(NAFILETEXT) f.close() self.ncfilename = tempfile.mktemp('.nc') f = netCDF4.Dataset(self.ncfilename, 'w') f.attribute = GLOBAL_ATTRIBUTE f.Conventions = CONVENTIONS f.title = TITLE f.source = SOURCE f.institution = INSTITUTION f.project = PROJECT f.createDimension(DIM1_NAME, DIM1_LEN) f.createDimension(DIM2_NAME, DIM2_LEN) v1 = f.createVariable(VAR_NAME, 'f8', (DIM1_NAME)) v2 = f.createVariable(VAR_MULT_NAME, 'f8', (DIM1_NAME, DIM2_NAME)) v1.units = VAR_UNITS v2.units = VAR_MULT_UNITS v1.long_name = VAR_LONG_NAME v1.standard_name = VAR_STD_NAME v1.Category = CATEGORY v1[:] = random_data v2[:] = random_mult_data f.close() self.nc_out_name = tempfile.mktemp('.nc') self.csv_out_name = tempfile.mktemp('.csv') self.na_out_name = tempfile.mktemp('.na')
def test_seek_file(self): """ Test file seek function """ f = input.EgadsFile(self.filename, 'r') f.seek(3) data = f.read(1) self.assertEqual(4, f.pos, 'Positions do not match') self.assertEqual(self.strdata2ln[3], data, 'Data from pos 3 does not match') f.seek(3, 'c') data = f.read(1) self.assertEqual(8, f.pos, 'Positions do not match') self.assertEqual(self.strdata2ln[7], data, 'Data from pos 7 does not match') f.seek(4) data = f.read(1) self.assertEqual(5, f.pos, 'Positions do not match') self.assertEqual(self.strdata2ln[4], data, 'Data from pos 3 does not match') f.close()
def test_read_data_one_line(self): """ Test reading one line of data from file """ f = einput.EgadsFile(self.filename, 'r') data = f.read_line() self.assertEqual(self.strdata1ln, data, 'One line data does not match') f.close()
def test_open_file(self): """ Test opening of file """ f = einput.EgadsFile(self.filename, 'r') self.assertEqual(f.filename, self.filename, 'Filenames do not match') self.assertRaises(IOError, einput.EgadsFile, 'nofile.txt') self.assertEqual(f.pos, 0, 'File position is not correct') f.close()
def test_read_data(self): """ Test reading data from file """ f = einput.EgadsFile(self.filename, 'r') data = f.read() self.assertEqual(self.strdata2ln, data, 'Data read in does not match') f.reset() data = f.read(4) self.assertEqual(self.strdata2ln[0:4], data, 'Characters read in do not match') f.close()
def setUp(self): self.filename = tempfile.mktemp('.na') f = einput.EgadsFile(self.filename, 'w') f.write(NAFILETEXT) f.close() self.originator = 'John Doe; email: [email protected]' self.org = 'ORGANIS' self.scom = [ 'This is a test file for verifying the status of the EGADS NASA Ames functionality.' ] self.var_names = [ 'GPS LAT', 'GPS LON', 'Height above sea level', 'Time2' ] self.units = ['degrees', 'degrees', 'm', 'seconds after midnight'] self.miss_vals = [-9900.0, -9900.0, -9900.0, -9900.0] self.time_max = 51147.42 self.time_min = 51143.42 self.GPS_LON_max = 11.2778 self.GPS_LON_min = 11.2809