• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python mocker.Mocker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test

 def test(action, app_method):
     delegate = mod.AppDelegate.alloc().init()
     m = Mocker()
     delegate.app = app = m.mock(Application)
     getattr(app, app_method)()
     with m:
         getattr(delegate, action)(None)
开发者ID:editxt,项目名称:editxt,代码行数:7,代码来源:test_app.py


示例2: test_move

    def test_move(self):
        """Move."""
        mocker = Mocker()

        # node, with a generation attribute
        node = mocker.mock()
        expect(node.generation).result(123)
        expect(node.mimetype).result("mime")

        # user, with the chained calls to the operation
        user = mocker.mock()
        new_parent_id = uuid.uuid4()
        expect(user.volume("vol_id").node("node_id").move(new_parent_id, "new_name")).result(node)
        self.dal._get_user = lambda *a: user

        with mocker:
            kwargs = dict(
                user_id="user_id",
                volume_id="vol_id",
                node_id="node_id",
                new_parent_id=new_parent_id,
                new_name="new_name",
                session_id="session_id",
            )
            result = self.dal.move(**kwargs)

        self.assertEqual(result, dict(generation=123, mimetype="mime"))
开发者ID:cloudfleet,项目名称:filesync-server,代码行数:27,代码来源:test_dal_backend.py


示例3: test_list_volumes_root_and_quota

    def test_list_volumes_root_and_quota(self):
        """List volumes, check root and quota."""
        mocker = Mocker()

        # root
        root = mocker.mock()
        expect(root.generation).result(123)
        expect(root.root_id).result("root_id")

        # quota
        quota = mocker.mock()
        expect(quota.free_bytes).result(4567890)

        # user
        user = mocker.mock()
        self.dal._get_user = lambda *a: user
        expect(user.volume().get_volume()).result(root)
        expect(user.get_shared_to(accepted=True)).result([])
        expect(user.get_udfs()).result([])
        expect(user.get_quota()).result(quota)

        with mocker:
            result = self.dal.list_volumes("user_id")

        self.assertEqual(sorted(result), ["free_bytes", "root", "shares", "udfs"])
        self.assertEqual(result["root"], dict(generation=123, root_id="root_id"))
        self.assertEqual(result["free_bytes"], 4567890)
开发者ID:cloudfleet,项目名称:filesync-server,代码行数:27,代码来源:test_dal_backend.py


示例4: test

 def test(c):
     m = Mocker()
     menu = m.mock(ak.NSMenu)
     ctl = CommandManager("<history>")
     for command in c.commands:
         ctl.add_command(command, None, menu)
     eq_(ctl.lookup(c.lookup), c.result)
开发者ID:editxt,项目名称:editxt,代码行数:7,代码来源:test_textcommand.py


示例5: test_reload_config

def test_reload_config():
    from editxt.config import Config
    m = Mocker()
    tv = m.mock(ak.NSTextView)
    tv.app.reload_config()
    with m:
        mod.reload_config(tv, None)
开发者ID:editxt,项目名称:editxt,代码行数:7,代码来源:test_commands.py


示例6: test_call_valid

    def test_call_valid(self):
        reg = getUtility(IRegistry).forInterface(ICollectiveFlattr)
        reg.access_token = u''

        mocker = Mocker()
        func = mocker.replace('collective.flattr.browser.flattr.Flattr.getAccessToken')
        func(u'un8Vzv7pNMXNuAQY3uRgjYfM4V3Feirz')
        mocker.result({'access_token': u'NEW_ACCESS_TOKEN',
            'token_type': u'bearer'})

        with as_manager(self.portal) as view:
            ## need the real class here, not the wrapped one, to get mocker
            ## working
            from collective.flattr.browser.flattr import Flattr

            with mocker:
                self.layer['request']['code'] = u'un8Vzv7pNMXNuAQY3uRgjYfM4V3Feirz'
                view = Flattr(self.portal, self.layer['request'])

                ret = view()
                self.assertEquals(reg.access_token, u'NEW_ACCESS_TOKEN')
                self.assertEquals(self.layer['request'].response\
                    .headers['location'], 'http://nohost/plone')
                ret = IStatusMessage(self.layer['request'])\
                    .showStatusMessages()[0]
                self.assertEquals(ret.message,
                    u'collective.flattr successfully configured')
                self.assertEquals(ret.type, u'info')
