def test_ct_real(self):
        """
        Test with a real CT file rather than a generated one
        """
        with open(os.path.join(RESOURCE_PATH, 'SBE37-IM_03710261_2013_07_25.hex'), 'r') as in_file:
            parser = CtdmoGhqrRecoveredCtParser(self.config_rec_ct, in_file, self.exception_callback)

            particles = parser.get_records(482)

            self.assertEqual(len(particles), 482)

            self.assertEqual(self.exception_callback_value, [])
    def test_ct_real(self):
        """
        Test with a real CT file rather than a generated one
        """
        with open(
                os.path.join(RESOURCE_PATH,
                             'SBE37-IM_03710261_2013_07_25.hex'),
                'r') as in_file:
            parser = CtdmoGhqrRecoveredCtParser(self.config_rec_ct, in_file,
                                                self.exception_callback)

            particles = parser.get_records(482)

            self.assertEqual(len(particles), 482)

            self.assertEqual(self.exception_callback_value, [])
    def test_rec_ct_simple(self):
        """
        Read Recovered CT data from the file and pull out data particles
        one at a time. Verify that the results are those we expected.
        """

        with open(os.path.join(RESOURCE_PATH, 'SBE37-IM_20110101_2011_01_01.hex'), 'r') as in_file:
            parser = CtdmoGhqrRecoveredCtParser(self.config_rec_ct, in_file, self.exception_callback)

            particles = parser.get_records(3)

            self.assertEqual(len(particles), 3)

            self.assert_particles(particles, 'SBE37-IM_20110101_2011_01_01.yml', RESOURCE_PATH)

            self.assertEqual(self.exception_callback_value, [])
    def test_rec_ct_no_records(self):
        """
        Read a Recovered CT data file that has no CT records.
        Verify that no particles are generated.
        """
        in_file = open(os.path.join(RESOURCE_PATH,
                                    'SBE37-IM_20100000_2010_00_00.hex'), 'r')
        parser = CtdmoGhqrRecoveredCtParser(self.config_rec_ct, in_file, self.exception_callback)

        # Not expecting any particles.
        expected_results = []

        # Try to get one particle and verify we didn't get any.
        result = parser.get_records(1)
        self.assertEqual(result, expected_results)

        in_file.close()
        self.assertEqual(self.exception_callback_value, [])
    def test_rec_ct_long_stream(self):
        """
        Read test data and pull out all particles from a file at once.
        """
        in_file = open(os.path.join(RESOURCE_PATH,
                                    'SBE37-IM_20141231_2014_12_31.hex'), 'r')
        parser = CtdmoGhqrRecoveredCtParser(self.config_rec_ct, in_file, self.exception_callback)

        total_records = 99
        particles = parser.get_records(total_records)
        self.assertEqual(len(particles), total_records)
        self.assert_particles(particles, 'SBE37-IM_20141231_2014_12_31.yml', RESOURCE_PATH)

        # confirm there are no more particles in this file
        particles2 = parser.get_records(5)
        self.assertEqual(len(particles2), 0)

        in_file.close()
        self.assertEqual(self.exception_callback_value, [])
    def test_rec_ct_no_records(self):
        """
        Read a Recovered CT data file that has no CT records.
        Verify that no particles are generated.
        """
        in_file = open(
            os.path.join(RESOURCE_PATH, 'SBE37-IM_20100000_2010_00_00.hex'),
            'r')
        parser = CtdmoGhqrRecoveredCtParser(self.config_rec_ct, in_file,
                                            self.exception_callback)

        # Not expecting any particles.
        expected_results = []

        # Try to get one particle and verify we didn't get any.
        result = parser.get_records(1)
        self.assertEqual(result, expected_results)

        in_file.close()
        self.assertEqual(self.exception_callback_value, [])
    def test_rec_ct_simple(self):
        """
        Read Recovered CT data from the file and pull out data particles
        one at a time. Verify that the results are those we expected.
        """

        with open(
                os.path.join(RESOURCE_PATH,
                             'SBE37-IM_20110101_2011_01_01.hex'),
                'r') as in_file:
            parser = CtdmoGhqrRecoveredCtParser(self.config_rec_ct, in_file,
                                                self.exception_callback)

            particles = parser.get_records(3)

            self.assertEqual(len(particles), 3)

            self.assert_particles(particles,
                                  'SBE37-IM_20110101_2011_01_01.yml',
                                  RESOURCE_PATH)

            self.assertEqual(self.exception_callback_value, [])
    def test_rec_ct_long_stream(self):
        """
        Read test data and pull out all particles from a file at once.
        """
        in_file = open(
            os.path.join(RESOURCE_PATH, 'SBE37-IM_20141231_2014_12_31.hex'),
            'r')
        parser = CtdmoGhqrRecoveredCtParser(self.config_rec_ct, in_file,
                                            self.exception_callback)

        total_records = 99
        particles = parser.get_records(total_records)
        self.assertEqual(len(particles), total_records)
        self.assert_particles(particles, 'SBE37-IM_20141231_2014_12_31.yml',
                              RESOURCE_PATH)

        # confirm there are no more particles in this file
        particles2 = parser.get_records(5)
        self.assertEqual(len(particles2), 0)

        in_file.close()
        self.assertEqual(self.exception_callback_value, [])
