Commit 93baecd6 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Add the __main__ such that on can execute scripts in myScript, and tests in test

parent 0f65970e
from . import INFO, SPCE, WARN, SEVR, DBUG
from .test import myTest, G_TESTS_LIST
# Local required import ------------------------------------------------
import sys
import os
import getopt
# Usage ---------------------------------------------------
usage = '''
{0}Usage: python mfdPlot [-h]
{1} [-t]
{1} [--test <list of tests>]
{1} [-s/--script <name of the script>]
{1} [-a/--args <String of the arguments>]
{1} [--debug]
'''.format(INFO, SPCE)
run4test = False
run4script = False
tests = []
script2execute = ''
args4script = ''
DEBUG = False
# Get the options
try:
opts, args = getopt.getopt(sys.argv[1:], "hts:a:", ["test=", "plot=", "args=", "debug"])
except getopt.GetoptError:
print(usage)
sys.exit(1)
# Treat the options
for opt, arg in opts:
if(opt == '-h'):
print(usage)
sys.exit(0)
elif opt in ("-t",):
run4test = True
tests2execute = G_TESTS_LIST
elif opt in ("--test",):
run4test = True
tests = str(arg)
elif opt in ("-s", "--script"):
run4script = True
script2execute = str(arg)
elif opt in ("-a", "--args"):
args4script = str(arg)
elif opt in ("--debug"):
DEBUG = True
if(run4test):
fail = []
status = True
debug = DEBUG
for test in tests2execute:
print
print
print(INFO + '{title:{c}^{n}}'.format(title=' ' + str(test.__name__) + ' ', c='=', n=72))
testStatus = myTest(test, True, fail, debug)
if testStatus:
print(INFO + 72 * '-' + " [PASSED]")
else:
print(INFO + 72 * '-' + " [FAILED] !")
status = status and testStatus
# Print final status
print
print
print(INFO + 'Status of test series: ' + str(status))
if not status:
print(SPCE + 'Number of Failed Tests: ' + str(len(fail)))
print(SPCE + 'List of Failed Tests: ')
for test in fail:
print(SPCE + '\t- ' + str(test))
elif(run4script):
try:
os.system("python mypltemplate/myScripts/"+str(script2execute)+" "+str(args4script))
except:
print(SEVR + "I could not execute " + str(script2execute) + " with the following arguments: " + str(args4script))
sys.exit(1)
# end
print(INFO + 'END')
# IMPORT ---------------------------------------------------------------
# this is because I don't know how you renamed your module
import sys
import os
cwd = os.getcwd()
sys.path.append(cwd)
modulename = sys.path[0].split('/')[-2]
mymodule = __import__(modulename)
# Actually you can just write:
# from <your module name> import *
# BEGINING OF THE SCRIPT -----------------------------------------------
run = mymodule.readRun(cwd + "/" + modulename + "/data/serie2/run1.txt")
fig = mymodule.FigOneAxes3D((run,), mymodule.AxResults)
fig.print2file(cwd + "/" + modulename + "/img/serie2_run1_results.eps")
from tests import myTest
from tests import test100, test101, test102
G_TESTS_LIST = [test100, test101, test102]
name: 'run1'
input0: 100
input1: 100.
input2: 200
results: [[10, 20],[5,40]]
| name | input0 | input1 | input2 | maxResults |
|--------+--------+---------+--------+------------|
| 'run1' | 100 | 100. | 200 | 40 |
| 'run2' | 100 | 50. | 300 | 30 |
| 'run3' | 100 | 80. | 320 | 70 |
from .. import WARN
from .. import MyWin
from .. import readRun
from .. import readSerie
from .. import AxResults
from .. import AxMaxResults
from .. import AxParameterSpace
from .. import FigOneAxes2D, FigOneAxes3D
_MYMODULE = __name__.split('.')[0]
# TESTER
def myTest(function, expected, failed, debug):
if debug:
status = function(debug)
if status is not expected:
failed.append(str(function.__name__))
return(False)
else:
return(True)
else:
try:
status = function(debug)
if status is not expected:
failed.append(str(function.__name__))
return(False)
else:
return(True)
except:
print(WARN + str(function.__name__) + " caught exception.")
failed.append(str(function.__name__))
return(False)
return(True)
# Tests:
# - 100 axes
# - 200 figures
# TEST
def test100(debug):
status = True
run = readRun(_MYMODULE + "/test/data/serie4test/run4test.txt")
fig = FigOneAxes3D((run,), AxResults, debug=debug)
status = fig.plot()
del fig
del run
return(status)
# TEST
def test101(debug):
status = True
serie = readSerie(_MYMODULE + "/test/data/serie4test/serie4test.txt")
fig = FigOneAxes2D((serie,), AxMaxResults, debug=debug)
status = fig.plot()
del fig
del serie
return(status)
# TEST
def test102(debug):
status = True
serie = readSerie(_MYMODULE + "/test/data/serie4test/serie4test.txt")
fig = FigOneAxes2D((serie,), AxParameterSpace, debug=debug)
status = fig.plot()
del fig
del serie
return(status)
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