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


Python mock.mockMethod函数代码示例

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


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

示例1: testRaiseErrorIfProddefSchemaIncompatible

    def testRaiseErrorIfProddefSchemaIncompatible(self):
        handle = self.getRbuildHandle()
        from rbuild_plugins.rebase import proddef
        from rbuild_plugins.rebase import IncompatibleProductDefinitionError
        from rbuild_plugins.rebase import OlderProductDefinitionError
        rbuilder = handle.facade.rbuilder

        mock.mockMethod(rbuilder.getProductDefinitionSchemaVersion)
        mock.mock(proddef, 'ProductDefinition')
        proddef.ProductDefinition._mock.set(version='4.0')

        # client newer than server, no change in schema version
        rbuilder.getProductDefinitionSchemaVersion._mock.setReturn('2.0')
        self.failUnlessEqual('2.0',
            handle.Rebase._getrBuilderProductDefinitionSchemaVersion('2.0'))
        # client newer than server, change in schema version
        self.failUnlessEqual('2.0',
            handle.Rebase._getrBuilderProductDefinitionSchemaVersion('1.0'))

        # client same version as server
        rbuilder.getProductDefinitionSchemaVersion._mock.setReturn('4.0')
        self.failUnlessEqual('4.0',
            handle.Rebase._getrBuilderProductDefinitionSchemaVersion('4.0'))

        # client older than server
        rbuilder.getProductDefinitionSchemaVersion._mock.setReturn('5.0')
        self.failUnlessRaises(OlderProductDefinitionError,
            handle.Rebase._getrBuilderProductDefinitionSchemaVersion,
            '4.0')
        self.failUnlessRaises(IncompatibleProductDefinitionError,
            handle.Rebase._getrBuilderProductDefinitionSchemaVersion,
            '4.0')
开发者ID:fedora-conary,项目名称:rbuild,代码行数:32,代码来源:rebasetest.py

示例2: testDelete

    def testDelete(self):
        handle = self.handle

        _target1 = mock.MockObject(name="foo", id="1")
        _target2 = mock.MockObject(name="bar", id="2")
        mock.mockMethod(handle.facade.rbuilder.getTargets)
        handle.facade.rbuilder.getTargets._mock.setReturn(
            [_target1, _target2])
        handle.facade.rbuilder.getTargets._mock.appendReturn(
            [_target1], target_id="1")
        handle.facade.rbuilder.getTargets._mock.appendReturn(
            [], target_id="bar")

        mock.mock(handle, "ui")
        handle.ui.getYn._mock.setDefaultReturn(False)
        handle.ui.getYn._mock.setReturn(True, "Delete foo?", default=False)
        handle.ui.getYn._mock.setReturn(True, "Delete bar?", default=False)


        handle.Targets.delete("1", force=True)
        handle.facade.rbuilder.getTargets._mock.assertCalled(target_id="1")
        handle.ui.getYn._mock.assertNotCalled()
        _target1.delete._mock.assertCalled()

        handle.Targets.delete("1")
        handle.facade.rbuilder.getTargets._mock.assertCalled(target_id="1")
        handle.ui.getYn._mock.assertCalled("Delete foo?", default=False)
        _target1.delete._mock.assertCalled()

        handle.Targets.delete("bar")
        handle.facade.rbuilder.getTargets._mock.assertCalled(target_id="bar")
        handle.facade.rbuilder.getTargets._mock.assertCalled()
        handle.ui.getYn._mock.assertCalled("Delete bar?", default=False)
        _target2.delete._mock.assertCalled()
开发者ID:sassoftware,项目名称:rbuild,代码行数:34,代码来源:targetstest.py

