2014-09-10 3 views
1

내 코드를 테스트하기 위해 파이썬 mockito https://code.google.com/p/mockito-python/을 사용 해왔다. python mockito 인수 인수 자

지금까지 파이썬 mockito 만 2 매처 (matcher)를 제공하는 것 : 포함() 및() https://code.google.com/p/mockito-python/wiki/Matchers

나는 전체 인수를 캡처 할 수 있도록 내가 코드를 작성하는 방법을 궁금해하고있다.

그래서 예를 들어, 내 코드는 내가 검증에서 할 수있는 모든

verify(self.cursor_mock, times=1).execute(contains("DELETE")) 

나는대로 실행에 전달 된 전체 인수를 캡처 할 수 있다면 그것은 좋은 것입니다, 현재

deleteSqlStatement = "DELETE from %s WHERE lower(z_id)=lower('%s') and y_id=%s" \ 
         % (self.SOME_TABLE, zId, yId) 
cursor.execute(deleteSqlStatement) 

경우 끈.

제안 사항?

+0

당신이 그냥 모의 꽤 쉬울 것이다이 단지 파이썬 모의를 사용하여 고려가 – Thomasleveil

답변

1

나는 인수를 캡처하기 위해 자신의 [Matcher]을 구현할 수 있다고 생각합니다. 다음

class Captor(Matcher): 

    def matches(self, arg): 
    self.value = arg 
    return True 

    def getValue(self): 
    return self.value 

및 테스트에 사용

:

captor = Captor() 
verify(self.cursor_mock, times=1).execute(captor) 
self.assertEqual("expected query", captor.getValue())