Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25257

Mocked object returning another Mocked object

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=5343cf7c3=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.016
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'attribute': 0.05; 'api': 0.09; 'attribute.': 0.09; 'url:voidspace': 0.09; '(the': 0.15; 'hardware.': 0.16; 'subject:object': 0.16; 'to:name:python list': 0.16; 'fix': 0.17; 'basically': 0.17; 'tests.': 0.17; 'app': 0.19; 'holds': 0.20; 'trying': 0.21; 'controlled': 0.22; 'defined': 0.22; "i'd": 0.22; 'cheers,': 0.23; 'idea': 0.24; 'header:User- Agent:1': 0.26; 'setting': 0.26; 'question': 0.27; 'end,': 0.29; 'piece': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'figure': 0.30; 'url:python': 0.32; 'print': 0.32; 'controlling': 0.33; 'to:addr :python-list': 0.33; '(with': 0.33; 'list': 0.35; 'software,': 0.35; 'next': 0.35; 'but': 0.36; 'url:org': 0.36; 'method': 0.36; 'itself': 0.37; 'option': 0.37; 'level': 0.37; 'object': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'help': 0.40; 'your': 0.60; 'group,': 0.60; 'received:194': 0.61; 'url:index': 0.61; 'bring': 0.62; 'greetings': 0.69; 'mock': 0.84; 'unitary': 0.84
X-IronPort-AV E=Sophos;i="4.77,579,1336341600"; d="scan'208";a="576326"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Fri, 13 Jul 2012 12:09:22 +0200
From Jean-Michel Pichavant <jeanmichel@sequans.com>
User-Agent Mozilla-Thunderbird 2.0.0.24 (X11/20100328)
MIME-Version 1.0
To Python List <python-list@python.org>
Subject Mocked object returning another Mocked object
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2074.1342174174.4697.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1342174174 news.xs4all.nl 6849 [2001:888:2000:d::a6]:51360
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25257

Show key headers only | View raw


Greetings Fellow Group,


I'd need your help to fix some issues I have with my unitary tests.
I'm trying to bring them to the next level by Mocking equipments 
controlled by my application.

Despite me reading http://www.voidspace.org.uk/python/mock/index.html I 
cannot figure out how to do the following :

I have an App object with the 'target' attribute. This target is 
controlling a piece of hardware. The hardware itself holds a software, 
hence the target object having an 'api' attribute. I hope I make sense.

So basically I'd like

self.target.api.<anyMethod>()

to return a Mocked object (Mocking an Api object response).



** Question **

I do I make *all* method calls return a specifik Mock?

target = Mock()

result = target.api.start() # I'd like result to be a Mock I defined 
with the 'returnCode' attribute

print result.returnCode
1

But I would like to do it for any method of api (the list is huge, 
setting each of them is not an option I think) so that in the end,

result = target.api.start()
result = target.api.stop()
result = target.api.reset()
result = target.api.loadSw()

return all the same Mock object (with 'returnCode')


Any idea ?

Cheers,

JM

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Mocked object returning another Mocked object Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-07-13 12:09 +0200
  Re: Mocked object returning another Mocked object Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-07-13 12:37 +0200

csiph-web