示例3: _mock

    def _mock(self, data=None, buildData=None):
        self.data.update(data or {})
        self.data['data'].update(buildData or {})

        self.vmwareDisk = disk = mock.MockObject()
        def mockMakeHDImage(image):
            buf = ''.join(chr(x) for x in range(32, 128))
            f = file(image, "w")
            for i in range(1024*1024):
                f.write(buf)
            f.flush()
            disk._mock.set(totalSize=f.tell(), image=image)
            return disk
        img = self.GeneratorClass(self.slaveCfg, self.data)
        img.swapSize = 4 * 1024 * 1024
        img.makeHDImage = mockMakeHDImage

        origLogCall = vmware_image.logCall
        self.logCallArgs = logCallArgs = []
        def mockLogCall(cmd, **kw):
            logCallArgs.append((cmd, kw))
            if cmd[0] != '/usr/bin/raw2vmdk':
                return origLogCall(cmd, **kwargs)
            hdImage = cmd[-2]
            outfile = cmd[-1]
            assert os.path.exists(hdImage)
            with open(outfile, 'w') as f:
                f.seek(1000000)
                f.truncate()
        self.mock(vmware_image, 'logCall', mockLogCall)
        mock.mockMethod(img.downloadChangesets)
        mock.mockMethod(img.postOutput)
        self.img = img
        return img
开发者ID:pombredanne,项目名称:jobslave,代码行数:34,代码来源:vmwaretest.py

示例4: testCancel

    def testCancel(self):
        from rbuild_plugins import images

        mock.mockMethod(self.handle.DescriptorConfig.createDescriptorData)
        mock.mock(images, 'xobj')

        _doc = mock.MockObject()
        _doc._mock.enable('job')
        images.xobj.Document._mock.setReturn(_doc)

        _job = mock.MockObject()
        _job._mock.enable('job_type', 'descriptor')
        images.xobj.XObj._mock.setReturn(_job)

        _image_action = mock.MockObject()
        _image_action._mock.set(key=images.Images.CANCEL)
        _image_action._root._mock.set(job_type='job_type',
            descriptor='descriptor')

        _image = mock.MockObject()
        _image._mock.set(key=images.Images.CANCEL, image_id='10', status='100',
            actions=[_image_action])
        _image.jobs.append._mock.setReturn(_doc, _doc)

        rv = self.handle.Images.cancel(_image)
        self.assertEqual(rv, _doc)
        self.assertEqual(rv.job, _job)
        self.assertEqual('job_type', rv.job.job_type)
        self.assertEqual('descriptor', rv.job.descriptor)
开发者ID:sassoftware,项目名称:rbuild,代码行数:29,代码来源:imagestest.py

示例5: testShowJobStatus

 def testShowJobStatus(self):
     handle = self.getRbuildHandle(mock.MockObject())
     handle.Show.registerCommands()
     handle.productStore.getPackageJobId._mock.setReturn(10)
     mock.mockMethod(handle.facade.rmake.displayJob)
     handle.Show.showJobStatus(10)
     handle.facade.rmake.displayJob._mock.assertCalled(10)
开发者ID:fedora-conary,项目名称:rbuild,代码行数:7,代码来源:showtest.py

示例6: testWatchJob

 def testWatchJob(self):
     handle = self.getRbuildHandle()
     mock.mockMethod(handle.facade.rmake.watchJob)
     handle.facade.rmake.watchJob._mock.setReturn(2, 1)
     ret = handle.Build.watchJob(1)
     handle.facade.rmake.watchJob._mock.assertCalled(1)
     self.assertEquals(ret, 2)
开发者ID:sassoftware,项目名称:rbuild,代码行数:7,代码来源:buildtest.py

