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


Python Mock.__name__方法代码示例

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


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

示例1: test_method_wrappers

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
    def test_method_wrappers(self):
        class Flask(flask.Flask, FlaskHTTPMethodsMixin):
            pass

        app = Flask(__name__)

        client = app.test_client()

        get_handler = Mock(return_value='', spec={})
        get_handler.__name__ = 'get_handler'
        app.get('/foo')(get_handler)

        post_handler = Mock(return_value='', spec={})
        post_handler.__name__ = 'post_handler'
        app.post('/foo')(post_handler)

        response = client.get('/foo')
        self.assertEquals(response.status_code, 200)
        get_handler.assert_called_once_with()

        response = client.post('/foo')
        self.assertEquals(response.status_code, 200)
        post_handler.assert_called_once_with()

        response = client.delete('/foo')
        self.assertEquals(response.status_code, 405)

        response = client.open('/foo', method='OPTIONS')
        self.assertItemsEqual(
            response.allow,
            ('POST', 'HEAD', 'OPTIONS', 'GET')
        )
开发者ID:conversocial,项目名称:velocity-monster,代码行数:34,代码来源:test_flask_utils.py

示例2: test_function_cache

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
    def test_function_cache(self, mkdirs, cache_file, is_expired, exists,
                            yaml_load, yaml_dump):
        """ Test when the file doesn't exist, is forced or is expired """
        empty_test = Mock()
        empty_test.__name__ = 'empty_test'
        empty_test.return_value = 'from empty_test'

        is_expired.return_value = False
        exists.return_value = False
        cache_file.return_value = 'test.yaml'
        yaml_load.return_value = "from cache"

        """ File doesn't exist, isn't expired, and isn't forced """
        with patch.object(cache, 'open', create=True) as mock_open:
            result = cache.function_cache(empty_test, 5, False)

            mkdirs.assert_called_once_with(cache.BASE_DIR)
            mock_open.assert_called_once_with('test.yaml', 'w')
            self.assertEqual(result, "from empty_test")

            exists.return_value = True

            """ Exists, isn't expired, forced """
            result = cache.function_cache(empty_test, 5, True)
            self.assertEqual(result, "from empty_test")

            """ Exists, but expired """
            is_expired.return_value = True

            result = cache.function_cache(empty_test, 5, False)
            self.assertEqual(result, "from empty_test")

            self.assertEqual(yaml_load.call_count, 0)
            self.assertEqual(empty_test.call_count, 3)
开发者ID:kennedyj,项目名称:python-commons,代码行数:36,代码来源:test_cache.py

示例3: test_cmd_plugin_unload_successful

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
    def test_cmd_plugin_unload_successful(self):
        # GIVEN

        ###### MOCK PLUGIN
        mock_plugin = Mock(spec=Plugin)
        mock_plugin.console = self.console
        mock_plugin.isEnabled = Mock(return_value=False)
        when(self.console).getPlugin("mock").thenReturn(mock_plugin)
        self.console._plugins['mock'] = mock_plugin
        ###### MOCK COMMAND
        mock_func = Mock()
        mock_func.__name__ = 'cmd_mockfunc'
        self.adminPlugin._commands['mockcommand'] = Command(plugin=mock_plugin, cmd='mockcommand', level=100, func=mock_func)
        ###### MOCK EVENT
        mock_plugin.onSay = Mock()
        mock_plugin.registerEvent('EVT_CLIENT_SAY', mock_plugin.onSay)
        ###### MOCK CRON
        mock_plugin.mockCronjob = Mock()
        mock_plugin.mockCrontab = b3.cron.PluginCronTab(mock_plugin, mock_plugin.mockCronjob, minute='*', second= '*/60')
        self.console.cron.add(mock_plugin.mockCrontab)
        self.assertIn(id(mock_plugin.mockCrontab), self.console.cron._tabs)

        superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
        superadmin.connects("1")
        # WHEN
        superadmin.clearMessageHistory()
        superadmin.says("!plugin unload mock")
        # THEN
        self.assertNotIn('mockcommand', self.adminPlugin._commands)
        self.assertIn(self.console.getEventID('EVT_CLIENT_SAY'), self.console._handlers)
        self.assertNotIn(mock_plugin, self.console._handlers[self.console.getEventID('EVT_CLIENT_SAY')])
        self.assertNotIn(id(mock_plugin.mockCrontab), self.console.cron._tabs)
        self.assertListEqual(['Plugin mock has been unloaded'], superadmin.message_history)
开发者ID:HaoDrang,项目名称:big-brother-bot,代码行数:35,代码来源:test_commands.py

