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


Python BaseDataHandler.execute_acquire_data方法代码示例

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


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

示例1: TestBaseDataHandlerUnit

# 需要导入模块: from ion.agents.data.handlers.base_data_handler import BaseDataHandler [as 别名]
# 或者: from ion.agents.data.handlers.base_data_handler.BaseDataHandler import execute_acquire_data [as 别名]
class TestBaseDataHandlerUnit(PyonTestCase):
    def setUp(self):
        self._stream_registrar = Mock()
        dh_config = {"external_dataset_res_id": "external_ds"}
        self._bdh = BaseDataHandler(stream_registrar=self._stream_registrar, dh_config=dh_config)

    def test_set_event_callback(self):
        self._bdh.set_event_callback("test_callback")
        self.assertEqual(self._bdh._event_callback, "test_callback")

    def test__dh_config(self):
        self._bdh._event_callback = Mock()
        self._bdh._dh_event(type="test_type", value="test_value")

    @patch.object(BaseDataHandler, "execute_acquire_data")
    @patch("ion.agents.data.handlers.base_data_handler.time")
    @unittest.skip("not working")
    def test__poll(self, time_mock, execute_acquire_data_mock):
        self._stream_registrar = Mock()
        dh_config = {"external_dataset_res_id": "external_ds"}
        bdh = BaseDataHandler(self._stream_registrar, dh_config)
        bdh._params = {"POLLING_INTERVAL": 1}
        glet = spawn(bdh._poll)

        self.counter = 0

        def inc_counter(*args):
            self.counter += 1
            if self.counter == 2:
                bdh._polling = False

        time_mock.sleep.side_effect = inc_counter

        glet.join(timeout=5)

        self.assertTrue(execute_acquire_data_mock.call_count >= 1)

    def test__publish_data_with_granules(self):
        publisher = Mock()

        granule1 = Mock(spec=Granule)
        granule2 = Mock(spec=Granule)
        granule3 = Mock(spec=Granule)
        data_generator = [granule1, granule2, granule3]

        BaseDataHandler._publish_data(publisher=publisher, data_generator=data_generator)

        expected = [call(granule1), call(granule2), call(granule3)]
        self.assertEqual(publisher.publish.call_args_list, expected)

    @patch("ion.agents.data.handlers.base_data_handler.log")
    def test__publish_data_no_granules(self, log_mock):
        publisher = Mock()

        granule1 = Mock()
        granule2 = Mock()
        granule3 = Mock()
        data_generator = [granule1, granule2, granule3]

        BaseDataHandler._publish_data(publisher=publisher, data_generator=data_generator)

        self.assertEqual(publisher.publish.call_count, 0)
        self.assertEqual(log_mock.warn.call_count, 3)

    def test__publish_data_no_generator(self):
        publisher = Mock()
        data_generator = Mock()

        self.assertRaises(
            InstrumentDataException, BaseDataHandler._publish_data, publisher=publisher, data_generator=data_generator
        )

    @patch.object(BaseDataHandler, "_constraints_for_historical_request")
    @patch.object(BaseDataHandler, "_init_acquisition_cycle")
    @patch.object(BaseDataHandler, "_get_data")
    @patch.object(BaseDataHandler, "_publish_data")
    def test__acquire_data_with_constraints(
        self, _publish_data_mock, _get_data_mock, _init_acquisition_cycle_mock, _constraints_for_historical_request_mock
    ):
        granule1 = Mock(spec=Granule)
        granule2 = Mock(spec=Granule)
        granule3 = Mock(spec=Granule)
        data_generator = [granule1, granule2, granule3]

        _get_data_mock.return_value = data_generator

        config = {"constraints": {"test_constraints": "value"}}
        publisher = Mock()
        unlock_new_data_callback = Mock()
        update_new_data_check_attachment = Mock()
        BaseDataHandler._acquire_data(
            config=config,
            publisher=publisher,
            unlock_new_data_callback=unlock_new_data_callback,
            update_new_data_check_attachment=update_new_data_check_attachment,
        )

        _init_acquisition_cycle_mock.assert_called_once_with(config)
        _constraints_for_historical_request_mock.assert_called_once_with(config)
        _get_data_mock.assert_called_once_with(config)
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:coi-services,代码行数:103,代码来源:test_base_data_handler.py

示例2: TestBaseDataHandlerUnit

