From 34df86b37d6838b115e65e5f3a332344afeb86b8 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Wed, 1 Jul 2020 10:45:34 +0200 Subject: Changes to adapt to new way to save results in DB. Created audio test. Added protections against unexpected status in DB. --- test-cli/test/tests/qamper.py | 61 ++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 42 deletions(-) (limited to 'test-cli/test/tests/qamper.py') diff --git a/test-cli/test/tests/qamper.py b/test-cli/test/tests/qamper.py index 7a31615..b4d57e3 100644 --- a/test-cli/test/tests/qamper.py +++ b/test-cli/test/tests/qamper.py @@ -26,60 +26,37 @@ class Qamper(unittest.TestCase): amp = Amper() # open serial connection if not amp.open(): - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: can not open a serial port", - "type": "string" - } - ) self.fail("Error: can not open a serial port") # check if the amperimeter is connected and working # 2 ATTEMTS if not amp.hello(): if not amp.hello(): - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: can not communicate with the amperimeter", - "type": "string" - } - ) self.fail("Error: can not communicate") # get current value (in Amperes) - current = amp.getCurrent() + self.current = amp.getCurrent() + # save result in a file + with open('/tmp/station/amper.txt', 'w') as outfile: + n = outfile.write("Current: {} A".format(self.current)) + outfile.close() + self.__resultlist.append( + { + "description": "Amperimeter values", + "filepath": "/tmp/station/amper.txt", + "mimetype": "text/plain" + } + ) # close serial connection amp.close() # Check current range - if float(current) > float(self._overcurrent): + if float(self.current) > float(self._overcurrent): # Overcurrent detected - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: Overcurrent detected ( {} A)".format(current), - "type": "string" - } - ) - self.fail("failed: Overcurrent detected ( {} )".format(current)) - elif float(current) < float(self._undercurrent): + self.fail("failed: Overcurrent detected ( {} )".format(self.current)) + elif float(self.current) < float(self._undercurrent): # Undercurrent detected - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: Undercurrent detected ( {} A)".format(current), - "type": "string" - } - ) - self.fail("failed: Undercurrent detected ( {} )".format(current)) - - # Test successful - self.__resultlist.append( - { - "desc": "Test result", - "data": "OK: Current {} A".format(current), - "type": "string" - } - ) + self.fail("failed: Undercurrent detected ( {} )".format(self.current)) def getresults(self): return self.__resultlist + + def gettextresult(self): + return "{} A".format(self.current) -- cgit v1.1