Example #9
0
def parse(basePythonCodePath, sourceFilePath, particleDataHdlrObj,
          serialNumToInductiveIdMapHandler):
    """
    This is the method called by Uframe
    :param basePythonCodePath This is the file system location of mi-dataset
    :param sourceFilePath This is the full path and filename of the file to be parsed
    :param particleDataHdlrObj Java Object to consume the output of the parser
    :return particleDataHdlrObj
    """

    log = get_logger()

    with open(sourceFilePath, 'r') as stream_handle:

        def exception_callback(exception):
            log.debug("Exception: %s", exception)
            particleDataHdlrObj.setParticleDataCaptureFailure()

        # extract the serial number from the file name
        serial_num = get_serial_num_from_filepath(sourceFilePath)

        # retrieve the inductive ID associated with the serial number
        induct_id = serialNumToInductiveIdMapHandler.getInductiveId(serial_num)

        if not induct_id:
            raise DatasetParserException(
                "Unable to obtain the inductive ID associated with serial num %d",
                serial_num)

        parser_config = {
            DataSetDriverConfigKeys.PARTICLE_MODULE:
            'mi.dataset.parser.ctdmo_ghqr_sio',
            DataSetDriverConfigKeys.PARTICLE_CLASS:
            ['CtdmoGhqrRecoveredInstrumentDataParticle'],
            INDUCTIVE_ID_KEY:
            induct_id
        }

        parser = CtdmoGhqrRecoveredCtParser(parser_config, stream_handle,
                                            exception_callback)

        # create and instance of the concrete driver class defined below
        driver = DataSetDriver(parser, particleDataHdlrObj)
        driver.processFileStream()

    return particleDataHdlrObj
    def test_rec_ct_missing_inductive_id_config(self):
        """
        Make sure that an exception is raised when building the
        Recovered CT parser if the inductive ID is missing in the config.
        """
        in_file = open(
            os.path.join(RESOURCE_PATH, 'SBE37-IM_20110101_2011_01_01.hex'),
            'r')

        bad_config = {
            DataSetDriverConfigKeys.PARTICLE_MODULE:
            'mi.dataset.parser.ctdmo_ghqr_sio',
            DataSetDriverConfigKeys.PARTICLE_CLASS:
            'CtdmoGhqrRecoveredInstrumentDataParticle',
        }

        with self.assertRaises(DatasetParserException):
            CtdmoGhqrRecoveredCtParser(bad_config, in_file,
                                       self.exception_callback)
def parse(unused, source_file_path, particle_data_handler):
    """
    This is the method called by Uframe
    :param unused
    :param source_file_path This is the full path and filename of the file to be parsed
    :param particle_data_handler Java Object to consume the output of the parser
    :return particle_data_handler
    """
    log = get_logger()

    with open(source_file_path, 'r') as stream_handle:

        def exception_callback(exception):
            log.debug("Exception: %s", exception)
            particle_data_handler.setParticleDataCaptureFailure()

        # extract the serial number from the file name
        serial_num = get_serial_num_from_filepath(source_file_path)

        parser_config = {
            DataSetDriverConfigKeys.PARTICLE_MODULE:
            'mi.dataset.parser.ctdmo_ghqr_sio',
            DataSetDriverConfigKeys.PARTICLE_CLASS:
            ['CtdmoGhqrRecoveredInstrumentDataParticle'],
            INDUCTIVE_ID_KEY:
            serial_num
        }

        parser = CtdmoGhqrRecoveredCtParser(parser_config, stream_handle,
                                            exception_callback)

        # create and instance of the concrete driver class defined below
        driver = DataSetDriver(parser, particle_data_handler)
        driver.processFileStream()

    return particle_data_handler