开发者ID:chrigl,项目名称:docker-library,代码行数:28,代码来源:test_flattr_view.py


示例7: test_add_part_to_uploadjob

    def test_add_part_to_uploadjob(self):
        """Delete an uploadjob."""
        mocker = Mocker()

        # upload job
        uj = mocker.mock()
        expect(uj.add_part('chunk_size', 'inflated_size', 'crc32',
                           'hash_context', 'magic_hash_context',
                           'decompress_context'))

        # user
        user = mocker.mock()
        self.dal._get_user = lambda *a: user
        expect(user.volume('volume_id')
               .get_uploadjob('uploadjob_id')).result(uj)

        with mocker:
            d = dict(user_id='user_id', uploadjob_id='uploadjob_id',
                     chunk_size='chunk_size', inflated_size='inflated_size',
                     crc32='crc32', hash_context='hash_context',
                     magic_hash_context='magic_hash_context',
                     decompress_context='decompress_context',
                     volume_id='volume_id')
            result = self.dal.add_part_to_uploadjob(**d)

        self.assertEqual(result, {})
开发者ID:CSRedRat,项目名称:magicicada-server,代码行数:26,代码来源:test_dal_backend.py


示例8: test_make_file_with_content

    def test_make_file_with_content(self):
        """Make a file with content associated."""
        mocker = Mocker()

        # node, with a generation attribute
        node = mocker.mock()
        expect(node.id).result('node_id')
        expect(node.generation).result(123)

        # user, with the chained calls to the operation
        user = mocker.mock()
        expect(user.volume('vol_id').dir('parent_id')
               .make_file_with_content('name', 'hash', 'crc32', 'size',
                                       'deflated_size', 'storage_key')
               ).result(node)
        self.dal._get_user = lambda *a: user

        with mocker:
            kwargs = dict(user_id='user_id', volume_id='vol_id', name='name',
                          parent_id='parent_id', crc32='crc32', size='size',
                          node_hash='hash', deflated_size='deflated_size',
                          storage_key='storage_key', session_id='session_id')
            result = self.dal.make_file_with_content(**kwargs)

        self.assertEqual(result, dict(generation=123, node_id='node_id'))
开发者ID:CSRedRat,项目名称:magicicada-server,代码行数:25,代码来源:test_dal_backend.py


示例9: test_wrap_to_margin_guide

def test_wrap_to_margin_guide():
    m = Mocker()
    tv = m.mock(ak.NSTextView)
    wrap = m.replace(mod, 'wrap_selected_lines')
    wrap(tv, mod.Options(wrap_column=const.DEFAULT_RIGHT_MARGIN, indent=True))
    with m:
        mod.wrap_at_margin(tv, None, None)
开发者ID:khairy,项目名称:editxt,代码行数:7,代码来源:test_wraplines.py


示例10: test

 def test(c):
     m = Mocker()
     options = make_options(c)
     tv = m.mock(TextView)
     tv.selectedRange() >> fn.NSMakeRange(0, 16)
     tv.string() >> fn.NSString.alloc().initWithString_(c.text)
     if not isinstance(c.expect, Exception):
         result = [c.text]
         def replace(range, value):
             start, end = range
             text = result[0]
             result[0] = text[:start] + value + text[start + end:]
         tv.shouldChangeTextInRange_replacementString_(ANY, ANY) >> True
         expect(tv.textStorage().replaceCharactersInRange_withString_(
             ANY, ANY)).call(replace)
         tv.didChangeText()
         tv.setNeedsDisplay_(True)
     finder = Finder((lambda: tv), options)
     with m:
         if isinstance(c.expect, Exception):
             def check(err):
                 print(err)
                 eq_(str(err), str(c.expect))
             with assert_raises(type(c.expect), msg=check):
                 getattr(finder, c.action)(None)
         else:
             getattr(finder, c.action)(None)
             eq_(result[0], c.expect)
