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


Python Mock.assert_called_once方法代码示例

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


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

示例1: test_listener_removal_on_emit

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
def test_listener_removal_on_emit():
    """Test that a listener removed during an emit is called inside the current
    emit cycle.
    """

    call_me = Mock()
    ee = BaseEventEmitter()

    def should_remove():
        ee.remove_listener('remove', call_me)

    ee.on('remove', should_remove)
    ee.on('remove', call_me)

    ee.emit('remove')

    call_me.assert_called_once()

    call_me.reset_mock()

    # Also test with the listeners added in the opposite order
    ee = BaseEventEmitter()
    ee.on('remove', call_me)
    ee.on('remove', should_remove)

    ee.emit('remove')

    call_me.assert_called_once()
开发者ID:jfhbrook,项目名称:pyee,代码行数:30,代码来源:test_sync.py

示例2: test_update

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
    def test_update(self, include_prerelease, is_started, start_interval, enabled, interval, start_called, stop_called):
        checker = NewVersionChecker(False)

        def start_side_effect(i):
            checker.interval = i

        start_mock = Mock(side_effect=start_side_effect)
        stop_mock = Mock()
        is_started_mock = Mock(return_value=is_started)

        checker.interval = start_interval
        checker.start = start_mock
        checker.stop = stop_mock
        checker.is_started = is_started_mock

        checker.update(include_prerelease, enabled, interval)

        self.assertEqual(checker.interval, interval)
        self.assertEqual(checker.include_prereleases, include_prerelease)
        if start_called:
            start_mock.assert_called_once_with(interval)
        else:
            start_mock.assert_not_called()

        if stop_called:
            stop_mock.assert_called_once()
        else:
            stop_mock.assert_not_called()
开发者ID:werwolfby,项目名称:monitorrent,代码行数:30,代码来源:test_new_version_checker.py

示例3: test_actualizar

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
    def test_actualizar(self):
        '''
        Prueba el metodo actualizar.
        '''
        # preparo datos
        self.actualizador.version_actual = 'a'
        self.actualizador.version_disponible = 'b'

        mock_descargar = Mock()
        mock_descargar.return_value = [
            {
                'nombre': 'foo',
                'descripcion': 'bar'
            },
            {
                'nombre': 'bar',
                'descripcion': 'bar'
            },
        ]
        self.actualizador.descargar_actualizacion = mock_descargar

        mock_aplicar = Mock()
        mock_aplicar.return_value = True
        self.actualizador.aplicar_actualizacion = mock_aplicar
        # llamo metodo a probar
        self.actualizador.actualizar()
        # verifico que todo este bien
        mock_descargar.assert_called_once()
        mock_aplicar.assert_called()
        assert mock_aplicar.call_count == 2
        assert self.actualizador.version_actual == 'b'
开发者ID:Grupo106,项目名称:actualizador,代码行数:33,代码来源:test_actualizador.py

示例4: test_facet_configuration_with_existing_facet_callable

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
def test_facet_configuration_with_existing_facet_callable(isolated_app):
    facet_mock = Mock()
    facet_mock.return_value = {
        'aggs': {
            'jessica-jones': {
                'terms': {
                    'field': 'defenders',
                    'size': 20,
                },
            },
        },
    }
    config = {
        'RECORDS_REST_FACETS': {
            'defenders': facet_mock
        },
    }
    expected = {
        'aggs': {
            'jessica-jones': {
                'terms': {
                    'field': 'defenders',
                    'size': 20
                }
            }
        }
    }
    with isolated_app.test_request_context('?facet_name=defenders'):
        with patch.dict(isolated_app.config, config):
            result = get_facet_configuration('records-hep')
            facet_mock.assert_called_once()
            assert expected == result
开发者ID:harunurhan,项目名称:inspire-next,代码行数:34,代码来源:test_search_utils.py

示例5: test_ensure_supervisor_started

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
def test_ensure_supervisor_started(tmpdir, monkeypatch):
    m = Mock()
    monkeypatch.setattr(subprocess, "check_call", m)
    tmpdir.join("supervisord.pid").write("123123")
    supconfig = tmpdir.join("etc", "supervisord.conf")
    ensure_supervisor_started(tmpdir, supconfig)
    m.assert_called_once()
开发者ID:zerotired,项目名称:devpi,代码行数:9,代码来源:test_gendeploy.py

示例6: test_devpictl

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
def test_devpictl(tmpdir, monkeypatch):
    m = Mock()
    monkeypatch.setattr(subprocess, "call", m)
    tmpdir.join("supervisord.pid").write(os.getpid())
    tmpdir.ensure("etc", "supervisord.conf")
    devpictl(str(tmpdir.join("bin", "devpi-ctl")))
    m.assert_called_once()
开发者ID:zerotired,项目名称:devpi,代码行数:9,代码来源:test_gendeploy.py

