def test_invalid_fields(self): """ Test the invalid field handling. """ log.debug("Running test_invalid_fields") filename = "invalid_fields.DAT" with open(os.path.join(RESOURCE_PATH, filename), 'r') as file_handle: self.parser = NutnrBParser(self.config, file_handle, self.exception_callback) particles = self.parser.get_records(1000) log.debug("Num particles: %d", len(particles)) self.assertEqual(len(particles), 3) self.assert_particles(particles, 'invalid_fields.yml', RESOURCE_PATH) self.assertEqual(self._exceptions_detected, 31) log.debug("Exceptions: %d", self._exceptions_detected)
def test_missing_metadata(self): """ Test the missing metadata handling. """ log.debug("Running test_missing_metadata") filename = "missing_metadata.DAT" with open(os.path.join(RESOURCE_PATH, filename), 'r') as file_handle: self.parser = NutnrBParser(self.config, file_handle, self.exception_callback) particles = self.parser.get_records(1000) log.debug("Num particles: %d", len(particles)) self.assertEqual(len(particles), 9) self.assert_particles(particles, 'missing_metadata.yml', RESOURCE_PATH) self.assertEqual(self._exceptions_detected, 1) log.debug("Exceptions: %d", self._exceptions_detected)
def test_happy_path(self): """ Test the happy path of operations where the parser takes the input and spits out a valid data particle given the stream. """ log.debug("Running test_happy_path") filename = "happy_path.DAT" with open(os.path.join(RESOURCE_PATH, filename), 'r') as file_handle: self.parser = NutnrBParser(self.config, file_handle, self.exception_callback) particles = self.parser.get_records(1000) log.debug("Num particles: %d", len(particles)) self.assertEqual(len(particles), 17) self.assert_particles(particles, 'happy_path.yml', RESOURCE_PATH) self.assertEqual(self._exceptions_detected, 0) log.debug("Exceptions: %d", self._exceptions_detected)
def parse(basePythonCodePath, sourceFilePath, particleDataHdlrObj): config.add_configuration( os.path.join(basePythonCodePath, 'res', 'config', 'mi-logging.yml')) log = get_logger() parser_config = { DataSetDriverConfigKeys.PARTICLE_MODULE: 'mi.dataset.parser.nutnr_b_particles', DataSetDriverConfigKeys.PARTICLE_CLASS: [ 'NutnrBMetadataRecoveredDataParticle', 'NutnrBInstrumentRecoveredDataParticle' ] } def exception_callback(exception): log.debug("ERROR: " + exception) particleDataHdlrObj.setParticleDataCaptureFailure() with open(sourceFilePath, 'r') as stream_handle: parser = NutnrBParser(parser_config, stream_handle, exception_callback) driver = DataSetDriver(parser, particleDataHdlrObj) driver.processFileStream() return particleDataHdlrObj
def parse(unused, source_file_path, particle_data_handler): parser_config = { DataSetDriverConfigKeys.PARTICLE_MODULE: 'mi.dataset.parser.nutnr_b_particles', DataSetDriverConfigKeys.PARTICLE_CLASS: [ 'NutnrBMetadataRecoveredDataParticle', 'NutnrBInstrumentRecoveredDataParticle' ] } def exception_callback(exception): log.debug("ERROR: %r", exception) particle_data_handler.setParticleDataCaptureFailure() with open(source_file_path, 'r') as stream_handle: parser = NutnrBParser(parser_config, stream_handle, exception_callback) driver = DataSetDriver(parser, particle_data_handler) driver.processFileStream() return particle_data_handler
class NutnrBParserUnitTestCase(ParserUnitTestCase): """ NutnrBParser unit test suite """ def setUp(self): ParserUnitTestCase.setUp(self) self.config = { DataSetDriverConfigKeys.PARTICLE_MODULE: 'mi.dataset.parser.nutnr_b_particles', DataSetDriverConfigKeys.PARTICLE_CLASS: None, } self._exceptions_detected = 0 def exception_callback(self, exception): log.debug("Exception received: %s", exception) self._exceptions_detected += 1 def test_happy_path(self): """ Test the happy path of operations where the parser takes the input and spits out a valid data particle given the stream. """ log.debug("Running test_happy_path") filename = "happy_path.DAT" with open(os.path.join(RESOURCE_PATH, filename), 'r') as file_handle: self.parser = NutnrBParser(self.config, file_handle, self.exception_callback) particles = self.parser.get_records(1000) log.debug("Num particles: %d", len(particles)) self.assertEqual(len(particles), 17) self.assert_particles(particles, 'happy_path.yml', RESOURCE_PATH) self.assertEqual(self._exceptions_detected, 0) log.debug("Exceptions: %d", self._exceptions_detected) def test_invalid_fields(self): """ Test the invalid field handling. """ log.debug("Running test_invalid_fields") filename = "invalid_fields.DAT" with open(os.path.join(RESOURCE_PATH, filename), 'r') as file_handle: self.parser = NutnrBParser(self.config, file_handle, self.exception_callback) particles = self.parser.get_records(1000) log.debug("Num particles: %d", len(particles)) self.assertEqual(len(particles), 3) self.assert_particles(particles, 'invalid_fields.yml', RESOURCE_PATH) self.assertEqual(self._exceptions_detected, 31) log.debug("Exceptions: %d", self._exceptions_detected) def test_missing_metadata(self): """ Test the missing metadata handling. """ log.debug("Running test_missing_metadata") filename = "missing_metadata.DAT" with open(os.path.join(RESOURCE_PATH, filename), 'r') as file_handle: self.parser = NutnrBParser(self.config, file_handle, self.exception_callback) particles = self.parser.get_records(1000) log.debug("Num particles: %d", len(particles)) self.assertEqual(len(particles), 9) self.assert_particles(particles, 'missing_metadata.yml', RESOURCE_PATH) self.assertEqual(self._exceptions_detected, 1) log.debug("Exceptions: %d", self._exceptions_detected) def test_missing_instrument_data(self): """ Test the missing instrument handling. """ log.debug("Running test_missing_instrument_data") filename = "missing_instrument_data.DAT" with open(os.path.join(RESOURCE_PATH, filename), 'r') as file_handle: self.parser = NutnrBParser(self.config, file_handle, self.exception_callback) particles = self.parser.get_records(1000) log.debug("Num particles: %d", len(particles)) self.assertEqual(len(particles), 5) self.assert_particles(particles, 'missing_instrument_data.yml', RESOURCE_PATH) self.assertEqual(self._exceptions_detected, 4) log.debug("Exceptions: %d", self._exceptions_detected)