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


Python mox.IsA方法代码示例

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


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

示例1: testMultipleTimesUsingIsAParameter

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def testMultipleTimesUsingIsAParameter(self):
    """Test if MultipleTimesGroup works with a IsA parameter."""
    mock_obj = self.mox.CreateMockAnything()
    mock_obj.Open()
    mock_obj.Method(mox.IsA(str)).MultipleTimes("IsA").AndReturn(9)
    mock_obj.Close()
    self.mox.ReplayAll()

    mock_obj.Open()
    actual_one = mock_obj.Method("1")
    second_one = mock_obj.Method("2") # This tests MultipleTimes.
    mock_obj.Close()

    self.assertEquals(9, actual_one)
    self.assertEquals(9, second_one) # Repeated calls should return same number.

    self.mox.VerifyAll() 
开发者ID:elsigh,项目名称:browserscope,代码行数:19,代码来源:mox_test.py

示例2: test_send

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def test_send(self):
    self.mox.StubOutWithMock(xmpp_request_handler.XmppRequestHandler,
                             'dispatcher')

    handler = xmpp_request_handler.XmppRequestHandler()
    handler.dispatcher = self.mox.CreateMock(dispatcher.Dispatcher)
    handler.dispatcher.add_request(
        method='POST',
        relative_url='url',
        headers=[('Content-Type',
                  mox.Regex('multipart/form-data; boundary=".*?"'))],
        body=mox.IsA(str),
        source_ip='0.1.0.10',
        fake_login=True)

    data = xmpp_request_handler._FormData()
    self.mox.ReplayAll()
    handler._send('url', data)
    self.mox.VerifyAll() 
开发者ID:elsigh,项目名称:browserscope,代码行数:21,代码来源:xmpp_request_handler_test.py

示例3: test_generate_discovery_doc_rest

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def test_generate_discovery_doc_rest(self):
    body = json.dumps(
        {'baseUrl': 'https://tictactoe.appspot.com/_ah/api/tictactoe/v1/'})
    discovery = self.prepare_discovery_request(body)
    discovery._discovery_proxy.generate_discovery_doc(
        mox.IsA(object), 'rest').AndReturn(body)

    self.mox.ReplayAll()
    response = discovery.handle_discovery_request(
        discovery_service.DiscoveryService._GET_REST_API, self.api_request,
        self.start_response)
    self.mox.VerifyAll()

    self.assert_http_match(response, 200,
                           [('Content-Type', 'application/json; charset=UTF-8'),
                            ('Content-Length', '%d' % len(body))],
                           body) 
开发者ID:elsigh,项目名称:browserscope,代码行数:19,代码来源:discovery_service_test.py

示例4: test_generate_discovery_doc_rpc

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def test_generate_discovery_doc_rpc(self):
    body = json.dumps({'rpcUrl': 'https://tictactoe.appspot.com/_ah/api/rpc'})
    discovery = self.prepare_discovery_request(body)
    discovery._discovery_proxy.generate_discovery_doc(
        mox.IsA(object), 'rpc').AndReturn(body)

    self.mox.ReplayAll()
    response = discovery.handle_discovery_request(
        discovery_service.DiscoveryService._GET_RPC_API, self.api_request,
        self.start_response)
    self.mox.VerifyAll()

    self.assert_http_match(response, 200,
                           [('Content-Type', 'application/json; charset=UTF-8'),
                            ('Content-Length', '%d' % len(body))],
                           body) 
开发者ID:elsigh,项目名称:browserscope,代码行数:18,代码来源:discovery_service_test.py

示例5: test_generate_directory

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def test_generate_directory(self):
    body = json.dumps({'kind': 'discovery#directoryItem'})
    discovery = self.prepare_discovery_request(body)
    discovery._discovery_proxy.generate_directory(
        mox.IsA(list)).AndReturn(body)

    self.mox.ReplayAll()
    response = discovery.handle_discovery_request(
        discovery_service.DiscoveryService._LIST_API, self.api_request,
        self.start_response)
    self.mox.VerifyAll()

    self.assert_http_match(response, 200,
                           [('Content-Type', 'application/json; charset=UTF-8'),
                            ('Content-Length', '%d' % len(body))],
                           body) 
开发者ID:elsigh,项目名称:browserscope,代码行数:18,代码来源:discovery_service_test.py

