def test_simple(self):
        """
        Read test data from the file and assert that the results are those we expected.
        """
        with open(os.path.join(RESOURCE_PATH, 'node59p1_2.ctdmo.dat'), 'rb') as stream_handle:
            parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback)

            particles = parser.get_records(12)
            self.assertEqual(len(particles), 12)
            self.assert_particles(particles, 'node59p1_2.ctdmo.yml', RESOURCE_PATH)

        self.assertEqual(self.exception_callback_value, [])
    def test_co_and_ct(self):
        """
        Test with both co and ct particle types verified
        """
        with open(os.path.join(RESOURCE_PATH, 'node59p1_3.ctdmo.dat'), 'rb') as stream_handle:
            parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback)

            particles = parser.get_records(24)
            self.assertEqual(len(particles), 24) 
            self.assert_particles(particles, 'node59p1_3.ctdmo.yml', RESOURCE_PATH)

        self.assertEqual(self.exception_callback_value, [])
    def test_long_stream(self):
        """
        Test a long file and confirm the number of particles is correct
        """
        with open(os.path.join(RESOURCE_PATH, 'node59p1_0.ctdmo.dat'), 'rb') as stream_handle:
            parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback)

            # require more records than are available in the file
            result = parser.get_records(2000)
            # confirm we only get the number in the file (10 CO * 12/block = 120, 129 CT blocks * 12/block = 1548)
            self.assertEqual(len(result), 1668)

        self.assertEqual(self.exception_callback_value, [])
    def test_unexpected_data(self):
        """
        Read test data from the file including unexpected data.
        Assert that the results are those we expected and an exception occurs.
        """
        with open(os.path.join(RESOURCE_PATH, 'node59p1_1.bad.ctdmo.dat'), 'rb') as stream_handle:
            parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback)

            particles = parser.get_records(24)
            self.assertEqual(len(particles), 24)
            self.assert_particles(particles, 'node59p1_1.ctdmo.yml', RESOURCE_PATH)

            self.assertEqual(len(self.exception_callback_value), 1)
            self.assert_(isinstance(self.exception_callback_value[0], UnexpectedDataException))
Пример #5
0
    def test_simple(self):
        """
        Read test data from the file and assert that the results are those we expected.
        """
        with open(os.path.join(RESOURCE_PATH, 'node59p1_2.ctdmo.dat'),
                  'rb') as stream_handle:
            parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle,
                                                   self.exception_callback)

            particles = parser.get_records(12)
            self.assertEqual(len(particles), 12)
            self.assert_particles(particles, 'node59p1_2.ctdmo.yml',
                                  RESOURCE_PATH)

        self.assertEqual(self.exception_callback_value, [])
Пример #6
0
    def test_long_stream(self):
        """
        Test a long file and confirm the number of particles is correct
        """
        with open(os.path.join(RESOURCE_PATH, 'node59p1_0.ctdmo.dat'),
                  'rb') as stream_handle:
            parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle,
                                                   self.exception_callback)

            # require more records than are available in the file
            result = parser.get_records(2000)
            # confirm we only get the number in the file (10 CO * 12/block = 120, 129 CT blocks * 12/block = 1548)
            self.assertEqual(len(result), 1668)

        self.assertEqual(self.exception_callback_value, [])
Пример #7
0
    def test_co_and_ct(self):
        """
        Test with both co and ct particle types verified
        """
        with open(os.path.join(RESOURCE_PATH, 'node59p1_3.ctdmo.dat'),
                  'rb') as stream_handle:
            parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle,
                                                   self.exception_callback)

            particles = parser.get_records(24)
            self.assertEqual(len(particles), 24)
            self.assert_particles(particles, 'node59p1_3.ctdmo.yml',
                                  RESOURCE_PATH)

        self.assertEqual(self.exception_callback_value, [])
Пример #8
0
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: ['CtdmoGhqrSioTelemeteredInstrumentDataParticle',
                                                     'CtdmoGhqrSioTelemeteredOffsetDataParticle']
        }

        parser = CtdmoGhqrSioTelemeteredParser(parser_config, stream_handle, exception_callback)

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

    return particleDataHdlrObj
Пример #9
0
    def test_unexpected_data(self):
        """
        Read test data from the file including unexpected data.
        Assert that the results are those we expected and an exception occurs.
        """
        with open(os.path.join(RESOURCE_PATH, 'node59p1_1.bad.ctdmo.dat'),
                  'rb') as stream_handle:
            parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle,
                                                   self.exception_callback)

            particles = parser.get_records(24)
            self.assertEqual(len(particles), 24)
            self.assert_particles(particles, 'node59p1_1.ctdmo.yml',
                                  RESOURCE_PATH)

            self.assertEqual(len(self.exception_callback_value), 1)
            self.assert_(
                isinstance(self.exception_callback_value[0],
                           UnexpectedDataException))
    def test_get_many(self):
        """
        Read test data from the file and pull out multiple data particles at one time.
        Assert that the results are those we expected.
        """
        with open(os.path.join(RESOURCE_PATH, 'node59p1_1.ctdmo.dat'), 'rb') as stream_handle:
            parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback)

            particles = parser.get_records(10)
            particles2 = parser.get_records(10)
            self.assertEquals(len(particles2), 10)
            particles.extend(particles2)
            particles3 = parser.get_records(10)
            # 24 records total, should only have 4 remaining at this point
            self.assertEquals(len(particles3), 4)
            particles.extend(particles3)

            self.assert_particles(particles, 'node59p1_1.ctdmo.yml', RESOURCE_PATH)

        self.assertEqual(self.exception_callback_value, [])
Пример #11
0
    def test_get_many(self):
        """
        Read test data from the file and pull out multiple data particles at one time.
        Assert that the results are those we expected.
        """
        with open(os.path.join(RESOURCE_PATH, 'node59p1_1.ctdmo.dat'),
                  'rb') as stream_handle:
            parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle,
                                                   self.exception_callback)

            particles = parser.get_records(10)
            particles2 = parser.get_records(10)
            self.assertEquals(len(particles2), 10)
            particles.extend(particles2)
            particles3 = parser.get_records(10)
            # 24 records total, should only have 4 remaining at this point
            self.assertEquals(len(particles3), 4)
            particles.extend(particles3)

            self.assert_particles(particles, 'node59p1_1.ctdmo.yml',
                                  RESOURCE_PATH)

        self.assertEqual(self.exception_callback_value, [])