当前位置: 首页>>代码示例>>Python>>正文


Python PhsenRecoveredParser.set_state方法代码示例

本文整理汇总了Python中mi.dataset.parser.phsen_abcdef.PhsenRecoveredParser.set_state方法的典型用法代码示例。如果您正苦于以下问题:Python PhsenRecoveredParser.set_state方法的具体用法?Python PhsenRecoveredParser.set_state怎么用?Python PhsenRecoveredParser.set_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mi.dataset.parser.phsen_abcdef.PhsenRecoveredParser的用法示例。


在下文中一共展示了PhsenRecoveredParser.set_state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PhsenRecoveredParserUnitTestCase

# 需要导入模块: from mi.dataset.parser.phsen_abcdef import PhsenRecoveredParser [as 别名]
# 或者: from mi.dataset.parser.phsen_abcdef.PhsenRecoveredParser import set_state [as 别名]

#.........这里部分代码省略.........
        self.assert_(isinstance(self.exception_callback_value[0], SampleException))

        stream_handle.close()

    def test_space_begin(self):
        """
        Test that we handle record that begin with a space
        """
        stream_handle = open(os.path.join(RESOURCE_PATH, 'SAMI_P0080_180713_space_begin.txt'))
        self.parser = PhsenRecoveredParser(self.config, None, stream_handle, self.state_callback,
                                           self.pub_callback, self.exception_callback)

        self.parser.get_records(1)

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

        stream_handle.close()

    def test_no_data_tag(self):
        """
        Test that we do not create a particle if the file does not contain the ':Data' tag
        """
        stream_handle = open(os.path.join(RESOURCE_PATH, 'SAMI_P0080_180713_no_data_tag.txt'))
        self.parser = PhsenRecoveredParser(self.config, None, stream_handle, self.state_callback,
                                           self.pub_callback, self.exception_callback)

        result = self.parser.get_records(1)
        self.assertEqual(result, [])

        stream_handle.close()

    def test_mid_state_start(self):
        """
        Test starting the parser in a state in the middle of processing
        """
        new_state = {StateKey.POSITION: 0x50b, StateKey.START_OF_DATA: False}
        stream_handle = open(os.path.join(RESOURCE_PATH,
                                          'SAMI_P0080_180713_simple.txt'))
        self.parser = PhsenRecoveredParser(self.config, new_state, stream_handle,
                                           self.state_callback, self.pub_callback, self.exception_callback)
        result = self.parser.get_records(1)
        expected_value = self.particle_128
        self.assertEqual(result, [expected_value])
        stream_handle.close()

    def test_mid_state_after_start(self):
        """
        Test starting the parser in a state after the start point
        """
        new_state = {StateKey.POSITION: 0x55f, StateKey.START_OF_DATA: True}
        stream_handle = open(os.path.join(RESOURCE_PATH,
                                          'SAMI_P0080_180713_simple.txt'))
        self.parser = PhsenRecoveredParser(self.config, new_state, stream_handle,
                                           self.state_callback, self.pub_callback, self.exception_callback)
        result = self.parser.get_records(1)
        expected_value = self.particle_129

        self.assertEqual(result, [expected_value])
        stream_handle.close()

    def test_mid_state_before_ph(self):
        """
        Test starting the parser in a state before the ph record
        """
        new_state = {StateKey.POSITION: 0x6db, StateKey.START_OF_DATA: True}
        stream_handle = open(os.path.join(RESOURCE_PATH,
                                          'SAMI_P0080_180713_simple.txt'))
        self.parser = PhsenRecoveredParser(self.config, new_state, stream_handle,
                                           self.state_callback, self.pub_callback, self.exception_callback)
        result = self.parser.get_records(1)
        expected_value = self.particle_a

        self.assertEqual(result, [expected_value])
        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
        """

        stream_handle = open(os.path.join(RESOURCE_PATH, 'SAMI_P0080_180713_simple.txt'))
        self.parser = PhsenRecoveredParser(self.config, None, stream_handle,
                                           self.state_callback, self.pub_callback, self.exception_callback)
        # there should only be 4 records, make sure we stop there
        result = self.parser.get_records(1)
        expected_value = self.particle_128
        self.assertEqual(result, [expected_value])

        new_state = {StateKey.POSITION: 0x6db, StateKey.START_OF_DATA: True}

        self.parser.set_state(new_state)
        result = self.parser.get_records(1)

        expected_value = self.particle_a

        self.assertEqual(result, [expected_value])

        stream_handle.close()
开发者ID:NickAlmonte,项目名称:mi-dataset,代码行数:104,代码来源:test_phsen_abcdef.py


注:本文中的mi.dataset.parser.phsen_abcdef.PhsenRecoveredParser.set_state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。