示例4: test_apply_interval

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
    def test_apply_interval(self):
        t = timer2.Timer()
        try:
            t.schedule.enter_after = Mock()

            myfun = Mock()
            myfun.__name__ = "myfun"
            t.apply_interval(30, myfun)

            self.assertEqual(t.schedule.enter_after.call_count, 1)
            args1, _ = t.schedule.enter_after.call_args_list[0]
            msec1, tref1, _ = args1
            self.assertEqual(msec1, 30)
            tref1()

            self.assertEqual(t.schedule.enter_after.call_count, 2)
            args2, _ = t.schedule.enter_after.call_args_list[1]
            msec2, tref2, _ = args2
            self.assertEqual(msec2, 30)
            tref2.cancelled = True
            tref2()

            self.assertEqual(t.schedule.enter_after.call_count, 2)
        finally:
            t.stop()
开发者ID:leobantech,项目名称:celery,代码行数:27,代码来源:test_timer2.py

示例5: test_wrap_memo

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

        func = Mock(name='func')
        func.return_value = 42
        func.__name__ = 'my_func'

        wrapped = memo(func)
        # First call gives a call count of 1
        self.assertEqual(wrapped(3), 42)
        self.assertEqual(func.call_count, 1)

        self.assertEqual(wrapped(3), 42)
        self.assertEqual(func.call_count, 1)

        self.assertEqual(wrapped(x=7, y=1, z=2), 42)
        self.assertEqual(func.call_count, 2)

        self.assertEqual(wrapped(y=1, x=7, z=2), 42)
        self.assertEqual(func.call_count, 2)

        self.assertEqual(wrapped(7, 1, 2), 42)     # doesn't matter, is is args or kwargs one call of function
        self.assertEqual(func.call_count, 2)       # arguments in cache should be the same

        self.assertEqual(wrapped(7, 2, 2), 42)
        self.assertEqual(func.call_count, 3)

        self.assertEqual(wrapped([7]), 42)
        self.assertEqual(func.call_count, 4)

        self.assertEqual(wrapped([7]), 42)         # cause list isn't hashable
        self.assertEqual(func.call_count, 5)
开发者ID:Scandie,项目名称:ProtossOP,代码行数:33,代码来源:decors-test.py

示例6: test_require_jwt_decorator

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
    def test_require_jwt_decorator(self):
        mock = Mock(return_value="success")
        mock.__name__ = 'test_mock'
        mock_fn = jwt.require_jwt(mock)
        bad_header = {
            "Authorization": "Bearer this-is-not-a-token"
        }
        nobearer_header = {
            "Authorization": "this-is-not-a-token"
        }
        token = jwt.create_token_for_user(self.default_user)
        with self.app.test_request_context(headers=bad_header):
            res = mock_fn()
            self.assertEqual(401, res.status_code)

        with self.app.test_request_context(headers=nobearer_header):
            res = mock_fn()
            self.assertEqual(401, res.status_code)

        with self.app.test_request_context():
            res = mock_fn()
            self.assertEqual(401, res.status_code)
        good_header = {
            "Authorization": "Bearer %s" % token
        }
        with self.app.test_request_context(headers=good_header):
            res = mock_fn()
            self.assertEqual("success", res)
开发者ID:patallen,项目名称:markdraft.com,代码行数:30,代码来源:test_auth.py

示例7: test_load_tokenizer

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
 def test_load_tokenizer(self, mock_all_subclasses, mock_load_backend):
     tokenizer0 = Mock()
     tokenizer0.__name__ = 'SplitTokenizer'
     tokenizer0Returns = Mock()
     tokenizer0.return_value = tokenizer0Returns
     tokenizer1 = Mock()
     tokenizer1.__name__ = 'NotSqlAlchemyWrapper'
     tokenizer2 = Mock()
     tokenizer2.__name__ = 'StillNotSqlAlchemyWrapper'
     mock_all_subclasses.return_value = [tokenizer0, tokenizer1, tokenizer2]
     sh = Spicedham()
     sh._load_tokenizer()
     self.assertEqual(sh.tokenizer, tokenizer0Returns)
     sh = Spicedham()
     mock_all_subclasses.return_value = []
     self.assertRaises(NoTokenizerFoundError, sh._load_tokenizer)
开发者ID:iankronquist,项目名称:spicedham,代码行数:18,代码来源:test_spicedham.py

示例8: test_http_request_wrapper

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
def test_http_request_wrapper(patched_time_sleep):
    socket_error = socket.error()
    socket_error.errno = errno.E2BIG

    with pytest.raises(socket.error):
        blobxfer.http_request_wrapper(Mock(side_effect=socket_error))

    socket_error.errno = errno.ETIMEDOUT
    with pytest.raises(IOError):
        mock = Mock(side_effect=socket_error)
        mock.__name__ = 'name'
        blobxfer.http_request_wrapper(mock, timeout=0.001)

    with pytest.raises(requests.exceptions.HTTPError):
        exc = requests.exceptions.HTTPError()
        exc.response = MagicMock()
        exc.response.status_code = 404
        mock = Mock(side_effect=exc)
        blobxfer.http_request_wrapper(mock)

    try:
        blobxfer.http_request_wrapper(
                _func_raise_requests_exception_once, val=[], timeout=1)
    except:
        pytest.fail('unexpected Exception raised')

    try:
        blobxfer.http_request_wrapper(_func_successful_requests_call)
    except:
        pytest.fail('unexpected Exception raised')
