Mesa (master): ci: ArgumentParser receives the args from the main parameters

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon May 18 17:50:55 UTC 2020


Module: Mesa
Branch: master
Commit: 37621da7b144a6021a8e3962352ad3561e82f560
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=37621da7b144a6021a8e3962352ad3561e82f560

Author: Pablo Saavedra <psaavedra at igalia.com>
Date:   Tue May  5 15:08:04 2020 +0200

ci: ArgumentParser receives the args from the main parameters

Change the main function to receive the args parameter from
sys.argv[1:]. The args parameter will be passed to the
ArgumentParser.parse_args() function as argument.

This change provides an easier  main() function signature to use
with pythonic testsuites.

Signed-off-by: Pablo Saavedra <psaavedra at igalia.com>
Reviewed-by: Alexandros Frantzis <alexandros.frantzis at collabora.com>
Reviewed-by: Andres Gomez <agomez at igalia.com>
Reviewed-by: Rohan Garg <rohan.garg at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4916>

---

 .gitlab-ci/tracie/tracie.py | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/.gitlab-ci/tracie/tracie.py b/.gitlab-ci/tracie/tracie.py
index d1a1c563021..d2c0d7355d9 100644
--- a/.gitlab-ci/tracie/tracie.py
+++ b/.gitlab-ci/tracie/tracie.py
@@ -137,16 +137,9 @@ def gitlab_check_trace(project_url, repo_commit, device_name, trace, expectation
 
     return ok, result
 
-def main():
-    parser = argparse.ArgumentParser()
-    parser.add_argument('--file', required=True,
-                        help='the name of the traces.yml file listing traces and their checksums for each device')
-    parser.add_argument('--device-name', required=True,
-                        help="the name of the graphics device used to replay traces")
-
-    args = parser.parse_args()
+def run(filename, device_name):
 
-    with open(args.file, 'r') as f:
+    with open(filename, 'r') as f:
         y = yaml.safe_load(f)
 
     if "traces-db" in y:
@@ -161,8 +154,10 @@ def main():
     results = {}
     for trace in traces:
         for expectation in trace['expectations']:
-            if expectation['device'] == args.device_name:
-                ok, result = gitlab_check_trace(project_url, commit_id, args.device_name, trace, expectation)
+            if expectation['device'] == device_name:
+                ok, result = gitlab_check_trace(project_url, commit_id,
+                                                device_name, trace,
+                                                expectation)
                 all_ok = all_ok and ok
                 results.update(result)
 
@@ -170,8 +165,18 @@ def main():
     with open(os.path.join(RESULTS_PATH, 'results.yml'), 'w') as f:
         yaml.safe_dump(results, f, default_flow_style=False)
 
+    return all_ok
 
-    sys.exit(0 if all_ok else 1)
+def main(args):
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--file', required=True,
+                        help='the name of the traces.yml file listing traces and their checksums for each device')
+    parser.add_argument('--device-name', required=True,
+                        help="the name of the graphics device used to replay traces")
+
+    args = parser.parse_args(args)
+    return run(args.file, args.device_name)
 
 if __name__ == "__main__":
-    main()
+    all_ok = main(sys.argv[1:])
+    sys.exit(0 if all_ok else 1)



More information about the mesa-commit mailing list