I am using a java jar in Pycharm environment to achieve testing in a pythion environment.
To make the application more interactive, we plan to use commandline arguments.
Eg:
The code used is as follows.
So I have modified the code this way considering overloading.
UPDATE: just understood that funciton overloading is not possible in python. How to achieve this scenario working? any suggestions please
To make the application more interactive, we plan to use commandline arguments.
Eg:
python test.py opc.tcp://localhost:XXXX AASo here, I am testing a AA configuration server at the mentioned URL. Now with this input, all the tests are performed.
The code used is as follows.
class TestClient: def __init__(self, URL, Config): self.Url = URL self.config = Config def perform_test(self): # subprocess.call(['java','-version']) subprocess.call( ['java', '-jar', 'XXX.jar', '-url', self.Url, '-config', self.config, '-specVersion', '2.0']) def read_results(self): pass if __name__ == "__main__": client = TestClient("opc.tcp://localhost:XXXX", "AA") client.perform_test() client.read_results()But to enhance further I want the user to type the version number and also the test he wants to do. As in (TEST A) as a parameter. But I also need to give a provision that if he does not provide this paramter, he should be able to perform all tests like previously.
So I have modified the code this way considering overloading.
import re import sys import bs4 as bs4 inputURL = sys.argv[1] inputConfig = sys.argv[2] version = sys.argv[3] print(len(sys.argv)) if len(sys.argv) > 4: typeOfTest = sys.argv[4] class TestClient: def __init__(self, URL, Config, Version): self.Url = URL self.config = Config self.version = Version def __init__(self, URL, Config, Version, TestType): self.testType = TestType #here i expect overloading of constructor def perform_test(self): # subprocess.call(['java','-version']) if len(sys.argv) > 4: subprocess.call( ['java', '-jar', 'XXX.jar', '-url', self.Url, '-config', self.config, '-specVersion', self.version]) else: subprocess.call( ['java', '-jar', 'XXX.jar', '-url', self.Url, '-config', self.config, '-specVersion', self.version, '-test', self.testType]) def read_results(self): pass if __name__ == "__main__": if len(sys.argv) > 4: client = TestClient(inputURL, inputConfig, version) else: client = TestClient(inputURL, inputConfig, version, typeOfTest) client.perform_test() client.read_results()So, I type on the command line :
python test.py opc.tcp://localhost:XXXX AA 2.0 TESTABut i get an error saying:
Error:client = TestClient(inputURL, inputConfig, version)
TypeError: __init__() missing 1 required positional argument: 'TestType'
Is the constructor overloading not poossible here? Please can anyone guide me some alternative?UPDATE: just understood that funciton overloading is not possible in python. How to achieve this scenario working? any suggestions please