0

I have a small test program with lib_procs.py, main_test.py and test_engine.py. Right now main_test obj is instantiated in test_engine.py. The obj is used to invoke the execute method in main_test.py. In the execute method procs.run_cmd(msg,cmd) is called which sends the command and returns the message.

lib_procs.py

def run_cmd(msg, cmd):
    #send hardware command and return something
    #it has other hardware specific method too

main_test.py

import lib_procs as procs
class main_test(object):
    def __init__(self, xmlpath, name)
     #initialize

    def execute(self):
       #Currently
       #parse xml
       msg = xml.msg
       cmd = xml.cmd
       output = procs.run_cmd(cmd, msg)
       #Do other things too

TestEngine.py

   if __name__ == "__main__::
       test_obj = main_test(xmlpath, test_name)
       test_obj.execute()

What I want to do is be able to run the run_cmd but through XML file. The XML file should have the information on what function to invoke. This should be extracted in main_test.py. The purpose of this is to make the test framework generic which could be used by others by changing the information in XML. Right now procs.run_cmd is hardware specific. Is it possible to do?

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
ilaunchpad
  • 1,283
  • 3
  • 16
  • 32
  • Sure, it's possible. You could use `exec`, but it's probably better to write conditionals based on the appropriate field in your XML. Or, make a `dict` mapping function names to actual functions. The specifics really depend on implementation details.. – user812786 Oct 07 '15 at 17:10
  • @whrrgarbl I'm little unsure about how to declare python method and modules inside xml tags. Is there any example? – ilaunchpad Oct 07 '15 at 17:20
  • Well, it's really up to you - that's the "implementation details" part. Do you want to have actual python code in the XML file? Or just name the function to call? ([This question](http://stackoverflow.com/questions/3061/calling-a-function-of-a-module-from-a-string-with-the-functions-name-in-python) might be useful if you want to go that route.) – user812786 Oct 07 '15 at 17:35

0 Answers0