开发者ID:khairy,项目名称:editxt,代码行数:28,代码来源:test_find.py


示例11: test

 def test(c):
     m = Mocker()
     sv = ThinSplitView.alloc().init()
     nsanim = m.replace(NSViewAnimation, passthrough=False)
     nsdict = m.replace(NSDictionary, passthrough=False)
     nsval = m.replace(NSValue, passthrough=False)
     nsarr = m.replace(NSArray, passthrough=False)
     view = m.mock(NSView)
     rect = m.mock(NSRect)
     rval = nsval.valueWithRect_(rect) >> m.mock()
     resize = nsdict.dictionaryWithObjectsAndKeys_(
         view, NSViewAnimationTargetKey, rval, NSViewAnimationEndFrameKey, None
     ) >> m.mock(NSDictionary)
     anims = nsarr.arrayWithObject_(resize) >> m.mock(NSArray)
     anim = nsanim.alloc() >> m.mock(NSViewAnimation)
     anim.initWithViewAnimations_(anims) >> anim
     anim.setDuration_(0.5)
     if c.delegate:
         delegate = m.mock(RedrawOnAnimationEndedDelegate)
         anim.setDelegate_(delegate)
     else:
         delegate = None
     anim.startAnimation()
     with m:
         sv._animate_view(view, rect, delegate)
开发者ID:youngrok,项目名称:editxt,代码行数:25,代码来源:test_splitview.py


示例12: test_set_main_view_of_window

def test_set_main_view_of_window():
    proj = Project.create()
    m = Mocker()
    view = m.mock(NSView)
    win = m.mock(NSWindow)
    with m:
        proj.set_main_view_of_window(view, win) # for now this does nothing
开发者ID:youngrok,项目名称:editxt,代码行数:7,代码来源:test_project.py


示例13: test_collect_process_info_new_report

    def test_collect_process_info_new_report(self):
        """Check how the process info is collected first time."""
        mocker = Mocker()
        assert not self.worker.process_cache

        # patch Process to return our mock for test pid
        Process = mocker.mock()
        self.patch(stats_worker.psutil, 'Process', Process)
        proc = mocker.mock()
        pid = 1234
        expect(Process(pid)).result(proc)

        # patch ProcessReport to return or mock for given proc
        ProcessReport = mocker.mock()
        self.patch(stats_worker, 'ProcessReport', ProcessReport)
        proc_report = mocker.mock()
        expect(ProcessReport(proc)).result(proc_report)

        # expect to get called with some info, return some results
        name = 'test_proc'
        result = object()
        expect(proc_report.get_memory_and_cpu(prefix=name)).result(result)

        with mocker:
            real = self.worker._collect_process(pid, name)
        self.assertIdentical(real, result)
开发者ID:CSRedRat,项目名称:magicicada-server,代码行数:26,代码来源:test_stats_worker.py


示例14: test_SyntaxFactory_index_definitions

def test_SyntaxFactory_index_definitions():
    from editxt.valuetrans import SyntaxDefTransformer
    class FakeDef(object):
        def __init__(self, name):
            self.name = name
        def __repr__(self):
            return "<%s %x>" % (self.name, id(self))
    text1 = FakeDef("Plain Text")
    text2 = FakeDef("Plain Text")
    python = FakeDef("Python")
    sf = SyntaxFactory()
    sf.registry = {
        "*.txt": text1,
        "*.text": text2,
        "*.txtx": text1,
        "*.py": python,
    }
    defs = sorted([text1, text2, python], key=lambda d:(d.name, id(d)))
    m = Mocker()
    vt = m.replace(NSValueTransformer, passthrough=False)
    st = vt.valueTransformerForName_("SyntaxDefTransformer") >> \
        m.mock(SyntaxDefTransformer)
    st.update_definitions(defs)
    with m:
        sf.index_definitions()
    eq_(sf.definitions, defs)
