import unittest from test.helpers.amper import Amper class Qamper(unittest.TestCase): params = None # varlist: undercurrent, overcurrent def __init__(self, testname, testfunc, varlist): self.params = varlist super(Qamper, self).__init__(testfunc) if "undercurrent" in varlist: self._undercurrent = varlist["undercurrent"] else: raise Exception('undercurrent param inside Qamp must be defined') if "overcurrent" in varlist: self._overcurrent = varlist["overcurrent"] else: raise Exception('overcurrent param inside Qamp must be defined') self._testMethodDoc = testname def execute(self): amp = Amper() print(amp) if not amp.open(): print("1") self.fail("failed: can not open serial port") return if not amp.hello(): print("2") self.fail("failed: can not communicate") return result = amp.getCurrent() print(result) amp.close() # # In order to give a valid result it is importarnt to define an under current value # if self._current > float(self._overcurrent): # self.fail("failed: OVERCURRENT DETECTED ( {} )".format(self._current)) # # if self._current < float(self._undercurrent): # self.fail("failed: UNDERCURRENT DETECTED ( {} )".format(self._current))