示例6: expect_crop

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def expect_crop(self, left_x=None, right_x=None, top_y=None, bottom_y=None):
    """Setup a mox expectation to images_stub._Crop."""
    crop_xform = images_service_pb.Transform()
    if left_x is not None:
      if not isinstance(left_x, float):
        raise self.failureException('Crop argument must be a float.')
      crop_xform.set_crop_left_x(left_x)
    if right_x is not None:
      if not isinstance(right_x, float):
        raise self.failureException('Crop argument must be a float.')
      crop_xform.set_crop_right_x(right_x)
    if top_y is not None:
      if not isinstance(top_y, float):
        raise self.failureException('Crop argument must be a float.')
      crop_xform.set_crop_top_y(top_y)
    if bottom_y is not None:
      if not isinstance(bottom_y, float):
        raise self.failureException('Crop argument must be a float.')
      crop_xform.set_crop_bottom_y(bottom_y)
    self._images_stub._Crop(mox.IsA(Image.Image), crop_xform).AndReturn(
        self._image) 
开发者ID:elsigh,项目名称:browserscope,代码行数:23,代码来源:blob_image_test.py

示例7: test_add_while_started

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def test_add_while_started(self):
    servr = ManualScalingServerFacade(instance_factory=self.factory)

    inst = self.mox.CreateMock(instance.Instance)
    self.mox.StubOutWithMock(server._THREAD_POOL, 'submit')
    self.mox.StubOutWithMock(wsgi_server.WsgiServer, 'start')
    self.mox.StubOutWithMock(wsgi_server.WsgiServer, 'port')
    wsgi_server.WsgiServer.port = 12345
    self.factory.new_instance(0, expect_ready_request=True).AndReturn(inst)
    wsgi_server.WsgiServer.start()
    server._THREAD_POOL.submit(servr._start_instance,
                               mox.IsA(wsgi_server.WsgiServer), inst)

    self.mox.ReplayAll()
    servr._add_instance()
    self.mox.VerifyAll()
    self.assertIn(inst, servr._instances)
    self.assertEqual((servr, inst), servr._port_registry.get(12345)) 
开发者ID:elsigh,项目名称:browserscope,代码行数:20,代码来源:server_test.py

示例8: expectSubscribe

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def expectSubscribe(self, phone=None, pledgePageSlug=None):
    if phone is None:
      phone = '212-234-5432'
    if pledgePageSlug is None:
      pledgePageSlug = '28e9-Team-Shant-is-Shant'
    self.mailing_list_subscriber \
        .Subscribe(email=self.pledge['email'],
                   first_name=u'Pik\u00E1',
                   last_name='Chu',
                   amount_cents=4200,
                   ip_addr=None,  # Not sure why this is None in unittests
                   time=mox.IsA(datetime.datetime),
                   phone=phone,
                   source='pledge',
                   nonce=mox.Regex('.*'),)
                   # pledgePageSlug=pledgePageSlug) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:18,代码来源:test_e2e.py

示例9: testBadTokenization

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def testBadTokenization(self):
    mock_error_handler = self.mox.CreateMock(errorhandler.ErrorHandler)

    def ValidateError(err):
      return (isinstance(err, error.Error) and
              err.code is errors.FILE_IN_BLOCK and
              err.token.string == '}')

    mock_error_handler.HandleFile('foo.js', mox.IsA(tokens.Token))
    mock_error_handler.HandleError(mox.Func(ValidateError))
    mock_error_handler.HandleError(mox.IsA(error.Error))
    mock_error_handler.FinishFile()

    self.mox.ReplayAll()

    source = StringIO.StringIO(_BAD_TOKENIZATION_SCRIPT)
    runner.Run('foo.js', mock_error_handler, source)

    self.mox.VerifyAll() 
开发者ID:google,项目名称:closure-linter,代码行数:21,代码来源:runner_test.py

示例10: testCollectSample

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def testCollectSample(self):
    obj_name = 'InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.'
    obj_param = 'TotalBytesSent'
    sampled_param = periodic_statistics.PeriodicStatistics.SampleSet.Parameter()
    sampled_param.Enable = True
    sampled_param.Reference = obj_name + obj_param
    sample_set = periodic_statistics.PeriodicStatistics.SampleSet()
    m = mox.Mox()
    mock_root = m.CreateMock(tr.core.Exporter)
    mock_root.GetExport(mox.IsA(str)).AndReturn(1000)
    m.ReplayAll()

    sample_set.SetCpeAndRoot(cpe=object(), root=mock_root)
    sample_set.SetParameter('1', sampled_param)
    sample_set.CollectSample()
    m.VerifyAll()

    # Check that the sampled_param updated it's values.
    self.assertEqual('1000', sampled_param.Values) 
开发者ID:omererdem,项目名称:honeything,代码行数:21,代码来源:periodic_statistics_test.py

