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


Python MagicMock.read方法代码示例

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


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

示例1: mock_tracks_response

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
def mock_tracks_response(uri):
    def json_res():
        return b'[{"kind":"track","id":1337,"title":"Foo","permalink":"foo","downloadable":true,"user":{"permalink":"user1"}, "original_format":"mp3"},{"kind":"track","id":1338,"title":"Bar","permalink":"bar","downloadable":true,"user":{"permalink":"user2"}, "original_format":"mp3"},{"kind":"track","id":1339,"title":"Baz","permalink":"baz","downloadable":true,"user":{"permalink":"user3"}, "original_format":"wav"}]'

    response = MagicMock()
    response.read = json_res
    return response
开发者ID:yyolk,项目名称:soundcloud-syncer,代码行数:9,代码来源:test_suser.py

示例2: mock_tracks_response

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
def mock_tracks_response(uri):
    def json_res():
        return json_bytes

    response = MagicMock()
    response.read = json_res
    return response
开发者ID:Sliim,项目名称:soundcloud-syncer,代码行数:9,代码来源:test_suser.py

示例3: test_attach_file_no_extension

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
 def test_attach_file_no_extension(self):
     msg = Message(to='me', text='hi')
     err = 'requires an extension'
     with patch(open_label, create=True) as mock_open:
         mock_file = MagicMock(spec=file)
         mock_file.read = lambda: 'x'
         mock_open.return_value = mock_file
         self.assertRaisesMessage(MessageError, err, msg.attach_file, 'bad')
开发者ID:jonathana,项目名称:pystmark,代码行数:10,代码来源:test_pystmark.py

示例4: test_call

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
 def test_call(self):
     ret = json.dumps( {u'ok':u'ok'} )
     read = MagicMock()
     read.read = MagicMock(return_value=ret)
     u = '/testing'
     with patch('urllib2.urlopen') as mock_method:
         mock_method.return_value = read
         request = ApiRequest('mm', ApcUrl(u))()
         self.assertEquals(request, json.loads(ret))
开发者ID:AtomLaw,项目名称:Airtime,代码行数:11,代码来源:test_apirequest.py

示例5: test_notify_webstream_data

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
 def test_notify_webstream_data(self):
     ret = json.dumps( {u'testing' : u'123' } )
     rp = RequestProvider(self.cfg)
     read = MagicMock()
     read.read = MagicMock(return_value=ret)
     with patch('urllib2.urlopen') as mock_method:
         mock_method.return_value = read
         response = rp.notify_webstream_data(media_id=123)
         mock_method.called_once_with(media_id=123)
         self.assertEquals(json.loads(ret), response)
开发者ID:hzlf,项目名称:pypo,代码行数:12,代码来源:test_requestprovider.py

示例6: test_read

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
 def test_read(self):
     """
     Asserts that read runs when plugin is loaded
     """
     fake_config = MagicMock()
     collectd_plugin.INSTANCES = [fake_config]
     fake_config.read = MagicMock()
     collectd_plugin.read()
     self.assertIsNotNone(collectd_plugin.CONFIGS)
     self.assertTrue(fake_config.read.called)
     collectd_plugin.INSTANCES = []
开发者ID:NYTimes,项目名称:collectd-rabbitmq,代码行数:13,代码来源:test_collectd_plugin.py

示例7: test_init

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
    def test_init(self):
        stream = MagicMock()
        stream.__iter__ = MagicMock()
        stream.__next__ = MagicMock()
        stream.next = MagicMock()
        os_stream = OpenstackStream(stream, size=1234)

        self.assertEquals(os_stream.size, 1234)
        self.assertEquals(os_stream.__len__(), 1234)
        self.assertEquals(os_stream.read(), stream.read(size=None))
        self.assertEquals(os_stream.__iter__(), stream.__iter__())
        self.assertEquals(os_stream.__next__(), stream.__next__())
        self.assertEquals(os_stream.next(), stream.__next__())
开发者ID:BillArnold,项目名称:barnoldjg,代码行数:15,代码来源:test_openstack.py

示例8: mock_open

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
def mock_open(mock=None, read_data=None):
    if mock is None:
        mock = MagicMock(spec=file_spec)

    handle = MagicMock(spec=file_spec)
    handle.write.return_value = None
    fake_file = StringIO(read_data)
    if read_data is None:
        if hasattr(handle, '__enter__'):
            handle.__enter__.return_value = handle
    else:
        if hasattr(handle, '__enter__'):
            handle.__enter__.return_value = fake_file
        handle.read = fake_file.read
    mock.return_value = handle
    return mock
开发者ID:credativ,项目名称:pulp,代码行数:18,代码来源:test_manage.py

示例9: test_should_unauthorize_child_resource_non_ajax_POST_requests_when_csrf_input_mismatch

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
    def test_should_unauthorize_child_resource_non_ajax_POST_requests_when_csrf_input_mismatch(self):
        request = DummyRequest(['mails'])
        request.method = 'POST'
        request.addArg('csrftoken', 'some csrf token')
        mock_content = MagicMock()
        mock_content.read = MagicMock(return_value={})
        request.content = mock_content

        request.getCookie = MagicMock(return_value='mismatched csrf token')

        d = self.web.get(request)

        def assert_unauthorized(_):
            self.assertEqual(401, request.responseCode)
            self.assertEqual("Unauthorized!", request.written[0])

        d.addCallback(assert_unauthorized)
        return d
