Beispiel #1
0
 def test_SofiePyTableAccess_NoneTypes(self):
     writer = SofieCsvPyTableAccess('simple-test-data.h5', '/test',fieldNames={'test1',
                                                                              'test2'})
     writer.write({'test1':0.2,'test2':0.4})
     writer.write({'test1':None,'test2':0.4})
     writer.write({'test1':0.2,'test2':None})
     writer.write({'test1':0.2,'test2':None})
Beispiel #2
0
    def test_getRunsAndGetRunsMetaFromFile(self):
        filename ='simple-test-data.h5'
        writer = AntRawDataAccess(filename, '/test')
        #self.assertEqual(writer.getRuns(),[]);
        writerData = ('1', '2', '3', '4', '5', '6', '7', '8', '9', 111111.101221)
        logging.info('Writing the following data: ' + str(writerData))
        writer.write(writerData)
        logging.info('Came Back from writing.')
        writer.close()

        writer = AntRawDataAccess(filename, '/test')
        self.assertEqual(writer.getRuns(),
            ['/RunMeta','/test/AntRawData']);

        writer.setRunName('again');
        writerData = ('1', '2', '3', '4', '5', '6', '7', '8', '9', 111111.101221)
        logging.info('Writing the following data: ' + str(writerData))
        writer.write(writerData)
        logging.info('Came Back from writing.')

        self.assertEqual(writer.getRuns(),
            ['/RunMeta','/again/AntRawData', '/test/AntRawData']);
        self.assertEqual(writer.getRuns('again'),
            ['/again/AntRawData']);
        self.assertEqual(writer.getRuns('agai'),
            []);
        self.assertEqual(writer.getRuns('agai'),
            []);

        self.assertEqual(writer.getRuns('again/AntRawData'),
            ['/again/AntRawData']);
        writer.close()
        
        #Testing RUNMETA static functions.
        
        theRuns = SofieCsvPyTableAccess.getRunsInTheFile('simple-test-data.h5')
        logging.info('The RUNS: '+ '|'.join(theRuns))
        expected = {'runSubject':'Our Subject','runNotes':'Test\n\nttt'}
        SofieCsvPyTableAccess.setRunMetaInFile(filename,'again',expected)     

        theRunMeta =    SofieCsvPyTableAccess.getRunMetaInFile(filename,'again')     
        logging.info('The Run INFO: {0}'.format(theRunMeta))
        self.assertTrue(all(item in theRunMeta.items() for item in expected.items()))
Beispiel #3
0
    def test_sofiecsvfile_adams_strangenames(self):
        logging.debug('Creating CSV FILE');
        csvFile = adam.open('test-data/test-adams-strangenames.tab')
        logging.debug('CSVFILE CREATED.');
        fieldNames = csvFile.getTableStructure(asList=True)
        logging.debug(fieldNames)
        csvWriter = SofieCsvPyTableAccess('simple-test-data.h5',
            fieldNames=fieldNames, runName='/hello/again/')

        for row in csvFile:
            logging.debug(row)
            csvWriter.write(row)

        csvFile.close()
        csvWriter.close()

        sofieReader = SofieCsvPyTableAccess('simple-test-data.h5',
            '/hello/again/CsvImportData')
        for row in sofieReader:
            logging.debug(row)
            self.assertTrue(row['Timer19'] >= 0)
Beispiel #4
0
 def test_twoWritersAtOnce(self):
     #ASYNC WRITING TO PYTABLES IS NOT RELIABLE.
     csvWriter = SofieCsvPyTableAccess('simple-test-data.h5',
         fieldNames=['test', 'test1'], runName='/hello/again/')
     csvWriter1 = SofieCsvPyTableAccess('simple-test-data.h5',
         fieldNames=['test', 'test1'], runName='/hello/again1/')
     
     theData = {'test':23, 'test1':24}
     theData1 = {'test':25, 'test1':26}
     
     csvWriter.write(theData)
     csvWriter1.write(theData1)
     csvWriter.close()
     csvWriter1.close()
     
     csvReader = SofieCsvPyTableAccess('simple-test-data.h5',
         fieldNames=['test', 'test1'], runName='/hello/again/')
     csvReader1 = SofieCsvPyTableAccess('simple-test-data.h5',
         fieldNames=['test', 'test1'], runName='/hello/again1/')
     for row,row1 in zip(csvReader,csvReader1):
         self.assertEqual(row['test'], 23)
         self.assertEqual(row['test1'], 24)
         self.assertEqual(row1['test'], 25)
         self.assertEqual(row1['test1'], 26)
     csvReader.close()
     csvReader1.close()