示例7: testCreateBranchCmdline

 def testCreateBranchCmdline(self):
     handle = self.getRbuildHandle(mock.MockObject())
     handle.Create.registerCommands()
     handle.CreateProjectBranch.initialize()
     mock.mockMethod(handle.facade.rbuilder.listPlatforms)
     mock.mockMethod(handle.facade.rbuilder.createBranch)
     mock.mock(handle, 'ui')
     Platform = namedtuple('Platform', 'platformName label id')
     handle.facade.rbuilder.listPlatforms._mock.setReturn([
         Platform('the platform', '[email protected]', 'http://the/platform'),
         Platform('not platform', '[email protected]', 'http://not/platform'),
         ])
     cmd = handle.Commands.getCommandClass('create')()
     cmd.runCommand(handle, {
         'project': 'proj',
         'branch': 'branch',
         'platform': 'the platform',
         }, ['rbuild', 'create', 'branch'])
     handle.facade.rbuilder.createBranch._mock.assertCalled(
             project='proj',
             name='branch',
             platformLabel='[email protected]',
             namespace=None,
             description='',
             )
     err = self.assertRaises(errors.PluginError,
             cmd.runCommand, handle, {
             'project': 'proj',
             'branch': 'branch',
             'platform': 'missing platform',
             }, ['rbuild', 'create', 'branch'])
     self.assertEquals(str(err),
             "No platform matching term 'missing platform' was found")
开发者ID:sassoftware,项目名称:rbuild,代码行数:33,代码来源:createprojectbranchtest.py

示例8: setUp

    def setUp(self):
        testcase.TestCaseWithWorkDir.setUp(self)
        # Delete all root handlers
        for handler in logging.root.handlers:
            logging.root.removeHandler(handler)
        logging.basicConfig(level=logging.DEBUG)
        self.logHandler = logging.root.handlers[0]
        mock.mockMethod(self.logHandler.handle)
        self.cfg = config.UpsrvConfig()
        self.cfg.downloadDB = "sqlite:///%s/%s" % (self.workDir, "upsrv.sqlite")
        salt = file("/dev/urandom").read(8).encode('hex')
        self.cfg.configLine('password %s %s' % (
            self.Username, crypt.crypt(self.Password, '$1$%s$' % salt)))

        self.wcfg = app.configure(self.cfg)

        maker = self.wcfg.registry.settings['db.sessionmaker']
        # New maker, without extensions, we don't need transaction
        # management
        makerArgs = maker.kw.copy()
        del makerArgs['extension']
        maker = maker.__class__(**makerArgs)
        conn = maker()
        db.schema.updateSchema(conn)
        conn.commit()

        self.conn = conn

        self.app = self.wcfg.make_wsgi_app()

        # Mock the conary config object
        self.conaryCfg = conarycfg.ConaryConfiguration(False)
        self.conaryCfg.root = "%s/%s" % (self.workDir, "__root__")
        mock.mock(conarycfg, 'ConaryConfiguration', self.conaryCfg)
开发者ID:pombredanne,项目名称:rbm,代码行数:34,代码来源:record_test.py

示例9: prepReposState

 def prepReposState(self, facade):
     mock.mockMethod(facade._getRepositoryStateFromDirectory)
     repos = mock.MockObject()
     sourceState = mock.MockObject()
     facade._getRepositoryStateFromDirectory._mock.setDefaultReturn(
         [repos, sourceState])
     return (repos, sourceState)
开发者ID:fedora-conary,项目名称:rbuild,代码行数:7,代码来源:conaryfacadetest.py

示例10: testDelete

    def testDelete(self):
        handle = self.handle
        mock.mockMethod(handle.facade.rbuilder.getImageDefs)
        mock.mock(handle, 'product')
        mock.mock(handle, 'productStore')
        mock.mock(handle.ui, 'getYn')
        handle.product.getProductShortname._mock.setReturn('project')
        handle.product.getProductVersion._mock.setReturn('branch')

        class MockBuildDefinition(object):
            """ substitutes for both the robj and the product build definitions """
            def __init__(self, name):
                self.name = name
            def export(self, f, level=0, namespace_=''):
                """ this will create 'IDs' that are md5sums of the name """
                f.write(self.name)
        buildDefinitions = [ MockBuildDefinition('one'), MockBuildDefinition('two'), ]
        handle.product._mock.set(buildDefinition=buildDefinitions)
        handle.facade.rbuilder.getImageDefs._mock.setReturn(
                [ buildDefinitions[0] ],
                id='f97c5d29941bfb1b2fdab0874906ab82', product='project', version='branch')
        handle.ui.getYn._mock.setReturn(True, "Delete one?", default=False)
        handle.productStore.getProductDefinitionXmlPath._mock.setReturn(
                '%s/productstore.xml' % self.workDir)

        handle.ImageDefs.delete('f97c5d29941bfb1b2fdab0874906ab82')

        self.assertEquals(len(buildDefinitions), 1)
        self.assertEquals(buildDefinitions[0].name, 'two')
        handle.productStore.commit._mock.assertCalled(message="Remove image def one")
        handle.productStore.update._mock.assertCalled()