开发者ID:youngrok,项目名称:editxt,代码行数:26,代码来源:test_syntax.py


示例15: test_create_share

    def test_create_share(self):
        """Create a share."""
        mocker = Mocker()

        # patch the DAL method to get the other user id from the username
        to_user = mocker.mock()
        expect(to_user.id).result('to_user_id')
        fake = mocker.mock()
        expect(fake(username='to_username')).result(to_user)
        self.patch(dal_backend.services, 'get_storage_user', fake)

        # share
        share = mocker.mock()
        expect(share.id).result('share_id')

        # user, with the chained calls to the operation
        user = mocker.mock()
        expect(user.volume().dir('node_id').share(
            'to_user_id', 'name', True)).result(share)
        self.dal._get_user = lambda *a: user

        with mocker:
            result = self.dal.create_share('user_id', 'node_id',
                                           'to_username', 'name', True)
        self.assertEqual(result, dict(share_id='share_id'))
开发者ID:CSRedRat,项目名称:magicicada-server,代码行数:25,代码来源:test_dal_backend.py


示例16: test_call_invalid_request

    def test_call_invalid_request(self):
        reg = getUtility(IRegistry).forInterface(ICollectiveFlattr)
        reg.access_token = u''

        mocker = Mocker()
        func = mocker.replace('collective.flattr.browser.flattr.Flattr.getAccessToken')
        func(u'un8Vzv7pNMXNuAQY3uRgjYfM4V3Feirz')
        mocker.result({'error': u'invalid_request',
            'error_description': u'error desc'})

        with as_manager(self.portal) as view:
            ## need the real class here, not the wrapped one, to get mocker
            ## working
            from collective.flattr.browser.flattr import Flattr

            with mocker:
                view = Flattr(self.portal, self.layer['request'])
                self.layer['request']['code'] = u'un8Vzv7pNMXNuAQY3uRgjYfM4V3Feirz'
                ret = view()
                self.assertEquals(self.layer['request'].response\
                    .headers['location'], 'http://nohost/plone')
                ret = IStatusMessage(self.layer['request'])\
                    .showStatusMessages()[0]
                self.assertEquals(ret.message, u'invalid_request: error desc')
                self.assertEquals(ret.type, u'error')
开发者ID:chrigl,项目名称:docker-library,代码行数:25,代码来源:test_flattr_view.py


示例17: test_get_share

    def test_get_share(self):
        """Get a share."""
        mocker = Mocker()

        # the share
        share = mocker.mock()
        expect(share.id).result('share_id')
        expect(share.root_id).result('share_root_id')
        expect(share.name).result('name')
        expect(share.shared_by_id).result('shared_by_id')
        expect(share.shared_to_id).result('shared_to_id')
        expect(share.accepted).result(True)
        expect(share.access).result(1)

        # user
        user = mocker.mock()
        self.dal._get_user = lambda *a: user
        expect(user.get_share('share_id')).result(share)

        with mocker:
            result = self.dal.get_share('user_id', 'share_id')
        should = dict(share_id='share_id', share_root_id='share_root_id',
                      name='name', shared_by_id='shared_by_id', accepted=True,
                      shared_to_id='shared_to_id', access=1)
        self.assertEqual(result, should)
开发者ID:CSRedRat,项目名称:magicicada-server,代码行数:25,代码来源:test_dal_backend.py


