From 09de774dcc1a5abc1c8f3a00fdb039aa3c522f52 Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Wed, 4 Mar 2020 17:46:36 +0100 Subject: SOPA Initial Commit --- test-cli/test/runners/simple.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'test-cli/test/runners') diff --git a/test-cli/test/runners/simple.py b/test-cli/test/runners/simple.py index 5b2da5a..3537d0e 100644 --- a/test-cli/test/runners/simple.py +++ b/test-cli/test/runners/simple.py @@ -22,9 +22,12 @@ class SimpleTestRunner: --------------------------------------------- """ - def __init__(self, stream=sys.stderr, verbosity=0): + __pgObj = None + + def __init__(self, pgObj, stream=sys.stderr, verbosity=0): self.stream = stream self.verbosity = verbosity + self.__pgObj = pgObj def writeUpdate(self, message): self.stream.write(message) @@ -33,7 +36,7 @@ class SimpleTestRunner: """ Run the given test case or Test Suite. """ - result = TextTestResult(self) + result = TextTestResult(self, self.__pgObj) test(result) result.testsRun # self.writeUpdate("---------------------------------------------\n") @@ -45,18 +48,22 @@ class TextTestResult(unittest.TestResult): FAIL = '\033[31mFAIL\033[0m\n' ERROR = '\033[31mERROR\033[0m\n' - def __init__(self, runner): + __pgObj = None + + def __init__(self, runner, pgObj): unittest.TestResult.__init__(self) self.runner = runner self.result = self.ERROR + self.__pgObj = pgObj def startTest(self, test): unittest.TestResult.startTest(self, test) self.runner.writeUpdate("%s : " % test.shortDescription()) # SEND TO DB THE UPDATE THAT WE RUN EACH TEST - psdb = TestSrv_Database() - psdb.open("setup.xml") - psdb.update_set_test_row(globalVar.station, globalVar.testid_ctl, globalVar.g_uuid, test.shortDescription(), "RUNNING") + self.__pgObj.update_set_test_row(globalVar.station, globalVar.testid_ctl, globalVar.g_uuid, test.shortDescription(), "RUNNING") + # psdb = TestSrv_Database() + # psdb.open("setup.xml") + # psdb.update_set_test_row(globalVar.station, globalVar.testid_ctl, globalVar.g_uuid, test.shortDescription(), "RUNNING") def addSuccess(self, test): unittest.TestResult.addSuccess(self, test) @@ -93,6 +100,7 @@ class TextTestResult(unittest.TestResult): if self.result == self.FAIL: simple_result = "FALSE" elif self.result == self.ERROR: simple_result = "FALSE" #SEND TO DB THE RESULT OF THE TEST - psdb = TestSrv_Database() - psdb.open("setup.xml") - psdb.add_test_to_batch(globalVar.g_uuid, test.shortDescription(), globalVar.testid_ctl, simple_result, globalVar.g_mid, test.longMessage) + # psdb = TestSrv_Database() + # psdb.open("setup.xml") + self.__pgObj.add_test_to_batch(globalVar.g_uuid, test.shortDescription(), globalVar.testid_ctl, simple_result, globalVar.g_mid, test.longMessage) + # psdb.add_test_to_batch(globalVar.g_uuid, test.shortDescription(), globalVar.testid_ctl, simple_result, globalVar.g_mid, test.longMessage) -- cgit v1.1 From dd9ffc52507c391271d0821636c683fd7562b46a Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Thu, 5 Mar 2020 18:50:47 +0100 Subject: Modified postgre functions. --- test-cli/test/runners/simple.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'test-cli/test/runners') diff --git a/test-cli/test/runners/simple.py b/test-cli/test/runners/simple.py index 3537d0e..084a5b8 100644 --- a/test-cli/test/runners/simple.py +++ b/test-cli/test/runners/simple.py @@ -89,12 +89,6 @@ class TextTestResult(unittest.TestResult): dbdata['name'] = test.shortDescription() dbdata['result'] = self.result dbdata['msg'] = str(test.longMessage) - #DB: INSERT IN THE DATABASE - filename='test_results.dat' - testResult = open(filename, 'a') - testResult.write(str(dbdata)) - testResult.write("\n") - testResult.close() #CONVERT FANCY FAIL AND PASS if self.result==self.PASS: simple_result="TRUE" if self.result == self.FAIL: simple_result = "FALSE" -- cgit v1.1 From 9f07a57d89a927aa9b172c1bf20c7ab563658c73 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Fri, 6 Mar 2020 12:46:27 +0100 Subject: Fixed multiple errors. --- test-cli/test/runners/simple.py | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'test-cli/test/runners') diff --git a/test-cli/test/runners/simple.py b/test-cli/test/runners/simple.py index 084a5b8..dd7c74d 100644 --- a/test-cli/test/runners/simple.py +++ b/test-cli/test/runners/simple.py @@ -12,7 +12,6 @@ from test.helpers.globalVariables import globalVar from test.helpers.testsrv_db import TestSrv_Database - class SimpleTestRunner: """ A Test Runner that shows results in a simple human-readable format. @@ -33,15 +32,12 @@ class SimpleTestRunner: self.stream.write(message) def run(self, test): - """ Run the given test case or Test Suite. - - """ + """ Run the given test case or Test Suite. """ result = TextTestResult(self, self.__pgObj) test(result) - result.testsRun - # self.writeUpdate("---------------------------------------------\n") return result + class TextTestResult(unittest.TestResult): # Print in terminal with colors PASS = '\033[32mPASS\033[0m\n' @@ -60,14 +56,11 @@ class TextTestResult(unittest.TestResult): unittest.TestResult.startTest(self, test) self.runner.writeUpdate("%s : " % test.shortDescription()) # SEND TO DB THE UPDATE THAT WE RUN EACH TEST - self.__pgObj.update_set_test_row(globalVar.station, globalVar.testid_ctl, globalVar.g_uuid, test.shortDescription(), "RUNNING") - # psdb = TestSrv_Database() - # psdb.open("setup.xml") - # psdb.update_set_test_row(globalVar.station, globalVar.testid_ctl, globalVar.g_uuid, test.shortDescription(), "RUNNING") + self.__pgObj.run_test(test.params["testidctl"], test.params["testid"]) def addSuccess(self, test): unittest.TestResult.addSuccess(self, test) - self.result=self.PASS + self.result = self.PASS def addError(self, test, err): unittest.TestResult.addError(self, test, err) @@ -76,25 +69,17 @@ class TextTestResult(unittest.TestResult): def addFailure(self, test, err): unittest.TestResult.addFailure(self, test, err) - test.longMessage=err[1] + test.longMessage = err[1] self.result = self.FAIL def stopTest(self, test): unittest.TestResult.stopTest(self, test) # display: print test result self.runner.writeUpdate(self.result) - # DB: PREPARE THE DATA TO BE INSERTED - dbdata = {} - dbdata['uuid'] = globalVar.g_uuid - dbdata['name'] = test.shortDescription() - dbdata['result'] = self.result - dbdata['msg'] = str(test.longMessage) - #CONVERT FANCY FAIL AND PASS - if self.result==self.PASS: simple_result="TRUE" - if self.result == self.FAIL: simple_result = "FALSE" - elif self.result == self.ERROR: simple_result = "FALSE" - #SEND TO DB THE RESULT OF THE TEST - # psdb = TestSrv_Database() - # psdb.open("setup.xml") - self.__pgObj.add_test_to_batch(globalVar.g_uuid, test.shortDescription(), globalVar.testid_ctl, simple_result, globalVar.g_mid, test.longMessage) - # psdb.add_test_to_batch(globalVar.g_uuid, test.shortDescription(), globalVar.testid_ctl, simple_result, globalVar.g_mid, test.longMessage) + # SEND TO DB THE RESULT OF THE TEST + if self.result == self.PASS: + status = "TEST_COMPLETE" + else: + status = "TEST_FAILED" + self.__pgObj.finish_test(test.params["testidctl"], test.params["testid"], status) + -- cgit v1.1 From 41ffba6a76a80a7ef4553cb8856393dd209d172e Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Tue, 10 Mar 2020 17:37:16 +0100 Subject: First release of the test. All the tests work correctly for SOPA0000. --- test-cli/test/runners/simple.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test-cli/test/runners') diff --git a/test-cli/test/runners/simple.py b/test-cli/test/runners/simple.py index dd7c74d..f8b4dd4 100644 --- a/test-cli/test/runners/simple.py +++ b/test-cli/test/runners/simple.py @@ -65,6 +65,7 @@ class TextTestResult(unittest.TestResult): def addError(self, test, err): unittest.TestResult.addError(self, test, err) test.longMessage = err[1] + print(err[1]) self.result = self.ERROR def addFailure(self, test, err): -- cgit v1.1 From e74e0a36d9ad6a01c04500f3a24cb0ef5dd0b283 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Fri, 13 Mar 2020 12:17:51 +0100 Subject: Added final flashing tasks: eeprom and nand. --- test-cli/test/runners/simple.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'test-cli/test/runners') diff --git a/test-cli/test/runners/simple.py b/test-cli/test/runners/simple.py index f8b4dd4..a165406 100644 --- a/test-cli/test/runners/simple.py +++ b/test-cli/test/runners/simple.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - """ Simple Test Runner for unittest module @@ -7,9 +5,6 @@ Simple Test Runner for unittest module import sys import unittest -import os -from test.helpers.globalVariables import globalVar -from test.helpers.testsrv_db import TestSrv_Database class SimpleTestRunner: @@ -65,7 +60,6 @@ class TextTestResult(unittest.TestResult): def addError(self, test, err): unittest.TestResult.addError(self, test, err) test.longMessage = err[1] - print(err[1]) self.result = self.ERROR def addFailure(self, test, err): -- 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/runners/simple.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'test-cli/test/runners') diff --git a/test-cli/test/runners/simple.py b/test-cli/test/runners/simple.py index a165406..e0418d2 100644 --- a/test-cli/test/runners/simple.py +++ b/test-cli/test/runners/simple.py @@ -71,10 +71,19 @@ class TextTestResult(unittest.TestResult): unittest.TestResult.stopTest(self, test) # display: print test result self.runner.writeUpdate(self.result) + # save result data + for result in test.getresults(): + if "desc" in result.keys() and result["desc"]: + if "type" in result.keys() and "data" in result.keys(): + if result["type"] == "string": + self.__pgObj.upload_result_string(test.params["testidctl"], test.params["testid"], + result["desc"], result["data"]) + elif result["type"] == "file": + self.__pgObj.upload_result_file(test.params["testidctl"], test.params["testid"], result["desc"], + result["data"]) # SEND TO DB THE RESULT OF THE TEST if self.result == self.PASS: status = "TEST_COMPLETE" else: status = "TEST_FAILED" self.__pgObj.finish_test(test.params["testidctl"], test.params["testid"], status) - -- 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/runners/simple.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test-cli/test/runners') diff --git a/test-cli/test/runners/simple.py b/test-cli/test/runners/simple.py index e0418d2..22fe449 100644 --- a/test-cli/test/runners/simple.py +++ b/test-cli/test/runners/simple.py @@ -79,8 +79,8 @@ class TextTestResult(unittest.TestResult): self.__pgObj.upload_result_string(test.params["testidctl"], test.params["testid"], result["desc"], result["data"]) elif result["type"] == "file": - self.__pgObj.upload_result_file(test.params["testidctl"], test.params["testid"], result["desc"], - result["data"]) + self.__pgObj.upload_result_file(test.params["testidctl"], test.params["testid"], + result["desc"], result["data"]) # SEND TO DB THE RESULT OF THE TEST if self.result == self.PASS: status = "TEST_COMPLETE" -- 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/runners/simple.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'test-cli/test/runners') diff --git a/test-cli/test/runners/simple.py b/test-cli/test/runners/simple.py index 22fe449..2eb61a4 100644 --- a/test-cli/test/runners/simple.py +++ b/test-cli/test/runners/simple.py @@ -59,8 +59,9 @@ class TextTestResult(unittest.TestResult): def addError(self, test, err): unittest.TestResult.addError(self, test, err) - test.longMessage = err[1] + # test.longMessage = err[1] self.result = self.ERROR + print(err[1]) def addFailure(self, test, err): unittest.TestResult.addFailure(self, test, err) @@ -73,17 +74,13 @@ class TextTestResult(unittest.TestResult): self.runner.writeUpdate(self.result) # save result data for result in test.getresults(): - if "desc" in result.keys() and result["desc"]: - if "type" in result.keys() and "data" in result.keys(): - if result["type"] == "string": - self.__pgObj.upload_result_string(test.params["testidctl"], test.params["testid"], - result["desc"], result["data"]) - elif result["type"] == "file": - self.__pgObj.upload_result_file(test.params["testidctl"], test.params["testid"], - result["desc"], result["data"]) + self.__pgObj.upload_result_file(test.params["testidctl"], test.params["testid"], + result["description"], result["filepath"], result["mimetype"]) # SEND TO DB THE RESULT OF THE TEST if self.result == self.PASS: status = "TEST_COMPLETE" + resulttext = test.gettextresult() else: status = "TEST_FAILED" - self.__pgObj.finish_test(test.params["testidctl"], test.params["testid"], status) + resulttext = test.longMessage + self.__pgObj.finish_test(test.params["testidctl"], test.params["testid"], status, resulttext) -- 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/runners/simple.py | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'test-cli/test/runners') diff --git a/test-cli/test/runners/simple.py b/test-cli/test/runners/simple.py index 2eb61a4..ece5a4e 100644 --- a/test-cli/test/runners/simple.py +++ b/test-cli/test/runners/simple.py @@ -5,6 +5,7 @@ Simple Test Runner for unittest module import sys import unittest +from test.helpers.iseelogger import logObj class SimpleTestRunner: @@ -59,28 +60,34 @@ class TextTestResult(unittest.TestResult): def addError(self, test, err): unittest.TestResult.addError(self, test, err) - # test.longMessage = err[1] + test.longMessage = err[1] self.result = self.ERROR - print(err[1]) + print(err) def addFailure(self, test, err): unittest.TestResult.addFailure(self, test, err) test.longMessage = err[1] self.result = self.FAIL + logObj.getlogger().info('{}:{}'.format(test, err)) def stopTest(self, test): - unittest.TestResult.stopTest(self, test) - # display: print test result - self.runner.writeUpdate(self.result) - # save result data - for result in test.getresults(): - self.__pgObj.upload_result_file(test.params["testidctl"], test.params["testid"], - result["description"], result["filepath"], result["mimetype"]) - # SEND TO DB THE RESULT OF THE TEST - if self.result == self.PASS: - status = "TEST_COMPLETE" - resulttext = test.gettextresult() - else: - status = "TEST_FAILED" - resulttext = test.longMessage - self.__pgObj.finish_test(test.params["testidctl"], test.params["testid"], status, resulttext) + try: + unittest.TestResult.stopTest(self, test) + # display: print test result + self.runner.writeUpdate(self.result) + # save result data + for result in test.getresults(): + self.__pgObj.upload_result_file(test.params["testidctl"], test.params["testid"], + result["description"], result["filepath"], result["mimetype"]) + # SEND TO DB THE RESULT OF THE TEST + if self.result == self.PASS: + status = "TEST_COMPLETE" + resulttext = test.gettextresult() + logObj.getlogger().info('{}:{}:{}:{}'.format(test.params["testidctl"], test.params["testid"], status, resulttext)) + else: + status = "TEST_FAILED" + resulttext = test.longMessage + logObj.getlogger().info('{}:{}:{}:{}'.format(test.params["testidctl"], test.params["testid"], status, resulttext)) + self.__pgObj.finish_test(test.params["testidctl"], test.params["testid"], status, resulttext) + except Exception as E: + logObj.getlogger().error('Exception: [{}]{}:{}:{}:{}'.format(E, test.params["testidctl"], test.params["testid"], status, resulttext)) \ No newline at end of file -- cgit v1.1 From 293f0682dd8258a068e4b152f9fecb292d732b78 Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Mon, 5 Oct 2020 11:45:41 +0200 Subject: modify finish_test call, added execution without messsage if fails --- test-cli/test/runners/simple.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test-cli/test/runners') diff --git a/test-cli/test/runners/simple.py b/test-cli/test/runners/simple.py index ece5a4e..c110b1c 100644 --- a/test-cli/test/runners/simple.py +++ b/test-cli/test/runners/simple.py @@ -88,6 +88,7 @@ class TextTestResult(unittest.TestResult): status = "TEST_FAILED" resulttext = test.longMessage logObj.getlogger().info('{}:{}:{}:{}'.format(test.params["testidctl"], test.params["testid"], status, resulttext)) - self.__pgObj.finish_test(test.params["testidctl"], test.params["testid"], status, resulttext) + if not self.__pgObj.finish_test(test.params["testidctl"], test.params["testid"], status, resulttext): + self.__pgObj.finish_test(test.params["testidctl"], test.params["testid"], status, "") except Exception as E: logObj.getlogger().error('Exception: [{}]{}:{}:{}:{}'.format(E, test.params["testidctl"], test.params["testid"], status, resulttext)) \ No newline at end of file -- cgit v1.1