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


Python base_data_handler.BaseDataHandler类代码示例

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


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

示例1: test__init_acquisition_cycle

 def test__init_acquisition_cycle(self):
     config = {}
     with self.assertRaises(NotImplementedException) as cm:
         BaseDataHandler._init_acquisition_cycle(config)
         ex = cm.exception
         # TODO: This is brittle as the message could change - do we need this check, or is getting the exception enough?
         self.assertEqual(ex.message, "ion.agents.data.handlers.base_data_handler.BaseDataHandler must implement '_init_acquisition_cycle'")
开发者ID:Bobfrat,项目名称:coi-services,代码行数:7,代码来源:test_base_data_handler.py

示例2: test__poll

    def test__poll(self, time_mock):
        stream_route = Mock(spec=StreamRoute)
        dh_config = {
            'external_dataset_res_id': 'external_ds',
            'stream_id': 'test_stream_id',
            'stream_route': stream_route
        }

        bdh = BaseDataHandler(dh_config)
        execute_acquire_sample_mock = MagicMock()
        bdh.execute_acquire_sample = execute_acquire_sample_mock

        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_sample_mock.call_count >= 1)
开发者ID:Bobfrat,项目名称:coi-services,代码行数:26,代码来源:test_base_data_handler.py

示例3: test__acquire_data_no_constraints

    def test__acquire_data_no_constraints(
        self,
        gevent_mock,
        _constraints_for_new_request_mock,
        _publish_data_mock,
        _get_data_mock,
        _init_acquisition_cycle_mock,
    ):
        granule1 = Mock(spec=Granule)
        granule2 = Mock(spec=Granule)
        granule3 = Mock(spec=Granule)
        data_generator = [granule1, granule2, granule3]

        gevent_mock.getcurrent = Mock()

        _constraints_for_new_request_mock.return_value = {"constraints": {"test_constraints": "value"}}
        _get_data_mock.return_value = data_generator

        config = {}
        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_new_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)
开发者ID:pombredanne,项目名称:coi-services,代码行数:33,代码来源:test_base_data_handler.py

示例4: test__acquire_data_with_constraints_testing_flag

    def test__acquire_data_with_constraints_testing_flag(
        self,
        _publish_data_mock,
        _get_data_mock,
        _init_acquisition_cycle_mock,
        EventPublisher_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"}, "TESTING": True}
        publisher = Mock()
        unlock_new_data_callback = Mock()
        update_new_data_check_attachment = Mock()
        EventPublisher_mock.publish_event = 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)
        _get_data_mock.assert_called_once_with(config)
        _publish_data_mock.assert_called_once_with(publisher, data_generator)
        _constraints_for_historical_request_mock.assert_called_once_with(config)
        EventPublisher_mock.publish_event.assert_called_once()
开发者ID:pombredanne,项目名称:coi-services,代码行数:32,代码来源:test_base_data_handler.py

示例5: test__publish_data_with_granules

    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)
开发者ID:pombredanne,项目名称:coi-services,代码行数:12,代码来源:test_base_data_handler.py

示例6: test__publish_data_no_granules

    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)
开发者ID:pombredanne,项目名称:coi-services,代码行数:12,代码来源:test_base_data_handler.py

示例7: test__acquire_data_with_constraints

    def test__acquire_data_with_constraints(self, _publish_data_mock, _get_data_mock, _init_acquisition_cycle_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'}
        publisher = Mock()
        unlock_new_data_callback = Mock()
        BaseDataHandler._acquire_data(config=config, publisher=publisher, unlock_new_data_callback=unlock_new_data_callback)

        _init_acquisition_cycle_mock.assert_called_once_with(config)
        _get_data_mock.assert_called_once_with(config)
        _publish_data_mock.assert_called_once_with(publisher, data_generator)
开发者ID:dstuebe,项目名称:coi-services,代码行数:16,代码来源:test_base_data_handler.py

示例8: test__poll

    def test__poll(self, time_mock, execute_acquire_data_mock):
        bdh=BaseDataHandler(None, None, None)
        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)
开发者ID:dstuebe,项目名称:coi-services,代码行数:16,代码来源:test_base_data_handler.py

示例9: test__acquire_data_with_constraints

    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)
开发者ID:kerfoot,项目名称:coi-services,代码行数:18,代码来源:test_base_data_handler.py

示例10: test__poll

    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)
开发者ID:pombredanne,项目名称:coi-services,代码行数:19,代码来源:test_base_data_handler.py

示例11: TestBaseDataHandlerUnit

class TestBaseDataHandlerUnit(PyonTestCase):

    def setUp(self):

        dh_config = {'external_dataset_res_id': 'external_ds'}
        self._bdh = BaseDataHandler(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('ion.agents.data.handlers.base_data_handler.time')
    def test__poll(self, time_mock):
        stream_route = Mock(spec=StreamRoute)
        dh_config = {
            'external_dataset_res_id': 'external_ds',
            'stream_id': 'test_stream_id',
            'stream_route': stream_route
        }

        bdh = BaseDataHandler(dh_config)
        execute_acquire_sample_mock = MagicMock()
        bdh.execute_acquire_sample = execute_acquire_sample_mock

        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_sample_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_sample_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_sample(config=config, publisher=publisher,
#.........这里部分代码省略.........
开发者ID:Bobfrat,项目名称:coi-services,代码行数:101,代码来源:test_base_data_handler.py

示例12: TestBaseDataHandlerUnit

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,代码行数:101,代码来源:test_base_data_handler.py

示例13: setUp

 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)
开发者ID:pombredanne,项目名称:coi-services,代码行数:4,代码来源:test_base_data_handler.py

示例14: TestBaseDataHandlerUnit

class TestBaseDataHandlerUnit(PyonTestCase):

    def setUp(self):
        self._rr_cli = Mock()
        self._stream_registrar = Mock()
        dh_config = {'external_dataset_res_id' : 'external_ds'}
        self._bdh = BaseDataHandler(rr_cli=self._rr_cli, 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')
    def test__poll(self, time_mock, execute_acquire_data_mock):
        bdh=BaseDataHandler(None, None, None)
        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, '_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):
        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'}
        publisher = Mock()
        unlock_new_data_callback = Mock()
        BaseDataHandler._acquire_data(config=config, publisher=publisher, unlock_new_data_callback=unlock_new_data_callback)

        _init_acquisition_cycle_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, '_new_data_constraints')
    @patch('ion.agents.data.handlers.base_data_handler.gevent')
    def test__acquire_data_no_constraints(self, gevent_mock, _new_data_constraints_mock, _publish_data_mock, _get_data_mock, _init_acquisition_cycle_mock):
        granule1 = Mock(spec=Granule)
        granule2 = Mock(spec=Granule)
        granule3 = Mock(spec=Granule)
        data_generator = [granule1, granule2, granule3]

        gevent_mock.getcurrent = Mock()
#.........这里部分代码省略.........
开发者ID:dstuebe,项目名称:coi-services,代码行数:101,代码来源:test_base_data_handler.py

示例15: setUp

 def setUp(self):
     self._rr_cli = Mock()
     self._stream_registrar = Mock()
     dh_config = {'external_dataset_res_id' : 'external_ds'}
     self._bdh = BaseDataHandler(rr_cli=self._rr_cli, stream_registrar=self._stream_registrar, dh_config=dh_config)
开发者ID:dstuebe,项目名称:coi-services,代码行数:5,代码来源:test_base_data_handler.py


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