示例18: test_call_no_unicode_and_no_error_desc

    def test_call_no_unicode_and_no_error_desc(self):
        reg = getUtility(IRegistry).forInterface(ICollectiveFlattr)
        reg.access_token = u''

        mocker = Mocker()
        func = mocker.replace('collective.flattr.browser.flattr.Flattr.getAccessToken')
        func(u'un8Vzv7pNMXNuAQY3uRgjYfM4V3Feirz')
        mocker.result({'access_token': u'NEW_ACCESS_TOKEN',
            'token_type': u'bearer', 'error': u'blubber'})

        with as_manager(self.portal) as view:
            from collective.flattr.browser.flattr import Flattr
            with mocker:
                self.layer['request']['code'] = 'un8Vzv7pNMXNuAQY3uRgjYfM4V3Feirz'
                view = Flattr(self.portal, self.layer['request'])

                ret = view()
                self.assertEquals(reg.access_token, u'')
                self.assertEquals(self.layer['request'].response\
                    .headers['location'], 'http://nohost/plone')
                ret = IStatusMessage(self.layer['request'])\
                    .showStatusMessages()
                self.assertEquals(ret[0].message,
                    u'undefined: Undefined error while getting access token')
                self.assertEquals(ret[0].type, u'error')
开发者ID:chrigl,项目名称:docker-library,代码行数:25,代码来源:test_flattr_view.py


示例19: test_make_content

    def test_make_content(self):
        """Make content."""
        mocker = Mocker()

        # node 'old gen'
        node = mocker.mock()
        expect(node.generation).result('new_generation')
        expect(node.make_content('original_hash', 'hash_hint', 'crc32_hint',
                                 'inflated_size_hint', 'deflated_size_hint',
                                 'storage_key', 'magic_hash'))

        # user
        user = mocker.mock()
        expect(user.volume('volume_id').get_node('node_id')).result(node)
        self.dal._get_user = lambda *a: user

        with mocker:
            d = dict(user_id='user_id', volume_id='volume_id',
                     node_id='node_id', original_hash='original_hash',
                     hash_hint='hash_hint', crc32_hint='crc32_hint',
                     inflated_size_hint='inflated_size_hint',
                     deflated_size_hint='deflated_size_hint',
                     storage_key='storage_key', magic_hash='magic_hash',
                     session_id=None)
            result = self.dal.make_content(**d)
        self.assertEqual(result, dict(generation='new_generation'))
开发者ID:CSRedRat,项目名称:magicicada-server,代码行数:26,代码来源:test_dal_backend.py


示例20: test

 def test(c):
     if c.eol != "\n":
         c.input = c.input.replace("\n", c.eol)
         c.output = c.output.replace("\n", c.eol)
     result = TestConfig()
     default = False
     m = Mocker()
     tv = m.mock(ak.NSTextView)
     (tv.doc_view.document.indent_mode << c.mode).count(0, None)
     (tv.doc_view.document.indent_size << c.size).count(0, None)
     (tv.doc_view.document.eol << c.eol).count(0, None)
     sel = fn.NSMakeRange(*c.oldsel); (tv.selectedRange() << sel).count(0, None)
     (tv.string() << fn.NSString.stringWithString_(c.input)).count(0, None)
     (tv.shouldChangeTextInRange_replacementString_(ANY, ANY) << True).count(0, None)
     ts = m.mock(ak.NSTextStorage); (tv.textStorage() << ts).count(0, None)
     c.setup(m, c, TestConfig(locals()))
     def do_text(sel, repl):
         result.text = c.input[:sel[0]] + repl + c.input[sel[0] + sel[1]:]
     expect(ts.replaceCharactersInRange_withString_(ANY, ANY)).call(do_text).count(0, None)
     def do_sel(sel):
         result.sel = sel
     expect(tv.setSelectedRange_(ANY)).call(do_sel).count(0, None)
     expect(tv.didChangeText()).count(0, None)
     if c.scroll:
         tv.scrollRangeToVisible_(ANY)
     with m:
         c.method(tv, None, None)
         if "text" in result:
             eq_(result.text, c.output)
         else:
             eq_(c.output, SAME)
         if "sel" in result:
             eq_(result.sel, c.newsel)
开发者ID:khairy,项目名称:editxt,代码行数:33,代码来源:test_commands.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mocket.Mocket类代码示例发布时间:2022-05-27
下一篇:
Python mocker.expect函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap