From eb4749e392e688aaa16851568c981749891462a8 Mon Sep 17 00:00:00 2001 From: asteroide Date: Wed, 25 Nov 2015 17:12:41 +0100 Subject: Add an aggregator for moonclient tests. Change-Id: I4c784def32998cdb998bc5532a24e6a7a6dcb3b7 --- moonclient/moonclient/tests.py | 45 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'moonclient') diff --git a/moonclient/moonclient/tests.py b/moonclient/moonclient/tests.py index 24732db5..fb4daa69 100644 --- a/moonclient/moonclient/tests.py +++ b/moonclient/moonclient/tests.py @@ -13,6 +13,7 @@ from uuid import uuid4 import os import time import subprocess +import glob class TestsLaunch(Lister): @@ -27,8 +28,10 @@ class TestsLaunch(Lister): parser = super(TestsLaunch, self).get_parser(prog_name) parser.add_argument( 'testfile', - metavar='', - help='Filename that contains tests to run', + metavar='', + help='Filenames that contains tests to run ' + '(examples: /path/to/test.json, /path/to/directory/, ' + '"/path/to/*-file.json" -- don\'t forget the quote)', ) return parser @@ -50,11 +53,45 @@ class TestsLaunch(Lister): def take_action(self, parsed_args): self.log.info("Write tests output to {}".format(self.logfile_name)) - stdout_back = self.app.stdout if not parsed_args.testfile: self.log.error("You don't give a test filename.") raise Exception("Cannot execute tests.") - tests_dict = json.load(open(parsed_args.testfile)) + if os.path.isfile(parsed_args.testfile): + return self.test_file(parsed_args.testfile) + else: + cpt = 1 + filenames = [] + global_result = {} + if os.path.isdir(parsed_args.testfile): + filenames = glob.glob(parsed_args.testfile + "/*.json") + else: + filenames = glob.glob(parsed_args.testfile) + for filename in filenames: + if os.path.isfile(filename): + self.log.info("\n\033[1m\033[32mExecuting {} ({}/{})\033[m".format(filename, cpt, len(filenames))) + global_result[filename] = self.test_file(filename) + cpt += 1 + results = [] + for result_id, result_values in global_result.iteritems(): + result_ok = True + # self.log.info(result_id) + # self.log.info(result_values[1]) + for value in result_values[1]: + if "False" in value[2]: + result_ok = False + break + if result_ok: + results.append((result_id, "\033[32mTrue\033[m")) + else: + results.append((result_id, "\033[1m\033[31mFalse\033[m")) + return ( + ("filename", "results"), + results + ) + + def test_file(self, testfile): + stdout_back = self.app.stdout + tests_dict = json.load(open(testfile)) self.log.debug("tests_dict = {}".format(tests_dict)) global_command_options = "" if "command_options" in tests_dict: -- cgit 1.2.3-korg