开发者

How to call a function and change a variable

I am calling a function several times as I am testing several responses. I am asking on how I call a function earlier in the program, changing a variable in this function and then calling it. Below is a snippet of the code.

class AbsoluteMove(unittest.TestCase):

     def Ssh(self):

        p=pexpect开发者_开发知识库.spawn('ssh user@10.10.10.10')
        self.command = './ptzpanposition -c 0 -u degx10' 
        p.sendline("cd /bin")
        i=p.expect('user@user-NA:')
        p.sendline(self.command)
        i=p.expect('user@-userNA:')
        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')

I want to change the 'self.command' variable in AbsoluteMove.Ssh() and then run this function. Does anyone know how to do this?

Thanks for any help


is it doable to add another parameter to Absolute Move?


You'll need to have a wrapper for the runTest function. Notice that I commented the self.command='./ptzpanposition -c 0 -u degx10' in runTest

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')


What it looks like is that self.command is just a string, and since AbsoluteMove.Ssh() takes no arguments it must use that string somehow..., so you could just change the value of self.command. A better design would have two commands, and an argument to AbsoluteMove.Ssh() to choose between them.


Sorry for wasting time,

I had declared the variable in the Ssh() function. I removed this and the variables were changed later down the code. The code will work this way thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