开发者ID:spelluru,项目名称:azure-batch-samples,代码行数:32,代码来源:test_blobxfer.py

示例9: test_load_backend

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
 def test_load_backend(self, mock_all_subclasses, mock_load_tokenizer):
     backend0 = Mock()
     backend0.__name__ = 'SqlAlchemyWrapper'
     backend0Returns = Mock()
     backend0.return_value = backend0Returns
     backend1 = Mock()
     backend1.__name__ = 'NotSqlAlchemyWrapper'
     backend2 = Mock()
     backend2.__name__ = 'StillNotSqlAlchemyWrapper'
     mock_all_subclasses.return_value = [backend0, backend1, backend2]
     sh = Spicedham()
     sh._load_backend()
     self.assertEqual(sh.backend, backend0Returns)
     sh = Spicedham()
     mock_all_subclasses.return_value = []
     self.assertRaises(NoBackendFoundError, sh._load_backend)
开发者ID:iankronquist,项目名称:spicedham,代码行数:18,代码来源:test_spicedham.py

示例10: test_multiple_ignored

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
 def test_multiple_ignored(self):
     cb = Mock()
     cb.__name__ = 'something'
     old = len(amo_models._on_change_callbacks[Addon])
     Addon.on_change(cb)
     assert len(amo_models._on_change_callbacks[Addon]) == old + 1
     Addon.on_change(cb)
     assert len(amo_models._on_change_callbacks[Addon]) == old + 1
开发者ID:tsl143,项目名称:addons-server,代码行数:10,代码来源:test_models.py

示例11: test_run_command_with_check_output_function

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
 def test_run_command_with_check_output_function(
         self, mock_subprocess):
     check_output = Mock()
     check_output.__name__ = 'check_output'
     mock_subprocess.check_output = check_output
     run_command(self.command)
     check_output.assert_called_once_with(
         self.command, stderr=mock_subprocess.STDOUT, shell=True)
开发者ID:simodalla,项目名称:pygmount,代码行数:10,代码来源:test_core.py

示例12: test_multiple_ignored

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
 def test_multiple_ignored(self):
     cb = Mock()
     cb.__name__ = 'something'
     old = len(models._on_change_callbacks[Webapp])
     Webapp.on_change(cb)
     eq_(len(models._on_change_callbacks[Webapp]), old + 1)
     Webapp.on_change(cb)
     eq_(len(models._on_change_callbacks[Webapp]), old + 1)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:10,代码来源:test_models.py

示例13: mock_task

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
 def mock_task(self):
     raw_task = Mock()
     # functools.wraps requires the wrapped thing to have a __name__ attr,
     # which Mock()s don't usually have. Furthermore, Celery seems to do
     # some fancy behind-the-scenes caching on tasks' __name__, such that
     # tests pollute each other if the names aren't unique.
     raw_task.__name__ = str(uuid.uuid4())
     return raw_task
开发者ID:ErinCall,项目名称:catsnap,代码行数:10,代码来源:test_db_redis_coordination.py

示例14: test_register_with_validators

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
    def test_register_with_validators(self):
        mock_transform = Mock(return_value=None)
        mock_transform.__name__ = 'mock_transform'
        mock_validator1 = Mock(return_value=None)
        mock_validator1.__name__ = 'mock_validator1'
        mock_validator2 = Mock(return_value=None)
        mock_validator2.__name__ = 'mock_validator2'

        validators = [mock_validator1, mock_validator2]

        registry.register("XX", mock_transform, validators) 

        transform = registry.get("XX", "mock_transform")
        self.assertEqual(list(transform.validators.values()), validators)

        transform()
        mock_transform.assert_called_once_with()
开发者ID:openelections,项目名称:openelections-core,代码行数:19,代码来源:test_transform_registry.py

示例15: test_register_raw

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import __name__ [as 别名]
    def test_register_raw(self):
        mock_transform = Mock(return_value=None)
        mock_transform.__name__ = 'mock_transform'

        registry.register("XX", mock_transform, raw=True)
        transform = registry.get("XX", "mock_transform", raw=True)
        transform()
        mock_transform.assert_called_once_with()
开发者ID:openelections,项目名称:openelections-core,代码行数:10,代码来源:test_transform_registry.py


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