Ejemplo n.º 1
0
    def test_co_real(self):
        """
        Test with a real rather than generated CO file
        """
        with open(os.path.join(RESOURCE_PATH, 'CTD15906.DAT'), 'rb') as in_file:

            parser = CtdmoGhqrSioRecoveredCoParser(self.config_rec_co, in_file, self.exception_callback)

            # only 1 CO block with 12 records in real file
            particles = parser.get_records(14)
            self.assertEqual(len(particles), 12)

        self.assertEqual(self.exception_callback_value, [])
Ejemplo n.º 2
0
    def test_co_real(self):
        """
        Test with a real rather than generated CO file
        """
        with open(os.path.join(RESOURCE_PATH, 'CTD15906.DAT'),
                  'rb') as in_file:

            parser = CtdmoGhqrSioRecoveredCoParser(self.config_rec_co, in_file,
                                                   self.exception_callback)

            # only 1 CO block with 12 records in real file
            particles = parser.get_records(14)
            self.assertEqual(len(particles), 12)

        self.assertEqual(self.exception_callback_value, [])
def parse(basePythonCodePath, sourceFilePath, particleDataHdlrObj):
    """
    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, 'rb') as stream_handle:

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

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

        parser = CtdmoGhqrSioRecoveredCoParser(parser_config, stream_handle,
                                               exception_callback)

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

    return particleDataHdlrObj
Ejemplo n.º 4
0
    def test_rec_co_simple(self):
        """
        Read Recovered CO 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, 'CTD02001.DAT'), 'rb') as in_file:

            parser = CtdmoGhqrSioRecoveredCoParser(self.config_rec_co, in_file, self.exception_callback)

            particles = parser.get_records(7)

            self.assertEqual(len(particles), 6)

            self.assert_particles(particles, 'CTD02001.yml', RESOURCE_PATH)

        self.assertEqual(self.exception_callback_value, [])
Ejemplo n.º 5
0
    def test_rec_co_no_records(self):
        """
        Read a Recovered CO data file that has no CO records.
        Verify that no particles are generated.
        """
        in_file = open(os.path.join(RESOURCE_PATH, 'CTD02000.DAT'), 'rb')
        parser = CtdmoGhqrSioRecoveredCoParser(self.config_rec_co, 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, [])
