def test_happy_path(self): """ Read files and verify that all expected particles can be read. Verify that the contents of the particles are correct. There should be no exceptions generated. """ log.debug('===== START TEST HAPPY PATH =====') with open(os.path.join(RESOURCE_PATH, 'ctdmo01_20140712_120719.DAT'), 'r') as file_handle: parser = CtdmoGhqrImodemParser(self._telemetered_config, file_handle, self.exception_callback) particles = parser.get_records(1000) self.assertEqual(self.exception_callback_value, []) self.particle_to_yml(particles, 'ctdmo01_20140712_120719_telem.yml') self.assert_particles(particles, "ctdmo01_20140712_120719_telem.yml", RESOURCE_PATH) with open(os.path.join(RESOURCE_PATH, 'ctdmo01_20140712_120719.DAT'), 'r') as file_handle: parser = CtdmoGhqrImodemParser(self._recovered_config, file_handle, self.exception_callback) particles = parser.get_records(1000) self.assertEqual(self.exception_callback_value, []) self.particle_to_yml(particles, 'ctdmo01_20140712_120719_recov.yml') self.assert_particles(particles, "ctdmo01_20140712_120719_recov.yml", RESOURCE_PATH) self.assertEqual(self.exception_callback_value, []) log.debug('===== END TEST HAPPY PATH =====')
def test_unexpected_data(self): """ This test verifies that an unexpected data exception is reported when unexpected data is found. """ log.debug('===== START TEST UNEXPECTED DATA =====') with open(os.path.join(RESOURCE_PATH, 'unexpected_data.DAT'), 'r') as file_handle: parser = CtdmoGhqrImodemParser(self._telemetered_config, file_handle, self.exception_callback) parser.get_records(1) self.assertEqual(len(self.exception_callback_value), 2) for exception in self.exception_callback_value: self.assertIsInstance(exception, UnexpectedDataException) log.debug('===== END TEST UNEXPECTED DATA =====')
def _build_parser(self, stream_handle): parser_config = { DataSetDriverConfigKeys.PARTICLE_MODULE: 'mi.dataset.parser.ctdmo_ghqr_imodem', DataSetDriverConfigKeys.PARTICLE_CLASS: None, DataSetDriverConfigKeys.PARTICLE_CLASSES_DICT: { CtdmoGhqrImodemParticleClassKey.METADATA_PARTICLE_CLASS: CtdmoGhqrImodemMetadataRecoveredDataParticle, CtdmoGhqrImodemParticleClassKey.INSTRUMENT_PARTICLE_CLASS: CtdmoGhqrImodemInstrumentRecoveredDataParticle, } } parser = CtdmoGhqrImodemParser(parser_config, stream_handle, self._exception_callback) return parser
def test_bad_config(self): """ The test ensures that a ConfigurationException is raised when providing the parser invalid configuration """ log.debug('===== START TEST BAD CONFIG =====') with self.assertRaises(ConfigurationException): with open( os.path.join(RESOURCE_PATH, 'ctdmo01_20140712_120719.DAT'), 'r') as file_handle: config = { DataSetDriverConfigKeys.PARTICLE_MODULE: 'mi.dataset.parser.ctdmo_ghqr_imodem', DataSetDriverConfigKeys.PARTICLE_CLASS: None, DataSetDriverConfigKeys.PARTICLE_CLASSES_DICT: None } CtdmoGhqrImodemParser(config, file_handle, self.exception_callback) log.debug('===== END TEST BAD CONFIG =====')