PyTest -Methode VerspottungPython

Python-Programme
Anonymous
 PyTest -Methode Verspottung

Post by Anonymous »

Code: Select all

def create_interface(iface, address, netmask):
validate_interface(iface, address, netmask)
if ping_test(address):
raise Exception("Address %s is already in use. interface %s with ip %s." % (address, iface, address))
proc = Popen(["sudo ifconfig %s %s netmask %s up" %
(iface, address, netmask)], shell=True, stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
ret = proc.returncode
if ret:
raise Exception("Failed to create virtual interface '%s': %s" %
(iface, out + err))
else:
logging.info("Created %s with ip %s and netmask %s successfully" %
(iface, address, netmask))
< /code>
Dies ist die Methode, für die ich einen Testfall schreiben muss. < /p>
Mein Testfall lautet wie folgt: < /p>
def test_create_interface(self):
iface = "eth0:1"
address = "1.2.3.4"
netmask = "255.255.255.0"
import subprocess
process = self.mox.CreateMock(subprocess.Popen)
process.returncode = 1
self.mox.StubOutWithMock(vi, "validate_interface")
vi.validate_interface(iface, address, netmask).AndReturn(None)
self.mox.StubOutWithMock(vi, "ping_test")
vi.ping_test(address).AndReturn(False)
self.mox.StubOutWithMock(subprocess, "Popen")
subprocess.Popen(  IgnoreArg(), stdout=subprocess.PIPE,
stderr=subprocess.PIPE).AndReturn(process)
self.mox.StubOutWithMock(process, "communicate")
process.communicate().AndReturn(("", 0))
self.mox.ReplayAll()
vi.create_interface(iface, address, netmask)
self.mox.VerifyAll()
, aber es schlägt mit:
Unerwartete Methode auf. Aufruf Funktion .__ Call __ ('Eth0: 1', '1.2. 3.4 ',' 255.255.255.0 ') -> Keine.
Was bin ich?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post