mercredi 21 décembre 2016

Mock a raw_input python

Ihave this functions wich should recibe a list [x,y]

def input_origem():
    origem = raw_input("Entre com o valor de x: ")
    origem = eval(origem)
    return origem
def input_saida():
    destino = raw_input("Entre com o valor de y  ")
    destino = eval(destino)
    return destino


def my func(origem, destino):

..
...
code 
..
...

print  myfunc(input_origem(), input_saida())

ok, code works well but idk how to mock this functions:

i try that way

class TEste(base.TestCase):
    @base.TestCase.mock.patch('mypath.input_origem')
    @base.TestCase.mock.patch('mypath.input_saida')
    def test_movimento_cavalo(self, origem_mock, saida_mock):
        origem_mock = self.mock.MagicMock()
        saida_mock = self.mock.MagickMock()
        myfunc(origem_mock, saida_mock)
        myfunc.should.be.equal([1,1])

But never complete the test, when i cancel

origem = raw_input("Entre com o valor de x: ") KeyboardInterrupt

Aucun commentaire:

Enregistrer un commentaire