示例7: test_handler_passed_to_gio

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
    def test_handler_passed_to_gio(self, monkeypatch):
        """Test if handler is correctly passed to Gio"""

        monkeypatch.setattr(
            Gio.DBusConnection, 'new_for_address_sync',
            Mock(return_value=Gio.DBusConnection()))

        signal_subscribe_mock = Mock()
        monkeypatch.setattr(
            Gio.DBusConnection, 'signal_subscribe',
            signal_subscribe_mock)

        conn = Connection()
        conn.connect_dbus()
        test_cb = lambda: None
        conn.signal_subscribe(test_cb)

        # test that Gio's signal_subscribe method is called once
        # and passed the callback as-is
        signal_subscribe_mock.assert_called_once()

        # pylint does not recognize Mock.call_args as sequence and won't
        # allow us to unpack it. Disabling the warning because we know what
        # we're doing here

        # pylint: disable=unpacking-non-sequence
        args, _ = signal_subscribe_mock.call_args
        assert args[6] == test_cb
开发者ID:techman83,项目名称:gst-switch,代码行数:30,代码来源:test_connection_unit.py

示例8: test_transmit_delete_item

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
 def test_transmit_delete_item(self):
     queue_item = self.get_queue_item()
     find_one = Mock(return_value={'item_id': '1', 'state': 'killed'})
     get_subscriber_reference = Mock(return_value={
         'item_id': '1',
         'subscriber_id': 'foo bar',
         'reference_id': 'foo',
         'extra': {
             'data': {
                 'revision': 'test'
             }
         }
     })
     insert_update_reference = Mock()
     mocked_service = MagicMock()
     mocked_service.return_value = MockedResourceService(
         find_one=find_one,
         get_subscriber_reference=get_subscriber_reference,
         insert_update_reference=insert_update_reference
     )
     with patch('aap.publish.transmitters.http_push_apple_news.get_resource_service', mocked_service):
         with HTTMock(self.delete_item_response):
             self.http_push._push_item(queue_item)
             find_one.assert_called_once()
             find_one.assert_called_with(req=None,
                                         item_id=queue_item.get('item_id'),
                                         _current_version=queue_item.get('item_version'))
             get_subscriber_reference.assert_called_once()
             get_subscriber_reference.assert_called_with('1', 'foo bar')
开发者ID:mdhaman,项目名称:superdesk-aap,代码行数:31,代码来源:http_push_apple_news_test.py

示例9: test__del__1

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
    def test__del__1(self):
        self.ftp.connected = Mock(return_value=True)
        m_disconnect = Mock()
        self.ftp.disconnect = m_disconnect

        del(self.ftp)

        m_disconnect.assert_called_once()
开发者ID:quarkslab,项目名称:irma,代码行数:10,代码来源:test_ftp.py

示例10: test_flip_switch

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
    def test_flip_switch(self):
        fetch_mock = Mock()

        self.patient._fetch = fetch_mock

        self.patient._flip_switch('MyService', 'ServiceType', 'action')

        fetch_mock.assert_called_once()
        fetch_mock.assert_called_with('http://host:6080/arcgis/admin/services/MyService.ServiceType/action')
开发者ID:agrc,项目名称:forklift,代码行数:11,代码来源:test_arcgis.py

示例11: test_turn_off

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
    def test_turn_off(self):
        flip_switch_mock = Mock()

        self.patient._flip_switch = flip_switch_mock

        self.patient.turn_off('MyService', 'ServiceType')

        flip_switch_mock.assert_called_once()
        flip_switch_mock.assert_called_with('MyService', 'ServiceType', 'stop')
开发者ID:agrc,项目名称:forklift,代码行数:11,代码来源:test_arcgis.py

示例12: test_areyousure_no

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
    def test_areyousure_no(self):
        yes = Mock()
        no = Mock()

        yes_func, no_func = self.sut.areyousure(yes, no)
        no_func()

        no.assert_called_once()
        self.widget.escape.assert_called_once()
        yes.assert_not_called()
开发者ID:Jdaco,项目名称:urwidgets,代码行数:12,代码来源:test_urwidgets.py

示例13: test_signal_sent

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
 def test_signal_sent(self):
     handler = Mock()
     form_submited.connect(handler)
     self.post(self.ok_data, expect_code=200)
     handler.assert_called_once()
     args, kwargs = handler.call_args
     self.assertIn('message', kwargs)
     self.assertIsInstance(kwargs['message'], Message)
     self.assertIn('request', kwargs)
     self.assertIsInstance(kwargs['request'], HttpRequest)
开发者ID:satyrius,项目名称:cmsplugin-feedback,代码行数:12,代码来源:test_post.py

示例14: test_should_update_ruleset

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
    def test_should_update_ruleset(self):
        out = StringIO()
        err = StringIO()
        update_mock = Mock()
        with patch('rules.models.Ruleset.update', update_mock):
            call_command('refreshprobes', '-u', 'probe1', stdout=out, stderr=err)

        update_mock.assert_called_once()
        self.assertIn('Update complete', out.getvalue())
        self.assertEqual('', err.getvalue())
开发者ID:sep,项目名称:scirius,代码行数:12,代码来源:test_refreshprobes.py

示例15: test_should_build_rules

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_called_once [as 别名]
    def test_should_build_rules(self):
        out = StringIO()
        err = StringIO()
        build_mock = Mock()
        with patch('probes.models.Probes.build_rules', build_mock):
            call_command('refreshprobes', '-b', 'probe1', stdout=out, stderr=err)

        build_mock.assert_called_once()
        self.assertIn('Build complete', out.getvalue())
        self.assertEqual('', err.getvalue())
开发者ID:sep,项目名称:scirius,代码行数:12,代码来源:test_refreshprobes.py


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