def stream_config(cls): return [ OptaaDjDclRecoveredInstrumentDataParticle.type(), OptaaDjDclRecoveredMetadataDataParticle.type(), OptaaDjDclTelemeteredInstrumentDataParticle.type(), OptaaDjDclTelemeteredMetadataDataParticle.type() ]
def test_get_many(self): """ Read a file and pull out multiple data particles at one time. Verify that the results are those we expected. """ log.debug('===== START TEST GET MANY RECOVERED =====') in_file = self.open_file(FILE2) parser = self.create_rec_parser(in_file, FILE2) # Generate a list of expected result particles. expected_particle = [] for count, expected in enumerate(EXPECTED_FILE2): ntp_time, fields = expected # Generate expected particle if count == 0: particle = OptaaDjDclRecoveredMetadataDataParticle( fields, internal_timestamp=ntp_time) else: particle = OptaaDjDclRecoveredInstrumentDataParticle( fields, internal_timestamp=ntp_time) expected_particle.append(particle) # In a single read, get all particles for this file. result = parser.get_records(len(expected_particle)) self.assertEqual(result, expected_particle) self.assertEqual(self.rec_exception_callback_value, None) in_file.close() log.debug('===== START TEST GET MANY TELEMETERED =====') in_file = self.open_file(FILE3) parser = self.create_tel_parser(in_file, FILE3) # Generate a list of expected result particles. expected_particle = [] for count, expected in enumerate(EXPECTED_FILE3): ntp_time, fields = expected # Generate expected particle if count == 0: particle = OptaaDjDclTelemeteredMetadataDataParticle( fields, internal_timestamp=ntp_time) else: particle = OptaaDjDclTelemeteredInstrumentDataParticle( fields, internal_timestamp=ntp_time) expected_particle.append(particle) # In a single read, get all particles for this file. result = parser.get_records(len(expected_particle)) self.assertEqual(result, expected_particle) self.assertEqual(self.tel_exception_callback_value, None) in_file.close() log.debug('===== END TEST GET MANY =====')
def test_simple(self): """ Read data from a file and pull out data particles one at a time. Verify that the results are those we expected. """ log.debug('===== START TEST SIMPLE RECOVERED =====') in_file = self.open_file(FILE1) parser = self.create_rec_parser(in_file, FILE1) for count, expected in enumerate(EXPECTED_FILE1): ntp_time, fields = expected # Generate expected particle if count == 0: expected_particle = \ OptaaDjDclRecoveredMetadataDataParticle(fields, internal_timestamp=ntp_time) else: expected_particle = \ OptaaDjDclRecoveredInstrumentDataParticle(fields, internal_timestamp=ntp_time) # Get record and verify. result = parser.get_records(1) self.assertEqual(result, [expected_particle]) self.assertEqual(self.rec_exception_callback_value, None) in_file.close() log.debug('===== START TEST SIMPLE TELEMETERED =====') in_file = self.open_file(FILE2) parser = self.create_tel_parser(in_file, FILE2) for count, expected in enumerate(EXPECTED_FILE2): ntp_time, fields = expected # Generate expected particle if count == 0: expected_particle = \ OptaaDjDclTelemeteredMetadataDataParticle(fields, internal_timestamp=ntp_time) else: expected_particle = \ OptaaDjDclTelemeteredInstrumentDataParticle(fields, internal_timestamp=ntp_time) # Get record and verify. result = parser.get_records(1) self.assertEqual(result, [expected_particle]) self.assertEqual(self.tel_exception_callback_value, None) in_file.close() log.debug('===== END TEST SIMPLE =====')
def test_set_state(self): """ This test verifies that the state can be changed after starting. Some particles are read and then the parser state is modified to skip ahead or back. """ log.debug('===== START TEST SET STATE RECOVERED =====') in_file = self.open_file(FILE6) parser = self.create_rec_parser(in_file, FILE6) # Read and verify 4 particles (of the 11). # 1 metadata particle, 3 instrument particles. for count, expected in enumerate(EXPECTED_FILE6[:4]): ntp_time, fields = expected # Generate expected particle if count == 0: expected_particle = \ OptaaDjDclRecoveredMetadataDataParticle(fields, internal_timestamp=ntp_time) else: expected_particle = \ OptaaDjDclRecoveredInstrumentDataParticle(fields, internal_timestamp=ntp_time) # Get record and verify. result = parser.get_records(1) self.assertEqual(result, [expected_particle]) # Skip ahead in the file so that we get the last 3 particles. new_state = { OptaaStateKey.POSITION: 469, OptaaStateKey.METADATA_GENERATED: True, OptaaStateKey.TIME_SINCE_POWER_UP: 0.666 } # Set the state. parser.set_state(new_state) # Read and verify the last 3 particles. for count, expected in enumerate(EXPECTED_FILE6[-3:]): ntp_time, fields = expected expected_particle = \ OptaaDjDclRecoveredInstrumentDataParticle(fields, internal_timestamp=ntp_time) # Get record and verify. result = parser.get_records(1) self.assertEqual(result, [expected_particle]) in_file.close() log.debug('===== START TEST SET STATE TELEMETERED =====') in_file = self.open_file(FILE6) parser = self.create_rec_parser(in_file, FILE6) # Read and verify 8 particles (of the 11). # 1 metadata particle, 7 instrument particles. for count, expected in enumerate(EXPECTED_FILE6[:8]): ntp_time, fields = expected # Generate expected particle if count == 0: expected_particle = \ OptaaDjDclTelemeteredMetadataDataParticle(fields, internal_timestamp=ntp_time) else: expected_particle = \ OptaaDjDclTelemeteredInstrumentDataParticle(fields, internal_timestamp=ntp_time) # Get record and verify. result = parser.get_records(1) self.assertEqual(result, [expected_particle]) # Go back in the file so that we get the last 8 particles. new_state = { OptaaStateKey.POSITION: 94, OptaaStateKey.METADATA_GENERATED: True, OptaaStateKey.TIME_SINCE_POWER_UP: 0.666 } # Set the state. parser.set_state(new_state) # Read and verify the last 8 particles. for count, expected in enumerate(EXPECTED_FILE6[-8:]): ntp_time, fields = expected expected_particle = \ OptaaDjDclTelemeteredInstrumentDataParticle(fields, internal_timestamp=ntp_time) # Get record and verify. result = parser.get_records(1) self.assertEqual(result, [expected_particle]) in_file.close() log.debug('===== END TEST SET STATE =====')
def test_mid_state_start(self): """ Test starting a parser with a state in the middle of processing. """ log.debug('===== START TEST MID-STATE START RECOVERED =====') in_file = self.open_file(FILE2) # Start at the beginning of record 4 (of 5 total) initial_state = { OptaaStateKey.POSITION: 177, OptaaStateKey.METADATA_GENERATED: True, OptaaStateKey.TIME_SINCE_POWER_UP: 0.222 } parser = self.create_rec_parser(in_file, FILE2, new_state=initial_state) # Generate a list of expected result particles. expected_particle = [] for count, expected in enumerate(EXPECTED_FILE2): if count >= 4: ntp_time, fields = expected particle = OptaaDjDclRecoveredInstrumentDataParticle( fields, internal_timestamp=ntp_time) expected_particle.append(particle) # Get record and verify. result = parser.get_records(len(expected_particle)) self.assertEqual(result, expected_particle) in_file.close() log.debug('===== START TEST MID-STATE START TELEMETERED =====') in_file = self.open_file(FILE1) # Start at the beginning of record 3 (of 3 total) initial_state = { OptaaStateKey.POSITION: 102, OptaaStateKey.METADATA_GENERATED: True, OptaaStateKey.TIME_SINCE_POWER_UP: 0.111 } parser = self.create_rec_parser(in_file, FILE1, new_state=initial_state) # Generate a list of expected result particles. expected_particle = [] for count, expected in enumerate(EXPECTED_FILE1): if count >= 3: ntp_time, fields = expected particle = OptaaDjDclTelemeteredInstrumentDataParticle( fields, internal_timestamp=ntp_time) expected_particle.append(particle) # Get record and verify. result = parser.get_records(len(expected_particle)) self.assertEqual(result, expected_particle) in_file.close() log.debug('===== END TEST MID-STATE START =====')