Gitlab will migrate to a new storage backend starting 0300 UTC on 2020-04-04. We do not anticipate a maintenance window for this migration. Performance may be impacted over the weekend. Thanks for your patience.

Commit f600ca5f authored by Daniel Brown's avatar Daniel Brown

Merge branch 'master' of git.ligo.org:finesse/test

parents 5661cdd2 391ee2b2
...@@ -8,22 +8,34 @@ import os.path as path ...@@ -8,22 +8,34 @@ import os.path as path
import requests import requests
import traceback import traceback
################ Exceptions ################ # ===========
# Exceptions
# ===========
# Setting the exception hooks
# ---------------------------
class ExitCodeException(Exception): class ExitCodeException(Exception):
""" Base class for all exceptions which set the exit code""" """ Base class for all exceptions which set the exit code"""
def getExitCode(self): def getExitCode(self):
"meant to be overridden in subclass" "meant to be overridden in subclass"
return 1 return 1
def handleUncaughtException(exctype, value, trace): def handleUncaughtException(exctype, value, trace):
oldHook(exctype, value, trace) """ Function to exit with error code from exception object """
if isinstance(value, ExitCodeException): oldHook(exctype, value, trace)
sys.exit(value.getExitCode()) if isinstance(value, ExitCodeException):
sys.exit(value.getExitCode())
# Set the exception hook to be our new function which exits with a error code
# Store old hook as a variable
sys.excepthook, oldHook = handleUncaughtException, sys.excepthook sys.excepthook, oldHook = handleUncaughtException, sys.excepthook
# Definning new exceptions
# --------------------------
class RunException(ExitCodeException): class RunException(ExitCodeException):
""" Exception for failures of finesse to run """
def __init__(self, returncode, args, err, out): def __init__(self, returncode, args, err, out):
self.returncode = returncode self.returncode = returncode
self.args = args self.args = args
...@@ -35,6 +47,7 @@ class RunException(ExitCodeException): ...@@ -35,6 +47,7 @@ class RunException(ExitCodeException):
return 3 return 3
class DiffException(ExitCodeException): class DiffException(ExitCodeException):
""" Exception for differances against the referance file """
def __init__(self, msg, outfile): def __init__(self, msg, outfile):
self.msg = msg self.msg = msg
self.outfile = outfile self.outfile = outfile
...@@ -42,9 +55,11 @@ class DiffException(ExitCodeException): ...@@ -42,9 +55,11 @@ class DiffException(ExitCodeException):
def getExitCode(self): def getExitCode(self):
return 5 return 5
################ Functions ################ # ===========
# Functions
# ===========
def runkat(katfile): def runkat(katfile):
""" Run the katfile """
try: try:
p = sub.Popen(["kat","--test","--noheader",katfile], stdout=sub.PIPE, stderr=sub.PIPE) p = sub.Popen(["kat","--test","--noheader",katfile], stdout=sub.PIPE, stderr=sub.PIPE)
out, err = p.communicate() out, err = p.communicate()
...@@ -55,6 +70,9 @@ def runkat(katfile): ...@@ -55,6 +70,9 @@ def runkat(katfile):
except OSError: except OSError:
pass pass
# BrumSoftTest once we leave this file, stdout and stderr get mapped though
# docker back to the system stdout and stderr on the host server
# This can only handel ascii, so here we re-encode the data stream as ascii
encoding=sys.stdout.encoding encoding=sys.stdout.encoding
if encoding==None: if encoding==None:
encoding='utf-8' encoding='utf-8'
...@@ -64,12 +82,14 @@ def runkat(katfile): ...@@ -64,12 +82,14 @@ def runkat(katfile):
print(out.encode('ascii','replace')) print(out.encode('ascii','replace'))
print(err.encode('ascii','replace'), file=sys.stderr) print(err.encode('ascii','replace'), file=sys.stderr)
# if finesse exited with a non-zero error code we raise a run exception (which maps to error code 3)
if p.returncode != 0: if p.returncode != 0:
raise RunException(p.returncode, "kat "+katfile, err, out) raise RunException(p.returncode, "kat "+katfile, err, out)
return [out,err,p.returncode] return [out,err,p.returncode]
def diff(katfile): def diff(katfile):
""" If everything ran okay we will calculate the differance """
diffFound = False diffFound = False
katdir=path.dirname(katfile) katdir=path.dirname(katfile)
...@@ -139,7 +159,18 @@ def diff(katfile): ...@@ -139,7 +159,18 @@ def diff(katfile):
if __name__ == "__main__": if __name__ == "__main__":
print("Kat Test Started, Arguments: "+str(sys.argv)) print("Kat Test Started, Arguments: "+str(sys.argv))
test_kat = sys.argv[1] test_kat = sys.argv[1]
runkat(test_kat)
try:
runkat(test_kat)
except Exception as e:
errtext = 'Error running finesse. Output file not produced, referance file not used. These will not be uploaded'
print(errtext)
print(errtext, file=sys.stderr)
raise e
else:
print('Finesse ran without error')
try: try:
diff(test_kat) diff(test_kat)
finally: finally:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment