Exemplo n.º 1
0
    def test_get_many(self):
        """
        Read test data and pull out multiple data particles at one time.
        Assert that the results are those we expected.
        """
        file_path = os.path.join(RESOURCE_PATH, '11079364_WC_WM.txt')
        stream_handle = open(file_path, 'r')

        # Note: since the recovered and telemetered parser and particles are common
        # to each other, testing one is sufficient, will be completely tested
        # in driver tests

        parser = WcWmCsppParser(self.config.get(WcWmDataTypeKey.WC_WM_CSPP_TELEMETERED),
                                None, stream_handle,
                                self.state_callback, self.pub_callback,
                                self.exception_callback)

        # try to get 2000 particles, there are more data records in the file
        # so should get 2000 including the meta data
        particles = parser.get_records(2000)

        log.debug("*** test_get_many Num particles %s", len(particles))
        self.assertEqual(len(particles), 2000)

        stream_handle.close()
Exemplo n.º 2
0
    def test_simple(self):
        """
        Read test data and pull out data particles
        Assert that the results are those we expected.
        """
        file_path = os.path.join(RESOURCE_PATH, '11079364_WC_WM.txt')
        stream_handle = open(file_path, 'r')

        # Note: since the recovered and telemetered parser and particles are common
        # to each other, testing one is sufficient, will be completely tested
        # in driver tests

        parser = WcWmCsppParser(self.config.get(WcWmDataTypeKey.WC_WM_CSPP_RECOVERED),
                                None, stream_handle,
                                self.state_callback, self.pub_callback,
                                self.exception_callback)

        particles = parser.get_records(20)

        log.debug("*** test_simple Num particles %s", len(particles))

        test_data = self.get_dict_from_yml('11079364_WC_WM_recov.yml')

        # # check all the values against expected results.

        for i in range(len(particles)):

            self.assert_result(test_data['data'][i], particles[i])

        stream_handle.close()
Exemplo n.º 3
0
    def create_yml(self):
        """
        This utility creates a yml file
        Be sure to verify the results by eye before trusting!
        """

        fid = open(os.path.join(RESOURCE_PATH, '11079364_WC_WM.txt'), 'rU')

        stream_handle = fid
        parser = WcWmCsppParser(
            self.config.get(WcWmDataTypeKey.WC_WM_CSPP_RECOVERED),
            stream_handle, self.exception_callback)

        particles = parser.get_records(20)

        self.particle_to_yml(particles, '11079364_WC_WM_recov.yml')
        fid.close()
Exemplo n.º 4
0
    def test_simple_telem(self):
        """
        Read test data and pull out data particles
        Assert that the results are those we expected.
        """
        file_path = os.path.join(RESOURCE_PATH, '11079364_WC_WM.txt')
        stream_handle = open(file_path, 'rU')

        parser = WcWmCsppParser(self.config.get(WcWmDataTypeKey.WC_WM_CSPP_TELEMETERED),
                                stream_handle,
                                self.exception_callback)

        particles = parser.get_records(20)

        log.debug("*** test_simple Num particles %s", len(particles))

        self.assert_particles(particles, '11079364_WC_WM_telem.yml', RESOURCE_PATH)
Exemplo n.º 5
0
    def create_yml(self):
        """
        This utility creates a yml file
        Be sure to verify the results by eye before trusting!
        """

        fid = open(os.path.join(RESOURCE_PATH, '11079364_WC_WM.txt'), 'rU')

        stream_handle = fid
        parser = WcWmCsppParser(self.config.get(WcWmDataTypeKey.WC_WM_CSPP_RECOVERED),
                                stream_handle,
                                self.exception_callback)

        particles = parser.get_records(20)

        self.particle_to_yml(particles, '11079364_WC_WM_recov.yml')
        fid.close()
Exemplo n.º 6
0
    def test_simple_telem(self):
        """
        Read test data and pull out data particles
        Assert that the results are those we expected.
        """
        file_path = os.path.join(RESOURCE_PATH, '11079364_WC_WM.txt')
        stream_handle = open(file_path, 'rU')

        parser = WcWmCsppParser(
            self.config.get(WcWmDataTypeKey.WC_WM_CSPP_TELEMETERED),
            stream_handle, self.exception_callback)

        particles = parser.get_records(20)

        log.debug("*** test_simple Num particles %s", len(particles))

        self.assert_particles(particles, '11079364_WC_WM_telem.yml',
                              RESOURCE_PATH)
