allow setting division pararameter on test plan fetch

This commit is contained in:
Vincent Sanders 2019-11-28 22:45:34 +00:00
parent 86f73b767a
commit e39afa3c97

View File

@ -1,26 +1,30 @@
#!/usr/bin/python3
'''
NetSurf automated test runner
This script retrives a test plan from the NetSurf infrastructure and
executes it using the monkey frontend
'''
# If you have any poo, fling it now!
BASE_PATH="https://test.netsurf-browser.org/cgi-bin/monkey-index.cgi"
MONKEY_PATH="./nsmonkey"
import sys
import getopt
import multiprocessing as mp
from urllib import request, parse
from io import StringIO
import yaml
import monkey_driver as driver
# Otherwise let's begin...
import sys
import getopt
import yaml
import multiprocessing as mp
from urllib import request
from io import StringIO
import monkey_driver as driver
BASE_PATH = "https://test.netsurf-browser.org/cgi-bin/monkey-index.cgi"
MONKEY_PATH = "./nsmonkey"
mp.set_start_method('fork')
def child_run_test(parts):
def child_run_test(verbose, parts):
outcapture = StringIO()
errcapture = StringIO()
oldout = sys.stdout
@ -40,23 +44,24 @@ def child_run_test(parts):
else:
sys.stdout = oldout
sys.stderr = olderr
if verbose == True:
if verbose:
print("STDOUT:\n{}\n".format(outcapture.getvalue()))
def run_test(parts):
p = mp.Process(target=child_run_test, args=(parts, ))
def run_test(verbose, parts):
p = mp.Process(target=child_run_test, args=(verbose, parts, ))
p.start()
p.join()
return p.exitcode
def print_usage():
print('Usage:')
print(' ' + sys.argv[0] + ' [-v] [-h]')
print(' ' + sys.argv[0] + ' [-v] [-h] [-d <division>]')
def parse_argv(argv):
verbose=False
verbose = False
division = 'index'
try:
opts, args = getopt.getopt(argv,"hv",[])
opts, args = getopt.getopt(argv, "hvd:", [])
except getopt.GetoptError:
print_usage()
sys.exit(2)
@ -65,32 +70,43 @@ def parse_argv(argv):
print_usage()
sys.exit()
elif opt in ("-v", "--verbose"):
verbose=True
return verbose
verbose = True
elif opt == '-d':
division = arg
verbose = parse_argv(sys.argv[1:])
return verbose, division
print("Fetching tests...")
index = request.urlopen(BASE_PATH)
index = index.read()
print("Parsing tests...")
test_set = yaml.load_all(index)
def main():
verbose, division = parse_argv(sys.argv[1:])
print("Running tests...")
ret = 0
for test in test_set:
if test["kind"] == 'group':
print("Start group: {}".format(test["group"]))
print(" [ {} ]".format(test["description"]))
elif test["kind"] == 'test':
print(" => Run test: {}".format(test["filename"]))
ret = run_test(test["content"])
if ret != 0:
break
if ret != 0:
print("FAIL")
sys.exit(1)
else:
print("PASS")
sys.exit(0)
print("Fetching tests...")
data = parse.urlencode({"division": division}).encode()
req = request.Request(BASE_PATH, data=data)
index = request.urlopen(req)
index = index.read()
print("Parsing tests...")
test_set = yaml.load_all(index)
print("Running tests...")
ret = 0
for test in test_set:
if test["kind"] == 'group':
print("Start group: {}".format(test["group"]))
print(" [ {} ]".format(test["description"]))
elif test["kind"] == 'test':
print(" => Run test: {}".format(test["filename"]))
ret = run_test(verbose, test["content"])
if ret != 0:
break
if ret != 0:
print("FAIL")
sys.exit(1)
else:
print("PASS")
sys.exit(0)
if __name__ == "__main__":
main()