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() # open serial connection if not amp.open(): self.fail("failed: can not open serial port") return # check if the amperimeter is connected and working # 2 ATTEMTS if not amp.hello(): if not amp.hello(): self.fail("failed: can not communicate") return # get current value (in Amperes) result = amp.getCurrent() # close serial connection amp.close() # # In order to give a valid result it is importarnt to define an under current value if result > float(self._overcurrent): self.fail("failed: Overcurrent detected ( {} )".format(result)) if result < float(self._undercurrent): self.fail("failed: Undercurrent detected ( {} )".format(result))