Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; '"""': 0.05; 'case.': 0.05; '"__main__":': 0.07; '__name__': 0.07; 'false.': 0.07; 'subject:test': 0.07; '"': 0.09; '**kwargs):': 0.09; '8bit%:2': 0.09; 'subject:using': 0.09; 'def': 0.10; 'cases': 0.15; 'passing': 0.15; 'skip:f 30': 0.15; 'comp': 0.16; 'failed!")': 0.16; 'foo():': 0.16; 'subject:Object': 0.16; 'subject:unittest': 0.16; 'subprocess': 0.16; 'skip:\xa0 30': 0.17; 'import': 0.21; 'skip:* 50': 0.22; '\xa0if': 0.22; 'raise': 0.24; 'command': 0.24; 'skip:" 20': 0.26; 'message- id:@mail.gmail.com': 0.27; 'subject:/': 0.28; 'run': 0.28; '8bit%:5': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'this.': 0.29; 'that.': 0.30; 'skip:& 30': 0.30; 'function': 0.30; 'to:addr :python-list': 0.33; 'skip:& 20': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'false': 0.35; 'returning': 0.35; 'skip:* 20': 0.35; 'but': 0.36; 'test': 0.36; 'unit': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'google': 0.39; 'skip:" 10': 0.40; 'help': 0.40; '&': 0.61; 'kind': 0.61; 'home': 0.66; 'kindly': 0.67; '8bit%:10': 0.69; 'hi\xa0': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=ItV0JwlsZppJdwm6HqdPV2xS0AlatMf5eiKQFmFyWng=; b=BBoKNb22kcH+w3mU05o+joUniBMpF8Q61vvQrrCL2eHNMkHYN3/rDJlove/jYZOYCa 7mIsQHA5tPO3mQ4MnIgrVlQEfs7j1Y7/X2R2T5qssBB3K4xMqCbaY8aT1ilp30bUH9eM v214TjU/J8Yv0JetThOVjYSrZMTKBTo3Jq1jDZrPNgHQoC0u7Wr10fdOo1R5oBktdnQp ZERdvIXDqoXsnJm2+o2bpOYUl1Qfi+CfX7Jf1vX1+rui0oVXiD+EzUARIbKOQql03+yp w2kHQo5Z7ebCi60UCBwicR4FqW4Xjfz3XTkaa744dGKpka/BFmOblmXzjislYPVyQ/W1 Q+mg== MIME-Version: 1.0 X-Received: by 10.180.100.10 with SMTP id eu10mr13464245wib.4.1362746200486; Fri, 08 Mar 2013 04:36:40 -0800 (PST) Date: Fri, 8 Mar 2013 18:06:40 +0530 Subject: Unit test cases for Object intraction using mox/unittest From: jitendra gupta To: python-list@python.org Content-Type: multipart/alternative; boundary=f46d044280c8333f4204d769131f X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 167 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362746207 news.xs4all.nl 6850 [2001:888:2000:d::a6]:33078 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40858 --f46d044280c8333f4204d769131f Content-Type: text/plain; charset=ISO-8859-1 Hi I need to write the unit test cases for similary kind of sitution. I need to write the unit test case for Foo.testCall. for both case true or false. I am unalbe to do that. kindly please help me on this. as function is not returning any thing. from google i got mox is good for this case. but i did not found any solution for this case ****************** Enter.py ******************** from run import RunComp def enter(): runC = RunComp("ComName", "~/pathToHome") """ This is based on some database condition we are passing name true or false """ foo = Foo(true) foo.testCall(runC) if __name__ == "__main__": enter() ************************************************** ***************** foo.py************************ Class Foo(): def __init__(self, found): self.found = found def testCall(self, SomeClassObject): if self.found: RunCompObject.call_run("codeRun -s " + self.found) else: RunCompObject.call_run("codeRun") ************************************************* ************** run.py ************************** from subprocess import call class RunComp(object): def __init__(self, com, home): self.comp = comp self.home = home def call_and_raise(*args, **kwargs): if call(*args, **kwargs): raise RuntimeError("LDF command failed!") def call_run(self, command): if self.comp: command = " ".join((command,myldfrc)) call(command, cwd=self.home) ************************************************* Thanks & Regards Jitu --f46d044280c8333f4204d769131f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi=A0

I need to write the unit test cases for similary k= ind of sitution.=A0

I need to write the unit test = case for Foo.testCall. for both case true or false. I am unalbe to do that.= =A0

kindly please help me on this. as function is not retur= ning any thing. from google i got mox is good for this case. but i did not = found any solution for this case

*****************= * =A0Enter.py ********************
from run import RunComp

def =A0ent= er():
=A0 =A0runC =3D RunComp(&quo= t;ComName", "~/pathToHome")
=A0 =A0""" This is based on som= e database condition we are passing name true or false =A0"""= ;
=A0 =A0 foo =3D Foo(true)=
=A0 =A0 foo.testCall(runC)

= if __name__ =3D=3D "__main__":
=A0 =A0enter()

*********************= *****************************

***************** foo.py************************
<= div>Class Foo():

=A0 =A0=A0 def __init__(self, found):
             self.found=
 =3D found

=A0 =A0 def testCall(self, SomeClassObject):
=A0 =A0 =A0 =A0 =A0 =A0if self.found:
=A0 =A0 =A0 =A0 =A0 =A0 =A0=A0RunCompObject.call_run= ("codeRun -s " + self.found)
=A0 =A0 =A0 =A0 =A0 =A0else:
=A0 =A0 =A0 =A0 =A0 =A0 =A0=A0RunCompObject.call_run= ("codeRun")
***********************= **************************

************** run.py **************************
<= div>
from subprocess import call

class RunComp(object):
    def __init__(self, com, home):=
             self.comp =3D comp
             self.home =3D home
  =A0
<= pre style=3D"margin-top:0px;margin-bottom:0px;padding:0px"> def call_and= _raise(*args, **kwargs):
        if call(*args, **kwargs):
                      rai=
se RuntimeError("LDF command failed!")
   
        def call_run(self, command):
            if self.comp:
co= mmand =3D " ".join((command,myldfrc))
           call(command,=A0cwd=3Dself.home)


**********************************= ***************


Thanks & Regard= s
Jitu

--f46d044280c8333f4204d769131f--