summaryrefslogtreecommitdiff
path: root/test-cli/test/runners
diff options
context:
space:
mode:
authorManel Caro <mcaro@iatec.biz>2021-11-06 16:28:38 +0100
committerManel Caro <mcaro@iatec.biz>2021-11-06 16:28:38 +0100
commitcf19bfe18cbd283b188a858ee1629f9909c924f4 (patch)
tree1efb23519727130058401df090ab1b5f4cc8ba99 /test-cli/test/runners
parentb6932fbaf898724ae87c29f8965621610f377084 (diff)
parentd5b273a3b58a250742049df4ca0ef0ba54f53d33 (diff)
downloadboard-cf19bfe18cbd283b188a858ee1629f9909c924f4.zip
board-cf19bfe18cbd283b188a858ee1629f9909c924f4.tar.gz
board-cf19bfe18cbd283b188a858ee1629f9909c924f4.tar.bz2
Merge branch 'sopa-test'rel.0.1sopa-test
Diffstat (limited to 'test-cli/test/runners')
-rw-r--r--test-cli/test/runners/simple.py80
1 files changed, 38 insertions, 42 deletions
diff --git a/test-cli/test/runners/simple.py b/test-cli/test/runners/simple.py
index 5b2da5a..c110b1c 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,10 +5,7 @@ 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
-
+from test.helpers.iseelogger import logObj
class SimpleTestRunner:
@@ -22,77 +17,78 @@ 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)
def run(self, test):
- """ Run the given test case or Test Suite.
-
- """
- result = TextTestResult(self)
+ """ 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'
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.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)
test.longMessage = err[1]
self.result = self.ERROR
+ print(err)
def addFailure(self, test, err):
unittest.TestResult.addFailure(self, test, err)
- test.longMessage=err[1]
+ 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)
- # 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)
- #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"
- 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)
+ 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))
+ 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