开发者ID:pixelated,项目名称:pixelated-user-agent,代码行数:20,代码来源:test_root_resource.py

示例10: cpMock

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
def cpMock():
  """Return a Mock for the ConfigParser."""
  theCPMock = Mock()
  theCPMock.thisConfigDict = dict(configDict())

  def hasMock(*args, **kwargs):  # pylint: disable=unused-argument
    """Mock the configparser.has_option function."""
    return theCPMock.thisConfigDict.get(args[1])

  def mockConfig(*args, **kwargs):  # pylint: disable=unused-argument
    """Mock the configparser object."""
    assert args[0] == theScript.PP
    return theCPMock.thisConfigDict[args[1]]

  theCPMock.read = Mock()
  theCPMock.get = mockConfig
  theCPMock.has_option = hasMock
  return theCPMock
开发者ID:LCDsoft,项目名称:ILCDIRAC,代码行数:20,代码来源:Test_diracClicMakeProductions.py

示例11: test_bz2_to_file_from_url

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
    def test_bz2_to_file_from_url(self):
        m = mock_open()
        de = Mock()
        de.decompress = Mock(return_value=3)
        in_file = MagicMock()

        def foo(size):
            if foo.count < 3:
                foo.count += 1
                return size
            return None

        foo.count = 0
        in_file.read = foo
        with patch.object(get_marc, 'BZ2Decompressor', de):
            with patch.object(get_marc, 'open', m):
                self.assertTrue(get_marc.get_bz2_from_file(in_file, 'name',
                                                           lambda x, y: True))
                self.assertFalse(get_marc.get_bz2_from_file(
                    in_file, 'name', lambda x, y: False))
        handle = m()
        self.assertEqual(handle.write.call_count, 3)
开发者ID:gryftir,项目名称:gutenborg,代码行数:24,代码来源:get_marc_test.py

示例12: setUp

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
 def setUp(self):
     self.gui = MagicMock(name="gui")
     modules = {
         'urllib': self.gui,
         'urllib.request': self.gui.request,
         'urllib.request.urlopen': self.gui.request.urlopen
     }
     uop = MagicMock(name="file")
     self.gui.request.urlopen.return_value = (uop, 0, 0)
     uop.read = MagicMock(name="data", return_value=WCONT)
     self.module_patcher = patch.dict('sys.modules', modules)
     self.module_patcher.start()
     self.gui.__le__ = MagicMock(name="APPEND")
     self.gui.svg = self.gui.svg.svg = self.gui
     self.gui.side_effect = lambda *a, **k: self.gui
     self.gui.g = MagicMock(name="gui_g")
     self.gui.g.__le__ = MagicMock(name="APPENDG")
     self.gui.g.side_effect = lambda *a, **k: self.gui.g
     self.gui.document.__getitem__.return_value = self.gui
     self.app = Impressious(self.gui)
     Impressious.SLIDES = []
     self.EV.x = self.EV.y = 42
开发者ID:labase,项目名称:impressious,代码行数:24,代码来源:impressious_tests.py

示例13: get_object

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
 def get_object(self, kwargs):
     """
     This operation gets an object from s3.  It retrieves the body of
     the object or a part of the body specified by a range variable.
     A MagicMock() class is used to transfer the body allowing it to
     be read by a read() operation.  The etags no matter if it is
     a multipart download or not is invalid as it will have a dash
     in the etags.  So it is never compared during download.  If the
     session's connection_error flag is set, it will raise a
     ConnectionError and reset the flag to False.
     """
     bucket = kwargs['bucket']
     key = kwargs['key']
     response_data = {}
     etag = ''
     if bucket in self.session.s3:
         body = self.session.s3[bucket][key]['Body']
         if 'range' in kwargs:
             str_range = kwargs['range']
             str_range = str_range[6:]
             range_components = str_range.split('-')
             beginning = range_components[0]
             end = range_components[1]
             if end == '':
                 body = body[int(beginning):]
             else:
                 body = body[int(beginning):(int(end) + 1)]
         mock_response = MagicMock()
         mock_response.read = MagicMock(return_value=body)
         response_data['Body'] = mock_response
         etag = self.session.s3[bucket][key]['ETag']
         response_data['ETag'] = etag + '--'
     else:
         response_data['Errors'] = [{'Message': 'Bucket does not exist'}]
     if self.session.connection_error:
         self.session.connection_error = False
         raise requests.ConnectionError
     return FakeHttp(etag), response_data
开发者ID:50onRed,项目名称:aws-cli,代码行数:40,代码来源:fake_session.py

示例14: mock_nrrd

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
def mock_nrrd():
    mocked_nrrd = MagicMock()
    mocked_nrrd.read = MagicMock(return_value=('mock_annotation_data',
                                               'mock_annotation_image'))
    return mocked_nrrd
开发者ID:AllenInstitute,项目名称:AllenSDK,代码行数:7,代码来源:test_reference_space_api.py

示例15: build_mock_response

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import read [as 别名]
 def build_mock_response(http_code, content=None):
     response = MagicMock()
     response.getcode = MagicMock(return_value=http_code)
     if content is not None:
         response.read = MagicMock(return_value=json.dumps(content).encode('utf-8'))
     return response
开发者ID:adamfazzari,项目名称:radiotherm,代码行数:8,代码来源:test_validate_response.py


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