本文整理汇总了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))