import unittest from test.helpers.amper import Amper class Qamper(unittest.TestCase): params = None __current = 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) self.__current = amp.getCurrent() # close serial connection amp.close() # Check current range if float(self.__current) > float(self._overcurrent): self.fail("failed: Overcurrent detected ( {} )".format(self.__current)) if float(self.__current) < float(self._undercurrent): self.fail("failed: Undercurrent detected ( {} )".format(self.__current)) def getresults(self): # resultlist is a python list of python dictionaries resultlist = [ { "desc": "current (Ampers)", "data": self.__current, "type": "string" } ] return resultlist