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


Python mocker.Mocker类代码示例

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


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


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