Nicolas Dechesne | 3f22575 | 2020-09-29 13:22:53 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
Milosz Wasilewski | 68279b2 | 2018-02-21 12:41:02 +0000 | [diff] [blame] | 3 | import collections |
Milosz Wasilewski | f9e70c0 | 2020-09-25 13:19:44 +0100 | [diff] [blame] | 4 | import datetime |
Milosz Wasilewski | 9c00f73 | 2020-08-04 10:29:35 +0100 | [diff] [blame] | 5 | import logging |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 6 | import os |
Milosz Wasilewski | 923ed1b | 2020-08-10 16:15:46 +0100 | [diff] [blame] | 7 | import pdfkit |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 8 | import subprocess |
| 9 | import yaml |
| 10 | from argparse import ArgumentParser |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 11 | from csv import DictWriter |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 12 | from jinja2 import Environment, FileSystemLoader |
| 13 | |
| 14 | |
Milosz Wasilewski | 9c00f73 | 2020-08-04 10:29:35 +0100 | [diff] [blame] | 15 | logger = logging.getLogger() |
| 16 | |
| 17 | |
Milosz Wasilewski | 68279b2 | 2018-02-21 12:41:02 +0000 | [diff] [blame] | 18 | class PrependOrderedDict(collections.OrderedDict): |
Milosz Wasilewski | 68279b2 | 2018-02-21 12:41:02 +0000 | [diff] [blame] | 19 | def prepend(self, key, value, dict_setitem=dict.__setitem__): |
Milosz Wasilewski | 9c00f73 | 2020-08-04 10:29:35 +0100 | [diff] [blame] | 20 | self[key] = value |
| 21 | self.move_to_end(key, last=False) |
Milosz Wasilewski | 68279b2 | 2018-02-21 12:41:02 +0000 | [diff] [blame] | 22 | |
| 23 | |
Milosz Wasilewski | e6f1632 | 2020-08-04 10:30:05 +0100 | [diff] [blame] | 24 | def render(obj, template="testplan.html", templates_dir=None, name=None): |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 25 | if name is None: |
| 26 | name = template |
Milosz Wasilewski | e6f1632 | 2020-08-04 10:30:05 +0100 | [diff] [blame] | 27 | if templates_dir is None: |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 28 | templates_dir = os.path.join( |
| 29 | os.path.dirname(os.path.abspath(__file__)), "templates" |
| 30 | ) |
Milosz Wasilewski | f761ab9 | 2018-02-13 11:21:18 +0000 | [diff] [blame] | 31 | _env = Environment(loader=FileSystemLoader(templates_dir)) |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 32 | _template = _env.get_template(template) |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 33 | obj["metadata"]["now"] = datetime.date.today().strftime("%B %d, %Y") |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 34 | _obj = _template.render(obj=obj) |
| 35 | with open("{}".format(name), "wb") as _file: |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 36 | _file.write(_obj.encode("utf-8")) |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 37 | |
Nicolas Dechesne | cd2e0f1 | 2020-09-29 11:20:25 +0200 | [diff] [blame] | 38 | # if the template is a .textile template, let's convert the output file to html |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 39 | if os.path.splitext(name)[1] == ".textile": |
Nicolas Dechesne | cd2e0f1 | 2020-09-29 11:20:25 +0200 | [diff] [blame] | 40 | import textile |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 41 | |
Nicolas Dechesne | cd2e0f1 | 2020-09-29 11:20:25 +0200 | [diff] [blame] | 42 | with open("{}".format(name), "r") as _file: |
| 43 | data = _file.read() |
| 44 | with open("{}{}".format(os.path.splitext(name)[0], ".html"), "w") as _file: |
| 45 | _file.write(textile.textile(data)) |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 46 | |
Nicolas Dechesne | d932555 | 2020-09-29 13:20:44 +0200 | [diff] [blame] | 47 | |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 48 | # get list of repositories and cache them |
| 49 | def repository_list(testplan): |
| 50 | repositories = set() |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 51 | tp_version = testplan["metadata"]["format"] |
Milosz Wasilewski | d5e1dd9 | 2018-02-12 12:08:44 +0000 | [diff] [blame] | 52 | if tp_version == "Linaro Test Plan v2": |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 53 | if ( |
| 54 | "manual" in testplan["tests"].keys() |
| 55 | and testplan["tests"]["manual"] is not None |
| 56 | ): |
| 57 | for test in testplan["tests"]["manual"]: |
| 58 | repositories.add(test["repository"]) |
Milosz Wasilewski | d5e1dd9 | 2018-02-12 12:08:44 +0000 | [diff] [blame] | 59 | |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 60 | if ( |
| 61 | "automated" in testplan["tests"].keys() |
| 62 | and testplan["tests"]["automated"] is not None |
| 63 | ): |
| 64 | for test in testplan["tests"]["automated"]: |
| 65 | repositories.add(test["repository"]) |
Milosz Wasilewski | d5e1dd9 | 2018-02-12 12:08:44 +0000 | [diff] [blame] | 66 | if tp_version == "Linaro Test Plan v1": |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 67 | for req in testplan["requirements"]: |
| 68 | if "tests" in req.keys() and req["tests"] is not None: |
| 69 | if ( |
| 70 | "manual" in req["tests"].keys() |
| 71 | and req["tests"]["manual"] is not None |
| 72 | ): |
| 73 | for test in req["tests"]["manual"]: |
| 74 | repositories.add(test["repository"]) |
| 75 | if ( |
| 76 | "automated" in req["tests"].keys() |
| 77 | and req["tests"]["automated"] is not None |
| 78 | ): |
| 79 | for test in req["tests"]["automated"]: |
| 80 | repositories.add(test["repository"]) |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 81 | return repositories |
| 82 | |
| 83 | |
| 84 | def clone_repository(repository_url, base_path, ignore=False): |
| 85 | path_suffix = repository_url.rsplit("/", 1)[1] |
| 86 | if path_suffix.endswith(".git"): |
| 87 | path_suffix = path_suffix[:-4] |
| 88 | |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 89 | path = os.path.abspath(os.path.join(base_path, path_suffix)) |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 90 | if os.path.exists(path) and ignore: |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 91 | return (repository_url, path) |
Nicolas Dechesne | 1f3fa5b | 2020-10-02 12:15:19 +0200 | [diff] [blame] | 92 | |
| 93 | # if the user does not use --ignore-clone, let's default to updating our local copy |
| 94 | if os.path.exists(path): |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 95 | subprocess.call(["git", "pull", "--ff-only"], cwd=path) |
| 96 | return (repository_url, path) |
Nicolas Dechesne | 1f3fa5b | 2020-10-02 12:15:19 +0200 | [diff] [blame] | 97 | |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 98 | # git clone repository_url |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 99 | subprocess.call(["git", "clone", repository_url, path]) |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 100 | # return tuple (repository_url, system_path) |
| 101 | return (repository_url, path) |
| 102 | |
| 103 | |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 104 | def test_exists(test, repositories, args): |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 105 | test_file_path = os.path.join(repositories[test["repository"]], test["path"]) |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 106 | current_dir = os.getcwd() |
Milosz Wasilewski | 9c00f73 | 2020-08-04 10:29:35 +0100 | [diff] [blame] | 107 | logger.debug("Current dir: {}".format(current_dir)) |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 108 | os.chdir(repositories[test["repository"]]) |
| 109 | if "revision" in test.keys(): |
| 110 | subprocess.call(["git", "checkout", test["revision"]]) |
| 111 | elif "branch" in test.keys(): |
| 112 | subprocess.call(["git", "checkout", test["branch"]]) |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 113 | else: |
| 114 | # if no revision is specified, use current HEAD |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 115 | output = subprocess.check_output(["git", "rev-parse", "HEAD"]) |
| 116 | test["revision"] = output.decode("utf-8").strip() |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 117 | |
| 118 | if not os.path.exists(test_file_path) or not os.path.isfile(test_file_path): |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 119 | test["missing"] = True |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 120 | os.chdir(current_dir) |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 121 | return not test["missing"] |
| 122 | test["missing"] = False |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 123 | # open the file and render the test |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 124 | subprocess.call(["git", "checkout", "-q", "master"]) |
Milosz Wasilewski | 9c00f73 | 2020-08-04 10:29:35 +0100 | [diff] [blame] | 125 | logger.debug("Current dir: {}".format(current_dir)) |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 126 | os.chdir(current_dir) |
Milosz Wasilewski | 9c00f73 | 2020-08-04 10:29:35 +0100 | [diff] [blame] | 127 | logger.debug("CWD: {}".format(os.getcwd())) |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 128 | test_file = open(test_file_path, "r") |
Ryan Harkin | 646fbff | 2020-07-09 22:11:11 +0100 | [diff] [blame] | 129 | test_yaml = yaml.load(test_file.read(), Loader=yaml.FullLoader) |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 130 | params_string = "" |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 131 | if "parameters" in test.keys(): |
| 132 | params_string = "_".join( |
| 133 | [ |
| 134 | "{0}-{1}".format(param_name, param_value) |
| 135 | .replace("/", "") |
| 136 | .replace(" ", "") |
| 137 | for param_name, param_value in test["parameters"].items() |
| 138 | ] |
| 139 | ) |
| 140 | test_yaml["params"].update(test["parameters"]) |
Nicolas Dechesne | 0d0f5a4 | 2020-09-29 11:26:49 +0200 | [diff] [blame] | 141 | |
| 142 | # add all default params from YAML test def in the test object |
| 143 | if args.single_output: |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 144 | if "params" in test_yaml.keys(): |
| 145 | if "parameters" not in test: |
| 146 | test["parameters"] = {} |
| 147 | for param_name, param_value in test_yaml["params"].items(): |
| 148 | if param_name not in test["parameters"].keys(): |
| 149 | test["parameters"].update({param_name: param_value}) |
Milosz Wasilewski | 9c00f73 | 2020-08-04 10:29:35 +0100 | [diff] [blame] | 150 | logger.debug("PARAM strings: {}".format(params_string)) |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 151 | test_name = "{0}_{1}.html".format(test_yaml["metadata"]["name"], params_string) |
Milosz Wasilewski | 807c0ea | 2018-02-13 19:14:01 +0000 | [diff] [blame] | 152 | if not args.single_output: |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 153 | test["filename"] = test_name |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 154 | test_path = os.path.join(os.path.abspath(args.output), test_name) |
Milosz Wasilewski | 807c0ea | 2018-02-13 19:14:01 +0000 | [diff] [blame] | 155 | if args.single_output: |
| 156 | # update test plan object |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 157 | test.update(test_yaml["run"]) |
Milosz Wasilewski | 68279b2 | 2018-02-21 12:41:02 +0000 | [diff] [blame] | 158 | # prepend in reversed order so 'name' is on top |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 159 | test.prepend("os", test_yaml["metadata"]["os"]) |
| 160 | test.prepend("scope", test_yaml["metadata"]["scope"]) |
| 161 | test.prepend("description", test_yaml["metadata"]["description"]) |
| 162 | if "name" not in test: |
| 163 | test.prepend("name", test_yaml["metadata"]["name"]) |
Milosz Wasilewski | 807c0ea | 2018-02-13 19:14:01 +0000 | [diff] [blame] | 164 | else: |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 165 | render( |
| 166 | test_yaml, |
| 167 | templates_dir=args.templates_directory, |
| 168 | template=args.test_template_name, |
| 169 | name=test_path, |
| 170 | ) |
| 171 | return not test["missing"] |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 172 | |
| 173 | |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 174 | def add_csv_row(requirement, test, args, manual=False): |
| 175 | fieldnames = [ |
| 176 | "req_name", |
| 177 | "req_owner", |
| 178 | "req_category", |
| 179 | "path", |
| 180 | "repository", |
| 181 | "revision", |
| 182 | "parameters", |
| 183 | "mandatory", |
| 184 | "kind", |
| 185 | ] |
| 186 | csv_file_path = os.path.join(os.path.abspath(args.output), args.csv_name) |
| 187 | has_header = False |
| 188 | if os.path.isfile(csv_file_path): |
| 189 | has_header = True |
| 190 | with open(csv_file_path, "ab+") as csv_file: |
| 191 | csvdict = DictWriter(csv_file, fieldnames=fieldnames) |
| 192 | if not has_header: |
| 193 | csvdict.writeheader() |
| 194 | csvdict.writerow( |
| 195 | { |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 196 | "req_name": requirement.get("name"), |
| 197 | "req_owner": requirement.get("owner"), |
| 198 | "req_category": requirement.get("category"), |
| 199 | "path": test.get("path"), |
| 200 | "repository": test.get("repository"), |
| 201 | "revision": test.get("revision"), |
| 202 | "parameters": test.get("parameters"), |
| 203 | "mandatory": test.get("mandatory"), |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 204 | "kind": "manual" if manual else "automated", |
| 205 | } |
| 206 | ) |
| 207 | |
| 208 | |
| 209 | def check_coverage(requirement, repositories, args): |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 210 | requirement["covered"] = False |
| 211 | if "tests" not in requirement.keys() or requirement["tests"] is None: |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 212 | return |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 213 | if ( |
| 214 | "manual" in requirement["tests"].keys() |
| 215 | and requirement["tests"]["manual"] is not None |
| 216 | ): |
| 217 | for test in requirement["tests"]["manual"]: |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 218 | if test_exists(test, repositories, args): |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 219 | requirement["covered"] = True |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 220 | if args.csv_name: |
| 221 | add_csv_row(requirement, test, args, True) |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 222 | if ( |
| 223 | "automated" in requirement["tests"].keys() |
| 224 | and requirement["tests"]["automated"] is not None |
| 225 | ): |
| 226 | for test in requirement["tests"]["automated"]: |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 227 | if test_exists(test, repositories, args): |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 228 | requirement["covered"] = True |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 229 | if args.csv_name: |
| 230 | add_csv_row(requirement, test, args) |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 231 | |
| 232 | |
Milosz Wasilewski | 68279b2 | 2018-02-21 12:41:02 +0000 | [diff] [blame] | 233 | def dict_representer(dumper, data): |
| 234 | return dumper.represent_dict(data.iteritems()) |
| 235 | |
| 236 | |
| 237 | def dict_constructor(loader, node): |
| 238 | return PrependOrderedDict(loader.construct_pairs(node)) |
| 239 | |
| 240 | |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 241 | def main(): |
| 242 | parser = ArgumentParser() |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 243 | parser.add_argument( |
| 244 | "-f", |
| 245 | "--file", |
| 246 | dest="testplan_list", |
| 247 | required=True, |
| 248 | nargs="+", |
| 249 | help="Test plan file to be used", |
| 250 | ) |
| 251 | parser.add_argument( |
| 252 | "-r", |
| 253 | "--repositories", |
| 254 | dest="repository_path", |
| 255 | default="repositories", |
| 256 | help="Test plan file to be used", |
| 257 | ) |
| 258 | parser.add_argument( |
| 259 | "-o", |
| 260 | "--output", |
| 261 | dest="output", |
| 262 | default="output", |
| 263 | help="Destination directory for generated files", |
| 264 | ) |
| 265 | parser.add_argument( |
| 266 | "-i", |
| 267 | "--ignore-clone", |
| 268 | dest="ignore_clone", |
| 269 | action="store_true", |
| 270 | default=False, |
| 271 | help="Ignore cloning repositories and use previously cloned", |
| 272 | ) |
| 273 | parser.add_argument( |
| 274 | "-s", |
| 275 | "--single-file-output", |
| 276 | dest="single_output", |
| 277 | action="store_true", |
| 278 | default=False, |
| 279 | help="""Render test plan into single HTML file. This option ignores |
| 280 | any metadata that is available in test cases""", |
| 281 | ) |
| 282 | parser.add_argument( |
| 283 | "-c", |
| 284 | "--csv", |
| 285 | dest="csv_name", |
| 286 | required=False, |
| 287 | help="Name of CSV to store overall list of requirements and test. If name is absent, the file will not be generated", |
| 288 | ) |
| 289 | parser.add_argument( |
| 290 | "--test-template-name", |
| 291 | default="test.html", |
| 292 | help="Name of the template used for rendering individual tests", |
| 293 | ) |
| 294 | parser.add_argument( |
| 295 | "--testplan-template-name", |
| 296 | help="Name of the template used for rendering testsplans", |
| 297 | ) |
| 298 | parser.add_argument( |
| 299 | "--templates-directory", |
| 300 | default=None, |
| 301 | help="Directory where the templates are located (absolute path)", |
| 302 | ) |
| 303 | parser.add_argument( |
| 304 | "--pdf", |
| 305 | default=None, |
| 306 | help="Path to the output pdf file. Only works if output generates HTML", |
| 307 | ) |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 308 | |
Milosz Wasilewski | 68279b2 | 2018-02-21 12:41:02 +0000 | [diff] [blame] | 309 | _mapping_tag = yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG |
| 310 | yaml.add_representer(PrependOrderedDict, dict_representer) |
| 311 | yaml.add_constructor(_mapping_tag, dict_constructor) |
| 312 | |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 313 | args = parser.parse_args() |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 314 | if not os.path.exists(os.path.abspath(args.output)): |
Milosz Wasilewski | 9c00f73 | 2020-08-04 10:29:35 +0100 | [diff] [blame] | 315 | os.makedirs(os.path.abspath(args.output), mode=0o755) |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 316 | for testplan in args.testplan_list: |
| 317 | if os.path.exists(testplan) and os.path.isfile(testplan): |
| 318 | testplan_file = open(testplan, "r") |
Ryan Harkin | 646fbff | 2020-07-09 22:11:11 +0100 | [diff] [blame] | 319 | tp_obj = yaml.load(testplan_file.read(), Loader=yaml.FullLoader) |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 320 | repo_list = repository_list(tp_obj) |
| 321 | repositories = {} |
| 322 | for repo in repo_list: |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 323 | repo_url, repo_path = clone_repository( |
| 324 | repo, args.repository_path, args.ignore_clone |
| 325 | ) |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 326 | repositories.update({repo_url: repo_path}) |
| 327 | # ToDo: check test plan structure |
Milosz Wasilewski | d5e1dd9 | 2018-02-12 12:08:44 +0000 | [diff] [blame] | 328 | |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 329 | tp_version = tp_obj["metadata"]["format"] |
Milosz Wasilewski | d5e1dd9 | 2018-02-12 12:08:44 +0000 | [diff] [blame] | 330 | if tp_version == "Linaro Test Plan v1": |
Nicolas Dechesne | 8ee692d | 2021-02-02 00:00:00 +0100 | [diff] [blame] | 331 | testplan_template = args.testplan_template_name or "testplan.html" |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 332 | for requirement in tp_obj["requirements"]: |
Milosz Wasilewski | d5e1dd9 | 2018-02-12 12:08:44 +0000 | [diff] [blame] | 333 | check_coverage(requirement, repositories, args) |
| 334 | if tp_version == "Linaro Test Plan v2": |
Nicolas Dechesne | 8ee692d | 2021-02-02 00:00:00 +0100 | [diff] [blame] | 335 | testplan_template = args.testplan_template_name or "testplan_v2.html" |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 336 | if ( |
| 337 | "manual" in tp_obj["tests"].keys() |
| 338 | and tp_obj["tests"]["manual"] is not None |
| 339 | ): |
| 340 | for test in tp_obj["tests"]["manual"]: |
Milosz Wasilewski | d5e1dd9 | 2018-02-12 12:08:44 +0000 | [diff] [blame] | 341 | test_exists(test, repositories, args) |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 342 | if ( |
| 343 | "automated" in tp_obj["tests"].keys() |
| 344 | and tp_obj["tests"]["automated"] is not None |
| 345 | ): |
| 346 | for test in tp_obj["tests"]["automated"]: |
Milosz Wasilewski | d5e1dd9 | 2018-02-12 12:08:44 +0000 | [diff] [blame] | 347 | test_exists(test, repositories, args) |
Milosz Wasilewski | f9e70c0 | 2020-09-25 13:19:44 +0100 | [diff] [blame] | 348 | # same filename extension as the template |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 349 | tp_name = ( |
| 350 | tp_obj["metadata"]["name"] + os.path.splitext(testplan_template)[1] |
| 351 | ) |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 352 | tp_file_name = os.path.join(os.path.abspath(args.output), tp_name) |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 353 | render( |
| 354 | tp_obj, |
| 355 | templates_dir=args.templates_directory, |
| 356 | template=testplan_template, |
| 357 | name=tp_file_name, |
| 358 | ) |
Milosz Wasilewski | b504541 | 2016-12-07 11:27:10 +0000 | [diff] [blame] | 359 | testplan_file.close() |
Milosz Wasilewski | 923ed1b | 2020-08-10 16:15:46 +0100 | [diff] [blame] | 360 | if args.pdf is not None: |
| 361 | pdfkit.from_file(tp_file_name, args.pdf) |
Benjamin Copeland | 15d743e | 2021-02-22 08:35:10 +0000 | [diff] [blame^] | 362 | |
| 363 | |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 364 | # go through requiremets and for each test: |
| 365 | # - if file exists render test as separate html file |
| 366 | # - if file is missing, indicate missing test (red) |
| 367 | # render test plan with links to test files |
| 368 | # add option to render as single file (for pdf generation) |
| 369 | |
Milosz Wasilewski | 6015206 | 2020-03-02 18:53:29 +0000 | [diff] [blame] | 370 | |
Milosz Wasilewski | f5ccdbd | 2016-10-25 18:49:20 +0100 | [diff] [blame] | 371 | if __name__ == "__main__": |
| 372 | main() |