From a03055f657d2e970e45e7ea2a3e66857f821eabd Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Mon, 9 Mar 2020 09:03:28 +0100 Subject: Solved problems with consumption test. Fixed error when getting mac address. --- test-cli/test/tests/qamper.py | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test-cli/test/tests/qamper.py (limited to 'test-cli/test/tests/qamper.py') diff --git a/test-cli/test/tests/qamper.py b/test-cli/test/tests/qamper.py new file mode 100644 index 0000000..2b02302 --- /dev/null +++ b/test-cli/test/tests/qamper.py @@ -0,0 +1,51 @@ +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)) -- cgit v1.1 From c685367cbd6abf1c6ae442df759e39b25a907d3b Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Mon, 9 Mar 2020 12:39:50 +0100 Subject: Fixed several test procedures. --- test-cli/test/tests/qamper.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 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 2b02302..b3ab8b1 100644 --- a/test-cli/test/tests/qamper.py +++ b/test-cli/test/tests/qamper.py @@ -22,30 +22,21 @@ class Qamper(unittest.TestCase): def execute(self): amp = Amper() - print(amp) + # open serial connection if not amp.open(): - print("1") self.fail("failed: can not open serial port") return - + # check if the amperimeter is connected and working if not amp.hello(): - print("2") self.fail("failed: can not communicate") return - + # get current value (in Amperes) result = amp.getCurrent() - print(result) - + # 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)) - - - - - - # # 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)) + if result < float(self._undercurrent): + self.fail("failed: Undercurrent detected ( {} )".format(result)) -- cgit v1.1 From 9f613e33f27f772682ab7d7bd2261a9c4bd014c5 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Wed, 15 Apr 2020 17:59:38 +0200 Subject: Allow 2 attempts to communicate to amperimeter. --- test-cli/test/tests/qamper.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 b3ab8b1..c611fdb 100644 --- a/test-cli/test/tests/qamper.py +++ b/test-cli/test/tests/qamper.py @@ -27,9 +27,11 @@ class Qamper(unittest.TestCase): self.fail("failed: can not open serial port") return # check if the amperimeter is connected and working + # 2 ATTEMTS if not amp.hello(): - self.fail("failed: can not communicate") - return + if not amp.hello(): + self.fail("failed: can not communicate") + return # get current value (in Amperes) result = amp.getCurrent() # close serial connection -- cgit v1.1 From 09b3bb38fc7305c9b47c29bc90ebc9c636827307 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Wed, 17 Jun 2020 09:44:56 +0200 Subject: SOPA0000: Added support for saving results (strings or files) in the DB. It also saves a final DMESG file. --- test-cli/test/tests/qamper.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 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 c611fdb..51aa469 100644 --- a/test-cli/test/tests/qamper.py +++ b/test-cli/test/tests/qamper.py @@ -4,6 +4,7 @@ from test.helpers.amper import Amper class Qamper(unittest.TestCase): params = None + __current = None # varlist: undercurrent, overcurrent def __init__(self, testname, testfunc, varlist): @@ -33,12 +34,22 @@ class Qamper(unittest.TestCase): self.fail("failed: can not communicate") return # get current value (in Amperes) - result = amp.getCurrent() + self.__current = 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)) + # 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)) - if result < float(self._undercurrent): - self.fail("failed: Undercurrent detected ( {} )".format(result)) + def getresults(self): + # resultlist is a python list of python dictionaries + resultlist = [ + { + "desc": "current (Ampers)", + "data": self.__current, + "type": "string" + } + ] + return resultlist -- cgit v1.1 From db3b1e45c47a1ef23c1ad67114a09cbec0976681 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Thu, 25 Jun 2020 11:45:31 +0200 Subject: Solved bugs. Adapted to DB changes. --- test-cli/test/tests/qamper.py | 64 +++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 17 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 51aa469..7a31615 100644 --- a/test-cli/test/tests/qamper.py +++ b/test-cli/test/tests/qamper.py @@ -4,7 +4,7 @@ from test.helpers.amper import Amper class Qamper(unittest.TestCase): params = None - __current = None + __resultlist = None # resultlist is a python list of python dictionaries # varlist: undercurrent, overcurrent def __init__(self, testname, testfunc, varlist): @@ -20,36 +20,66 @@ class Qamper(unittest.TestCase): else: raise Exception('overcurrent param inside Qamp must be defined') self._testMethodDoc = testname + self.__resultlist = [] def execute(self): amp = Amper() # open serial connection if not amp.open(): - self.fail("failed: can not open serial port") - return + 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.fail("failed: can not communicate") - return + 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) - self.__current = amp.getCurrent() + 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)) + if float(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): + # Undercurrent detected + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: Undercurrent detected ( {} A)".format(current), + "type": "string" + } + ) + self.fail("failed: Undercurrent detected ( {} )".format(current)) - def getresults(self): - # resultlist is a python list of python dictionaries - resultlist = [ + # Test successful + self.__resultlist.append( { - "desc": "current (Ampers)", - "data": self.__current, + "desc": "Test result", + "data": "OK: Current {} A".format(current), "type": "string" } - ] - return resultlist + ) + + def getresults(self): + return self.__resultlist -- cgit v1.1 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 From 1d51a80b57cc8c80c78d67c85290503997060e9e Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Mon, 6 Jul 2020 17:22:17 +0200 Subject: Modified paths of ram and nfs temporary folders. --- test-cli/test/tests/qamper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 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 b4d57e3..58054c9 100644 --- a/test-cli/test/tests/qamper.py +++ b/test-cli/test/tests/qamper.py @@ -35,13 +35,13 @@ class Qamper(unittest.TestCase): # get current value (in Amperes) self.current = amp.getCurrent() # save result in a file - with open('/tmp/station/amper.txt', 'w') as outfile: + with open('/mnt/station_ramdisk/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", + "filepath": "/mnt/station_ramdisk/amper.txt", "mimetype": "text/plain" } ) -- cgit v1.1 From d46bce422fd03cd57d1ba336361da17d6efb48db Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Fri, 31 Jul 2020 02:07:37 +0200 Subject: TEST restructure --- test-cli/test/tests/qamper.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 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 58054c9..df340eb 100644 --- a/test-cli/test/tests/qamper.py +++ b/test-cli/test/tests/qamper.py @@ -5,6 +5,7 @@ from test.helpers.amper import Amper class Qamper(unittest.TestCase): params = None __resultlist = None # resultlist is a python list of python dictionaries + dummytest = False # varlist: undercurrent, overcurrent def __init__(self, testname, testfunc, varlist): @@ -21,8 +22,28 @@ class Qamper(unittest.TestCase): raise Exception('overcurrent param inside Qamp must be defined') self._testMethodDoc = testname self.__resultlist = [] + if "dummytest" in varlist: + self.dummytest = varlist["dummytest"] + + def saveresultinfile(self, currentvalue): + # save result in a file + with open('/mnt/station_ramdisk/amper.txt', 'w') as outfile: + n = outfile.write("Current: {} A".format(currentvalue)) + outfile.close() + self.__resultlist.append( + { + "description": "Amperimeter values", + "filepath": "/mnt/station_ramdisk/amper.txt", + "mimetype": "text/plain" + } + ) def execute(self): + if self.dummytest: + self.current = "0.0" + self.saveresultinfile(self.current) + return + amp = Amper() # open serial connection if not amp.open(): @@ -35,16 +56,7 @@ class Qamper(unittest.TestCase): # get current value (in Amperes) self.current = amp.getCurrent() # save result in a file - with open('/mnt/station_ramdisk/amper.txt', 'w') as outfile: - n = outfile.write("Current: {} A".format(self.current)) - outfile.close() - self.__resultlist.append( - { - "description": "Amperimeter values", - "filepath": "/mnt/station_ramdisk/amper.txt", - "mimetype": "text/plain" - } - ) + self.saveresultinfile(self.current) # close serial connection amp.close() # Check current range -- cgit v1.1 From 227d9783fe8327b84ac3b0e032f012ba144816f8 Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Fri, 31 Jul 2020 13:58:41 +0200 Subject: IGEP0048: added plc test --- test-cli/test/tests/qamper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 df340eb..96b673c 100644 --- a/test-cli/test/tests/qamper.py +++ b/test-cli/test/tests/qamper.py @@ -39,7 +39,7 @@ class Qamper(unittest.TestCase): ) def execute(self): - if self.dummytest: + if self.dummytest == '1': self.current = "0.0" self.saveresultinfile(self.current) return -- cgit v1.1