示例11: test_add_while_started

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def test_add_while_started(self):
    servr = ManualScalingModuleFacade(instance_factory=self.factory)

    inst = self.mox.CreateMock(instance.Instance)
    self.mox.StubOutWithMock(module._THREAD_POOL, 'submit')
    self.mox.StubOutWithMock(wsgi_server.WsgiServer, 'start')
    self.mox.StubOutWithMock(wsgi_server.WsgiServer, 'port')
    wsgi_server.WsgiServer.port = 12345
    self.factory.new_instance(0, expect_ready_request=True).AndReturn(inst)
    wsgi_server.WsgiServer.start()
    module._THREAD_POOL.submit(servr._start_instance,
                               mox.IsA(wsgi_server.WsgiServer), inst)

    self.mox.ReplayAll()
    servr._add_instance()
    self.mox.VerifyAll()
    self.assertIn(inst, servr._instances)
    self.assertEqual((servr, inst), servr._port_registry.get(12345)) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:20,代码来源:module_test.py

示例12: expect_crop

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def expect_crop(self, left_x=None, right_x=None, top_y=None, bottom_y=None):
    """Setup a mox expectation to images_stub._Crop."""
    crop_xform = images_service_pb.Transform()
    if left_x is not None:
      if not isinstance(left_x, float):
        raise self.failureException('Crop argument must be a float.')
      crop_xform.set_crop_left_x(left_x)
    if right_x is not None:
      if not isinstance(right_x, float):
        raise self.failureException('Crop argument must be a float.')
      crop_xform.set_crop_right_x(right_x)
    if top_y is not None:
      if not isinstance(top_y, float):
        raise self.failureException('Crop argument must be a float.')
      crop_xform.set_crop_top_y(top_y)
    if bottom_y is not None:
      if not isinstance(bottom_y, float):
        raise self.failureException('Crop argument must be a float.')
      crop_xform.set_crop_bottom_y(bottom_y)
    self._images_stub._Crop(mox.IsA(MockImage), crop_xform).AndReturn(
        self._image) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:23,代码来源:blob_image_test.py

示例13: testContextFlush

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def testContextFlush(self):
    """Test context handling."""
    TestEntity().put()

    # Stub out context
    m = mox.Mox()
    m.StubOutWithMock(context.Context, "_set", use_mock_anything=True)
    m.StubOutWithMock(context.Context, "flush", use_mock_anything=True)

    # Record calls
    context.Context._set(mox.IsA(context.Context))
    context.Context.flush()
    context.Context._set(None)

    m.ReplayAll()
    try: # test, verify
      self.handler.post()

      #  1 entity should be processed
      self.assertEquals(1, len(TestHandler.processed_keys))

      m.VerifyAll()
    finally:
      m.UnsetStubs() 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:26,代码来源:handlers_test.py

示例14: testFirstMapper

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def testFirstMapper(self):
    """Make sure service attribute works when matches first RPCMapper."""
    self.rpc_mapper1.build_request(
        self.handler, Request1).AndReturn(self.request)

    def build_response(handler, response):
      output = '%s %s %s' % (response.integer_field,
                             response.string_field,
                             response.enum_field)
      handler.response.headers['content-type'] = (
        'application/x-www-form-urlencoded')
      handler.response.out.write(output)
    self.rpc_mapper1.build_response(
        self.handler, mox.IsA(Response1)).WithSideEffects(build_response)

    self.mox.ReplayAll()

    self.handler.handle('POST', '/my_service', 'method1')

    self.VerifyResponse('200', 'OK', '1 a VAL1')

    self.mox.VerifyAll() 
开发者ID:google,项目名称:protorpc,代码行数:24,代码来源:service_handlers_test.py

示例15: testResponseException

# 需要导入模块: import mox [as 别名]
# 或者: from mox import IsA [as 别名]
def testResponseException(self):
    """Test what happens when build_response raises ResponseError."""
    self.rpc_mapper1.build_request(
        self.handler, Request1).AndReturn(self.request)

    self.rpc_mapper1.build_response(
        self.handler, mox.IsA(Response1)).AndRaise(
        service_handlers.ResponseError)

    self.ExpectRpcError(self.rpc_mapper1,
                        remote.RpcState.SERVER_ERROR,
                        'Internal Server Error')

    self.mox.ReplayAll()

    self.handler.handle('POST', '/my_service', 'method1')

    self.VerifyResponse('500', 'Internal Server Error', '')

    self.mox.VerifyAll() 
开发者ID:google,项目名称:protorpc,代码行数:22,代码来源:service_handlers_test.py


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