Exemplo n.º 7
0
    def test_bad_data(self):
        """
        Ensure that bad data is skipped when it exists.
        """

        # the 4th data record in this file are corrupted and will be ignored

        file_path = os.path.join(RESOURCE_PATH, '11079364_BAD_WC_WM.txt')
        stream_handle = open(file_path, 'rU')

        parser = WcWmCsppParser(self.config.get(WcWmDataTypeKey.WC_WM_CSPP_RECOVERED),
                                stream_handle,
                                self.exception_callback)

        parser.get_records(20)

        # log.info('##Exception value %s', self.exception_callback_value)

        self.assert_(isinstance(self.exception_callback_value[0], RecoverableSampleException))

        stream_handle.close()
Exemplo n.º 8
0
    def test_bad_data(self):
        """
        Ensure that bad data is skipped when it exists.
        """

        # the 4th data record in this file are corrupted and will be ignored

        file_path = os.path.join(RESOURCE_PATH, '11079364_BAD_WC_WM.txt')
        stream_handle = open(file_path, 'r')

        parser = WcWmCsppParser(self.config.get(WcWmDataTypeKey.WC_WM_CSPP_RECOVERED),
                                None, stream_handle,
                                self.state_callback, self.pub_callback,
                                self.exception_callback)

        particles = parser.get_records(20)

        # log.info('##Exception value %s', self.exception_callback_value)

        self.assert_(isinstance(self.exception_callback_value, RecoverableSampleException))

        stream_handle.close()
Exemplo n.º 9
0
    def test_mid_state_start(self):
        """
        This test makes sure that we retrieve the correct particles upon starting with an offset state.
        """

        file_path = os.path.join(RESOURCE_PATH, '11079364_WC_WM.txt')
        stream_handle = open(file_path, 'r')

        # position 1445 is the end of the 15th data record, which would have produced the
        # metadata particle and the first 15 engineering particles
        initial_state = {StateKey.POSITION: 1445, StateKey.METADATA_EXTRACTED: True}

        parser = WcWmCsppParser(self.config.get(WcWmDataTypeKey.WC_WM_CSPP_RECOVERED),
                                initial_state, stream_handle,
                                self.state_callback, self.pub_callback,
                                self.exception_callback)

        #expect to get the 16th and 17th engineering particles next
        particles = parser.get_records(2)

        log.debug("Num particles: %s", len(particles))

        self.assertTrue(len(particles) == 2)

        expected_results = self.get_dict_from_yml('11079364_WC_WM_recov.yml')

        # skip the first 16 particles in the yml file due to mid state start
        offset = 16

        for i in range(len(particles)):
            self.assert_result(expected_results['data'][i + offset], particles[i])

        # now expect the state to be the end of the 17th data record and metadata sent
        the_new_state = {StateKey.POSITION: 1591, StateKey.METADATA_EXTRACTED: True}
        log.debug("********** expected state: %s", the_new_state)
        log.debug("******** new parser state: %s", parser._state)
        self.assertTrue(parser._state == the_new_state)

        stream_handle.close()
Exemplo n.º 10
0
    def _build_parser(self, stream_handle):

        parser_config = {
            DataSetDriverConfigKeys.PARTICLE_CLASS: None,
            DataSetDriverConfigKeys.PARTICLE_CLASSES_DICT: {
                METADATA_PARTICLE_CLASS_KEY: WcWmMetadataRecoveredDataParticle,
                DATA_PARTICLE_CLASS_KEY: WcWmEngRecoveredDataParticle
            }
        }

        parser = WcWmCsppParser(parser_config, stream_handle,
                                self._exception_callback)

        return parser
Exemplo n.º 11
0
    def test_set_state(self):
        """
        Test changing to a new state after initializing the parser and
        reading data, as if new data has been found and the state has
        changed
        """

        file_path = os.path.join(RESOURCE_PATH, '11079364_WC_WM.txt')
        stream_handle = open(file_path, 'r')

        # 11079419_PPB_OCR_20.yml has the metadata and the first 19
        # engineering particles in it
        expected_results = self.get_dict_from_yml('11079364_WC_WM_recov.yml')

        parser = WcWmCsppParser(self.config.get(WcWmDataTypeKey.WC_WM_CSPP_RECOVERED),
                                None, stream_handle,
                                self.state_callback, self.pub_callback,
                                self.exception_callback)

        particles = parser.get_records(2)

        log.debug("Num particles: %s", len(particles))

        self.assertTrue(len(particles) == 2)

        for i in range(len(particles)):
            self.assert_result(expected_results['data'][i], particles[i])

        # position 935 is the byte at the start of the 9th data record
        new_state = {StateKey.POSITION: 935, StateKey.METADATA_EXTRACTED: True}

        parser.set_state(new_state)

        particles = parser.get_records(2)

        self.assertTrue(len(particles) == 2)

        # offset in the expected results
        offset = 9
        for i in range(len(particles)):
            self.assert_result(expected_results['data'][i + offset], particles[i])

        stream_handle.close()