Ejemplo n.º 6
0
    def test_rec_co_simple(self):
        """
        Read Recovered CO 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, 'CTD02001.DAT'),
                  'rb') as in_file:

            parser = CtdmoGhqrSioRecoveredCoParser(self.config_rec_co, in_file,
                                                   self.exception_callback)

            particles = parser.get_records(7)

            self.assertEqual(len(particles), 6)

            self.assert_particles(particles, 'CTD02001.yml', RESOURCE_PATH)

        self.assertEqual(self.exception_callback_value, [])
Ejemplo n.º 7
0
    def test_rec_co_no_records(self):
        """
        Read a Recovered CO data file that has no CO records.
        Verify that no particles are generated.
        """
        in_file = open(os.path.join(RESOURCE_PATH, 'CTD02000.DAT'), 'rb')
        parser = CtdmoGhqrSioRecoveredCoParser(self.config_rec_co, 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, [])
Ejemplo n.º 8
0
    def test_rec_co_long_stream(self):
        """
        Read test data and pull out all particles from a file at once.
        File used for this test has 3 CO SIO blocks and a total of 19 CO records.
        """
        in_file = open(os.path.join(RESOURCE_PATH, 'CTD02004.DAT'), 'rb')
        parser = CtdmoGhqrSioRecoveredCoParser(self.config_rec_co, in_file, self.exception_callback)

        particles = parser.get_records(19)
        self.assertEqual(len(particles), 19)

        # there should be no more particles in the file, ensure no more are returned
        particles2 = parser.get_records(19)
        self.assertEqual(len(particles2), 0)

        self.assert_particles(particles, 'CTD02004.yml', RESOURCE_PATH)

        in_file.close()
        self.assertEqual(self.exception_callback_value, [])
Ejemplo n.º 9
0
    def test_rec_co_get_many(self):
        """
        Read Recovered CO data and pull out multiple data particles in two blocks.
        Verify that the results are those we expected.
        File used for this test has 2 CO SIO blocks.
        """
        in_file = open(os.path.join(RESOURCE_PATH, 'CTD02002.DAT'), 'rb')
        parser = CtdmoGhqrSioRecoveredCoParser(self.config_rec_co, in_file, self.exception_callback)

        particles = parser.get_records(6)
        particles2 = parser.get_records(6)

        particles.extend(particles2)

        self.assertEqual(len(particles), 10)
        self.assert_particles(particles, 'CTD02002.yml', RESOURCE_PATH)

        in_file.close()
        self.assertEqual(self.exception_callback_value, [])
Ejemplo n.º 10
0
    def test_rec_co_long_stream(self):
        """
        Read test data and pull out all particles from a file at once.
        File used for this test has 3 CO SIO blocks and a total of 19 CO records.
        """
        in_file = open(os.path.join(RESOURCE_PATH, 'CTD02004.DAT'), 'rb')
        parser = CtdmoGhqrSioRecoveredCoParser(self.config_rec_co, in_file,
                                               self.exception_callback)

        particles = parser.get_records(19)
        self.assertEqual(len(particles), 19)

        # there should be no more particles in the file, ensure no more are returned
        particles2 = parser.get_records(19)
        self.assertEqual(len(particles2), 0)

        self.assert_particles(particles, 'CTD02004.yml', RESOURCE_PATH)

        in_file.close()
        self.assertEqual(self.exception_callback_value, [])
Ejemplo n.º 11
0
    def test_rec_co_get_many(self):
        """
        Read Recovered CO data and pull out multiple data particles in two blocks.
        Verify that the results are those we expected.
        File used for this test has 2 CO SIO blocks.
        """
        in_file = open(os.path.join(RESOURCE_PATH, 'CTD02002.DAT'), 'rb')
        parser = CtdmoGhqrSioRecoveredCoParser(self.config_rec_co, in_file,
                                               self.exception_callback)

        particles = parser.get_records(6)
        particles2 = parser.get_records(6)

        particles.extend(particles2)

        self.assertEqual(len(particles), 10)
        self.assert_particles(particles, 'CTD02002.yml', RESOURCE_PATH)

        in_file.close()
        self.assertEqual(self.exception_callback_value, [])
Ejemplo n.º 12
0
    def test_rec_co_big_giant_input(self):
        """
        Read a large file and verify that all expected particles can be read.
        Verification is not done at this time, but will be done during
        integration and qualification testing.
        File used for this test has 250 total CO particles.
        """
        in_file = open(os.path.join(RESOURCE_PATH, 'CTD02100.DAT'), 'rb')
        parser = CtdmoGhqrSioRecoveredCoParser(self.config_rec_co, in_file, self.exception_callback)

        number_expected_results = 250

        # In a single read, get all particles in this file.
        result = parser.get_records(number_expected_results)
        self.assertEqual(len(result), number_expected_results)

        self.assert_particles(result, 'CTD02100.yml', RESOURCE_PATH)

        in_file.close()
        self.assertEqual(self.exception_callback_value, [])
Ejemplo n.º 13
0
    def test_rec_co_big_giant_input(self):
        """
        Read a large file and verify that all expected particles can be read.
        Verification is not done at this time, but will be done during
        integration and qualification testing.
        File used for this test has 250 total CO particles.
        """
        in_file = open(os.path.join(RESOURCE_PATH, 'CTD02100.DAT'), 'rb')
        parser = CtdmoGhqrSioRecoveredCoParser(self.config_rec_co, in_file,
                                               self.exception_callback)

        number_expected_results = 250

        # In a single read, get all particles in this file.
        result = parser.get_records(number_expected_results)
        self.assertEqual(len(result), number_expected_results)

        self.assert_particles(result, 'CTD02100.yml', RESOURCE_PATH)

        in_file.close()
        self.assertEqual(self.exception_callback_value, [])