开发者ID:sassoftware,项目名称:rbuild,代码行数:31,代码来源:imagedefstest.py

示例11: testDeleteNoImageDefs

    def testDeleteNoImageDefs(self):
        from rbuild_plugins import imagedefs

        handle = self.handle
        mock.mockMethod(handle.facade.rbuilder.getImageDefs)
        mock.mock(handle, 'product')
        mock.mock(handle, 'productStore')
        mock.mock(handle.ui, 'getYn')
        handle.product.getProductShortname._mock.setReturn('project')
        handle.product.getProductVersion._mock.setReturn('branch')

        buildDefinitions = [ ]
        handle.product._mock.set(buildDefinition=buildDefinitions)
        handle.facade.rbuilder.getImageDefs._mock.setReturn(
                [ ],
                id='f97c5d29941bfb1b2fdab0874906ab82', product='project', version='branch')

        err = self.assertRaises(Exception,
                handle.ImageDefs.delete, 'f97c5d29941bfb1b2fdab0874906ab82')
        self.assertEquals(len(buildDefinitions), 0)
        handle.productStore.update._mock.assertNotCalled()
        handle.ui.getYn._mock.assertNotCalled()
        self.assertEquals(str(err), "Unable to find imagedef with id "
                "'f97c5d29941bfb1b2fdab0874906ab82' on branch version of "
                "project project")
开发者ID:sassoftware,项目名称:rbuild,代码行数:25,代码来源:imagedefstest.py

示例12: testListNoProduct

    def testListNoProduct(self):
        handle = self.handle
        mock.mockMethod(handle.facade.rbuilder.getImages)

        err = self.assertRaises(errors.MissingProductStoreError,
            handle.ImageDefs.list)
        self.assertIn('rbuild init', str(err))
开发者ID:sassoftware,项目名称:rbuild,代码行数:7,代码来源:imagedefstest.py

示例13: testGetChoice

 def testGetChoice(self):
     h = self.getRbuildHandle()
     choices = ["a", "b", "c"]
     mock.mockMethod(h.ui.input)
     h.ui.input._mock.setReturns(["", "x", "0", "4", "3"], "prompt [1-3]: ")
     rc, txt = self.captureOutput(h.ui.getChoice, "prompt", choices)
     self.assertEqual(rc, 2)
开发者ID:pombredanne,项目名称:rbuild,代码行数:7,代码来源:uitest.py

示例14: testModifiedFileNames

 def testModifiedFileNames(self):
     handle = self.getRbuildHandle()
     cf = handle.facade.conary
     mock.mockMethod(cf.getCheckoutStatus)
     cf.getCheckoutStatus._mock.setReturn((('A', '/p/1'), ('M', '/p/2')),
                                          '/p')
     self.assertEquals(handle.Rebase._modifiedFileNames('/p'), ['/p/2'])
开发者ID:fedora-conary,项目名称:rbuild,代码行数:7,代码来源:rebasetest.py

示例15: testBuildJob

 def testBuildJob(self):
     _, facade = self.prep()
     mock.mockMethod(facade._getRmakeHelper)
     client = mock.MockObject()
     facade._getRmakeHelper._mock.setDefaultReturn(client)
     facade.buildJob(1)
     client.buildJob._mock.assertCalled(1)
开发者ID:fedora-conary,项目名称:rbuild,代码行数:7,代码来源:rmakefacadetest.py


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