# 需要导入模块: from ion.agents.data.handlers.base_data_handler import BaseDataHandler [as 别名]
# 或者: from ion.agents.data.handlers.base_data_handler.BaseDataHandler import execute_acquire_data [as 别名]
class TestBaseDataHandlerUnit(PyonTestCase):

    def setUp(self):
        self._stream_registrar = Mock()
        dh_config = {'external_dataset_res_id' : 'external_ds'}
        self._bdh = BaseDataHandler(stream_registrar=self._stream_registrar, dh_config=dh_config)

    def test_set_event_callback(self):
        self._bdh.set_event_callback('test_callback')
        self.assertEqual(self._bdh._event_callback, 'test_callback')

    def test__dh_config(self):
        self._bdh._event_callback = Mock()
        self._bdh._dh_event(type='test_type', value='test_value')

    @patch.object(BaseDataHandler, 'execute_acquire_data')
    @patch('ion.agents.data.handlers.base_data_handler.time')
    @unittest.skip('')
    def test__poll(self, time_mock, execute_acquire_data_mock):
        self._stream_registrar = Mock()
        dh_config = {'external_dataset_res_id' : 'external_ds', 'stream_id' : 'test_stream_id' }
        bdh = BaseDataHandler(self._stream_registrar, dh_config)
        #bdh.initialize()
        bdh._params = {'POLLING_INTERVAL':1}
        glet = spawn(bdh._poll)

        self.counter = 0
        def inc_counter(*args):
            self.counter += 1
            if self.counter == 2:
                bdh._polling = False

        time_mock.sleep.side_effect = inc_counter

        glet.join(timeout=5)

        self.assertTrue(execute_acquire_data_mock.call_count >= 2)

    def test__publish_data_with_granules(self):
        publisher = Mock()

        granule1 = Mock(spec=Granule)
        granule2 = Mock(spec=Granule)
        granule3 = Mock(spec=Granule)
        data_generator = [granule1, granule2, granule3]

        BaseDataHandler._publish_data(publisher=publisher, data_generator=data_generator)

        expected = [call(granule1), call(granule2), call(granule3)]
        self.assertEqual(publisher.publish.call_args_list, expected)

    @patch('ion.agents.data.handlers.base_data_handler.log')
    def test__publish_data_no_granules(self, log_mock):
        publisher = Mock()

        granule1 = Mock()
        granule2 = Mock()
        granule3 = Mock()
        data_generator = [granule1, granule2, granule3]

        BaseDataHandler._publish_data(publisher=publisher, data_generator=data_generator)

        self.assertEqual(publisher.publish.call_count, 0)
        self.assertEqual(log_mock.warn.call_count, 3)

    def test__publish_data_no_generator(self):
        publisher = Mock()
        data_generator = Mock()

        self.assertRaises(InstrumentDataException, BaseDataHandler._publish_data, publisher=publisher, data_generator=data_generator)

    @patch.object(BaseDataHandler, '_constraints_for_historical_request')
    @patch.object(BaseDataHandler, '_init_acquisition_cycle')
    @patch.object(BaseDataHandler, '_get_data')
    @patch.object(BaseDataHandler, '_publish_data')
    def test__acquire_data_with_constraints(self, _publish_data_mock, _get_data_mock, _init_acquisition_cycle_mock, _constraints_for_historical_request_mock):
        granule1 = Mock(spec=Granule)
        granule2 = Mock(spec=Granule)
        granule3 = Mock(spec=Granule)
        data_generator = [granule1, granule2, granule3]

        _get_data_mock.return_value = data_generator

        config = {'constraints' : {'test_constraints':'value'}}
        publisher = Mock()
        unlock_new_data_callback = Mock()
        update_new_data_check_attachment = Mock()
        BaseDataHandler._acquire_data(config=config, publisher=publisher, unlock_new_data_callback=unlock_new_data_callback, update_new_data_check_attachment=update_new_data_check_attachment)

        _init_acquisition_cycle_mock.assert_called_once_with(config)
        _constraints_for_historical_request_mock.assert_called_once_with(config)
        _get_data_mock.assert_called_once_with(config)
        _publish_data_mock.assert_called_once_with(publisher, data_generator)

    @patch.object(BaseDataHandler, '_init_acquisition_cycle')
    @patch.object(BaseDataHandler, '_get_data')
    @patch.object(BaseDataHandler, '_publish_data')
    @patch.object(BaseDataHandler, '_constraints_for_new_request')
    @patch('ion.agents.data.handlers.base_data_handler.gevent')
    def test__acquire_data_no_constraints(self, gevent_mock, _constraints_for_new_request_mock, _publish_data_mock, _get_data_mock, _init_acquisition_cycle_mock):
#.........这里部分代码省略.........
开发者ID:kerfoot,项目名称:coi-services,代码行数:103,代码来源:test_base_data_handler.py


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