summaryrefslogtreecommitdiff
path: root/test-cli/test/runners
diff options
context:
space:
mode:
Diffstat (limited to 'test-cli/test/runners')
-rw-r--r--test-cli/test/runners/__init__.py0
-rw-r--r--test-cli/test/runners/__pycache__/__init__.cpython-35.pycbin0 -> 146 bytes
-rw-r--r--test-cli/test/runners/__pycache__/simple.cpython-35.pycbin0 -> 3452 bytes
-rw-r--r--test-cli/test/runners/simple.py98
4 files changed, 98 insertions, 0 deletions
diff --git a/test-cli/test/runners/__init__.py b/test-cli/test/runners/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test-cli/test/runners/__init__.py
diff --git a/test-cli/test/runners/__pycache__/__init__.cpython-35.pyc b/test-cli/test/runners/__pycache__/__init__.cpython-35.pyc
new file mode 100644
index 0000000..2927283
--- /dev/null
+++ b/test-cli/test/runners/__pycache__/__init__.cpython-35.pyc
Binary files differ
diff --git a/test-cli/test/runners/__pycache__/simple.cpython-35.pyc b/test-cli/test/runners/__pycache__/simple.cpython-35.pyc
new file mode 100644
index 0000000..e7a35ea
--- /dev/null
+++ b/test-cli/test/runners/__pycache__/simple.cpython-35.pyc
Binary files differ
diff --git a/test-cli/test/runners/simple.py b/test-cli/test/runners/simple.py
new file mode 100644
index 0000000..5b2da5a
--- /dev/null
+++ b/test-cli/test/runners/simple.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+
+"""
+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:
+ """ A Test Runner that shows results in a simple human-readable format.
+
+ As example, a common output is:
+ This is a test short description : PASS
+ This is another test short description : FAIL
+ ---------------------------------------------
+
+ """
+ def __init__(self, stream=sys.stderr, verbosity=0):
+ self.stream = stream
+ self.verbosity = verbosity
+
+ def writeUpdate(self, message):
+ self.stream.write(message)
+
+ def run(self, test):
+ """ Run the given test case or Test Suite.
+
+ """
+ result = TextTestResult(self)
+ 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):
+ unittest.TestResult.__init__(self)
+ self.runner = runner
+ self.result = self.ERROR
+
+ 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")
+
+ def addSuccess(self, test):
+ unittest.TestResult.addSuccess(self, test)
+ self.result=self.PASS
+
+ def addError(self, test, err):
+ unittest.TestResult.addError(self, test, err)
+ test.longMessage = err[1]
+ self.result = self.ERROR
+
+ def addFailure(self, test, err):
+ unittest.TestResult.addFailure(self, test, err)
+ 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)
+ #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)