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, '01554008_DBG_PDBG.txt') stream_handle = open(file_path, 'r') expected_results = self.get_dict_from_yml( '01554008_DBG_PDBG_recov.yml') parser = DbgPdbgCsppParser( self.config.get(DbgPdbgDataTypeKey.DBG_PDBG_CSPP_RECOVERED), None, stream_handle, self.state_callback, self.pub_callback, self.exception_callback) # read all 8 particles from the file particles = parser.get_records(8) log.debug("Num particles: %s", len(particles)) self.assertTrue(len(particles) == 8) for i in range(len(particles)): self.assert_result(expected_results['data'][i], particles[i]) # position 1528 is the byte at the start of the 2nd data record new_state = { StateKey.POSITION: 1528, StateKey.METADATA_EXTRACTED: True } parser.set_state(new_state) particles = parser.get_records(2) self.assertTrue(len(particles) == 2) # offset in the expected results # should not get the first 2 status particles or the metadata particle offset = 3 for i in range(len(particles)): self.assert_result(expected_results['data'][i + offset], particles[i]) stream_handle.close()
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, '01554008_DBG_PDBG.txt') stream_handle = open(file_path, 'r') expected_results = self.get_dict_from_yml('01554008_DBG_PDBG_recov.yml') parser = DbgPdbgCsppParser(self.config.get(DbgPdbgDataTypeKey.DBG_PDBG_CSPP_RECOVERED), None, stream_handle, self.state_callback, self.pub_callback, self.exception_callback) # read all 8 particles from the file particles = parser.get_records(8) log.debug("Num particles: %s", len(particles)) self.assertTrue(len(particles) == 8) for i in range(len(particles)): self.assert_result(expected_results['data'][i], particles[i]) # position 1528 is the byte at the start of the 2nd data record new_state = {StateKey.POSITION: 1528, StateKey.METADATA_EXTRACTED: True} parser.set_state(new_state) particles = parser.get_records(2) self.assertTrue(len(particles) == 2) # offset in the expected results # should not get the first 2 status particles or the metadata particle offset = 3 for i in range(len(particles)): self.assert_result(expected_results['data'][i + offset], particles[i]) stream_handle.close()