2010-01-20 5 views
0

여러 응답을 테스트 할 때 함수를 여러 번 호출합니다. 나는이 함수의 변수를 변경하고 호출하는 방식으로 함수에서 더 일찍 함수를 호출하는 방법에 대해 묻는다. 다음은 코드 스 니펫입니다.함수를 호출하고 변수를 변경하는 방법

class AbsoluteMove(unittest.TestCase): 

    def Ssh(self): 

     p=pexpect.spawn('ssh [email protected]') 
     self.command = './ptzpanposition -c 0 -u degx10' 
     p.sendline("cd /bin") 
     i=p.expect('[email protected]:') 
     p.sendline(self.command) 
     i=p.expect('[email protected]:') 
     self.Value = p.before 

class VerifyTilt(AbsoluteMove): 

    def runTest(self): 

     self.dest.PanTilt._y=2.0 

     try: 
      result = self.client.service.AbsoluteMove(self.token, self.dest, self.speed) 
     except suds.WebFault as detail: 
      print detail 

     self.command = './ptzpanposition -c 0 -u degx10' 
     AbsoluteMove.Ssh(self) 

     # Position of the camera verified through Ssh (No decimal point added to the Ssh value) 
     self.assertEqual(self.Value, '20') 

나는 AbsoluteMove.Ssh()의 'self.command'변수를 변경 한 후이 기능을 실행합니다. 누구든지이 작업을 수행하는 방법을 알고 있습니까? 어떤 도움

당신은 runTest 기능에 대한 래퍼를해야합니다

답변

0

,

은 내가 쉿() 함수에서 변수를 선언했다. 이 코드를 제거하고 변수가 나중에 코드에서 변경되었습니다. 이 코드는이 덕분에 작동합니다.

+0

"여기 어떻게 질문하나요?" 이 페이지 : http://stackoverflow.com/faq – Jorenko

0

에 대한

감사합니다. 내가

class VerifyTilt(AbsoluteMove): 
def testWrapper(self): 
    self.command = './ptzpanposition -c 0 -u degx10' 
    runTest() 
    self.command = 'some other command' 
    runTest() 

def runTest(self): 

    self.dest.PanTilt._y=2 

    try: 
     result = self.client.service.AbsoluteMove(self.token, self.dest, self.speed) 
    except suds.WebFault as detail: 
     print detail 

    # self.command = './ptzpanposition -c 0 -u degx10' 
    AbsoluteMove.Ssh(self) 

    # Position of the camera verified through Ssh (No decimal point added to the Ssh value) 
    self.assertEqual(self.Value, '200') 
1

는 절대 또 다른 매개 변수를 이동 추가 할 수 행할 수 runTestself.command='./ptzpanposition -c 0 -u degx10' 댓글을 달았 것을 알?

0

self.command는 단지 문자열이고 AbsoluteMove.Ssh()는 인자를 취하지 않기 때문에 어떻게 든 문자열을 사용해야하므로 self.command의 값을 변경할 수 있습니다. 더 나은 디자인은 두 개의 명령을 가지며 AbsoluteMove.Ssh()에 대한 인수로 이들 사이를 선택합니다. 시간 낭비 죄송

관련 문제