Hi <div><br></div><div>I need to write the unit test cases for similary kind of sitution. </div><div><br></div><div>I need to write the unit test case for Foo.testCall. for both case true or false. I am unalbe to do that. </div>
<div><br></div><div>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</div><div><br></div><div>******************  Enter.py ********************</div>
<div><font color="#666666">from run import RunComp</font></div><div><font color="#666666"><br></font></div><div><font color="#666666">def  enter():</font></div><div><font color="#666666">   runC = RunComp("ComName", "~/pathToHome")</font></div>
<div><font color="#666666">   """ This is based on some database condition we are passing name true or false  """</font></div><div><font color="#666666">    foo = Foo(true)</font></div><div><font color="#666666">    foo.testCall(runC)</font></div>
<div><font color="#666666"><br></font></div><div><font color="#666666">if __name__ == "__main__":</font></div><div><font color="#666666">   enter()</font></div><div><br></div><div>**************************************************</div>
<div><br></div><div>***************** foo.py************************</div><div><font color="#666666">Class Foo():</font></div><div><font color="#666666"><br></font></div><div><font color="#666666">    </font><span style="color:rgb(102,102,102);font-size:12px"> </span><span style="color:rgb(102,102,102);font-size:12px">def __init__(self, found):</span></div>
<pre style="margin-top:0px;margin-bottom:0px;padding:0px;color:rgb(102,102,102);font-size:12px"><pre style="margin-top:0px;margin-bottom:0px;padding:0px"><span style="font-family:arial">             </span><span style="font-family:arial;font-size:small;white-space:normal">self.found</span><span style="font-family:arial"> = found</span></pre>
<pre style="margin-top:0px;margin-bottom:0px;padding:0px"><span style="font-family:arial"><br></span></pre></pre><div><div><font color="#666666">    def testCall(self, SomeClassObject):</font></div><div><font color="#666666">           if self.found:</font></div>
<div><font color="#666666">              <span style="font-size:12px">RunComp</span>Object.<span style="font-size:12px">call_run</span>("codeRun -s " + self.found)</font></div><div><font color="#666666">           else:</font></div>
<div><font color="#666666">              <span style="font-size:12px">RunComp</span>Object.<span style="font-size:12px">call_run</span>("codeRun")</font></div></div><div>*************************************************</div>
<div><br></div><div>************** run.py **************************</div><div><pre style="margin-top:0px;margin-bottom:0px;padding:0px;color:rgb(102,102,102);font-size:12px">from subprocess import call</pre><pre style="margin-top:0px;margin-bottom:0px;padding:0px;color:rgb(102,102,102);font-size:12px">
<br></pre><pre style="margin-top:0px;margin-bottom:0px;padding:0px;color:rgb(102,102,102);font-size:12px"><pre style="margin-top:0px;margin-bottom:0px;padding:0px">class RunComp(object):</pre><pre style="margin-top:0px;margin-bottom:0px;padding:0px">
    <span style="font-family:arial">def __init__(self, com, home):</span></pre><pre style="margin-top:0px;margin-bottom:0px;padding:0px"><span style="font-family:arial">             self.comp = comp</span></pre><pre style="margin-top:0px;margin-bottom:0px;padding:0px">
<span style="font-family:arial">             self.home = home</span></pre><pre style="margin-top:0px;margin-bottom:0px;padding:0px">   </pre><pre style="margin-top:0px;margin-bottom:0px;padding:0px">    def call_and_raise(*args, **kwargs):</pre>
<pre style="margin-top:0px;margin-bottom:0px;padding:0px">        <span style="font-family:arial">if call(*args, **kwargs):</span></pre><pre style="margin-top:0px;margin-bottom:0px;padding:0px"><span style="font-family:arial">                      </span><span style="font-family:arial">raise RuntimeError("LDF command failed!")</span></pre>
<pre style="margin-top:0px;margin-bottom:0px;padding:0px">   </pre><pre style="margin-top:0px;margin-bottom:0px;padding:0px"><span style="font-family:arial">        def call_run(self, command):</span></pre><pre style="margin-top:0px;margin-bottom:0px;padding:0px">
<span style="font-family:arial">            if self.comp:</span></pre><pre style="margin-top:0px;margin-bottom:0px;padding:0px"><span style="font-family:arial">                </span><span style="font-family:arial">command = " ".join((command,myldfrc))</span></pre>
<pre style="margin-top:0px;margin-bottom:0px;padding:0px"><span style="font-family:arial">           call(command, </span><span style="font-family:arial">cwd=self.home</span><span style="font-family:arial">)</span></pre></pre>
</div><div><br></div><div><br></div><div>*************************************************</div><div><br></div><div><br></div><div>Thanks & Regards</div><div>Jitu</div><div><br></div>