From e39afa3c9734399c0285a019980147710761a589 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 28 Nov 2019 22:45:34 +0000 Subject: allow setting division pararameter on test plan fetch --- test/monkey-see-monkey-do | 106 ++++++++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 45 deletions(-) (limited to 'test') diff --git a/test/monkey-see-monkey-do b/test/monkey-see-monkey-do index 8de29fa53..48d9953fb 100755 --- a/test/monkey-see-monkey-do +++ b/test/monkey-see-monkey-do @@ -1,26 +1,30 @@ #!/usr/bin/python3 -# If you have any poo, fling it now! +''' +NetSurf automated test runner -BASE_PATH="https://test.netsurf-browser.org/cgi-bin/monkey-index.cgi" -MONKEY_PATH="./nsmonkey" +This script retrives a test plan from the NetSurf infrastructure and + executes it using the monkey frontend +''' -# Otherwise let's begin... +# If you have any poo, fling it now! import sys import getopt -import yaml - import multiprocessing as mp - -from urllib import request +from urllib import request, parse from io import StringIO - +import yaml import monkey_driver as driver +# Otherwise let's begin... + +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 ]') 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 = parse_argv(sys.argv[1:]) - -print("Fetching tests...") -index = request.urlopen(BASE_PATH) -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(test["content"]) - if ret != 0: - break - -if ret != 0: - print("FAIL") - sys.exit(1) -else: - print("PASS") - sys.exit(0) + verbose = True + elif opt == '-d': + division = arg + + return verbose, division + +def main(): + verbose, division = parse_argv(sys.argv[1:]) + + 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() -- cgit v1.2.3