本文整理匯總了Python中mi.dataset.parser.adcps_jln_stc.AdcpsJlnStcParser.set_state方法的典型用法代碼示例。如果您正苦於以下問題:Python AdcpsJlnStcParser.set_state方法的具體用法?Python AdcpsJlnStcParser.set_state怎麽用?Python AdcpsJlnStcParser.set_state使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mi.dataset.parser.adcps_jln_stc.AdcpsJlnStcParser
的用法示例。
在下文中一共展示了AdcpsJlnStcParser.set_state方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: AdcpsJlnStcParserUnitTestCase
# 需要導入模塊: from mi.dataset.parser.adcps_jln_stc import AdcpsJlnStcParser [as 別名]
# 或者: from mi.dataset.parser.adcps_jln_stc.AdcpsJlnStcParser import set_state [as 別名]
#.........這裏部分代碼省略.........
result = self.parser.get_records(1)
self.assert_result(result, self.particle_d, 1622)
result = self.parser.get_records(1)
self.assert_result(result, self.particle_e, 1993)
# no data left
result = self.parser.get_records(1)
self.assertEqual(result, [])
self.assert_(isinstance(self.publish_callback_value, list))
self.assertEqual(self.publish_callback_value[0], self.particle_e)
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.
"""
self.stream_handle = open(os.path.join(RESOURCE_PATH, 'adcpt_20130929_091817.DAT'))
self.parser = AdcpsJlnStcParser(self.config, self.start_state, self.stream_handle,
self.state_callback, self.pub_callback, self.exception_callback)
result = self.parser.get_records(4)
self.assertEqual(result, [self.particle_header_footer, self.particle_a, self.particle_b, self.particle_c])
log.debug('POSITION: %s', self.parser._state[StateKey.POSITION])
self.assertEqual(self.parser._state[StateKey.POSITION], 1251)
self.assertEqual(self.state_callback_value[StateKey.POSITION], 1251)
self.assertEqual(self.publish_callback_value[0], self.particle_header_footer)
self.assertEqual(self.publish_callback_value[1], self.particle_a)
self.assertEqual(self.publish_callback_value[2], self.particle_b)
self.assertEqual(self.publish_callback_value[3], self.particle_c)
def test_mid_state_start(self):
"""
Test starting the parser in a state in the middle of processing
"""
# Move position in file to middle of second record. Should return the 3rd record (particle c)
new_state = {StateKey.POSITION: 590}
self.stream_handle = open(os.path.join(RESOURCE_PATH, 'adcpt_20130929_091817.DAT'))
self.parser = AdcpsJlnStcParser(self.config, new_state, self.stream_handle,
self.state_callback, self.pub_callback, self.exception_callback)
result = self.parser.get_records(1)
self.assert_result(result, self.particle_c, 1251)
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
"""
self.stream_handle = open(os.path.join(RESOURCE_PATH, 'adcpt_20130929_091817.DAT'))
self.parser = AdcpsJlnStcParser(self.config, self.start_state, self.stream_handle,
self.state_callback, self.pub_callback, self.exception_callback)
new_state = {StateKey.POSITION: 590}
self.parser.set_state(new_state)
result = self.parser.get_records(1)
self.assert_result(result, self.particle_c, 1251)
result = self.parser.get_records(1)
self.assert_result(result, self.particle_d, 1622)
def test_bad_data(self):
"""
Ensure that bad data is skipped when it exists.
"""
# Bad checksum
# If checksum is bad, skip the record and continue parsing.
self.stream_handle = StringIO(AdcpsJlnStcParserUnitTestCase.BAD_CHECKSUM)
self.parser = AdcpsJlnStcParser(self.config, self.start_state, self.stream_handle,
self.state_callback, self.pub_callback, self.exception_callback)
# Only the header and second record, particle_b should be returned.
result = self.parser.get_records(3)
self.assertEqual(self.publish_callback_value[0], self.particle_header_footer)
self.assertEqual(self.publish_callback_value[1], self.particle_b)
if len(result) != 2:
self.fail("Expected two records and got %d. Record containing bad data should have been skipped.",
len(result))
# Incorrect number of bytes
# If numbytes is incorrect, skip the record and continue parsing.
self.start_state = {StateKey.POSITION: 0}
self.stream_handle = StringIO(AdcpsJlnStcParserUnitTestCase.BAD_NUM_BYTES)
self.parser = AdcpsJlnStcParser(self.config, self.start_state, self.stream_handle,
self.state_callback, self.pub_callback, self.exception_callback)
result = self.parser.get_records(3)
self.assertEqual(self.publish_callback_value[0], self.particle_header_footer)
self.assertEqual(self.publish_callback_value[1], self.particle_b)
if len(result) != 2:
self.fail("Expected two records and got %d. Record containing bad data should have been skipped.",
len(result))
def test_receive_fail(self):
# ReceiveFailure
# If record marked with 'ReceiveFailure', skip the record and continue parsing.
self.start_state = {StateKey.POSITION: 0}
self.stream_handle = StringIO(AdcpsJlnStcParserUnitTestCase.BAD_RX_FAILURE)
self.parser = AdcpsJlnStcParser(self.config, self.start_state, self.stream_handle,
self.state_callback, self.pub_callback, self.exception_callback)
result = self.parser.get_records(3)
self.assertEqual(self.publish_callback_value[0], self.particle_header_footer)
self.assertEqual(self.publish_callback_value[1], self.particle_b)
if len(result) != 2:
self.fail("Expected two records and got %d. Record containing ReceiveFailure should have been skipped.",
len(result))