diff mbox series

[autobuilder,v2,4/4] scripts/send_qa_email.py: add unit tests on previous version computation

Message ID 20230123123111.37665-5-alexis.lothore@bootlin.com
State New
Headers show
Series generate regression reports against proper releases | expand

Commit Message

Alexis Lothoré Jan. 23, 2023, 12:31 p.m. UTC
The "previous version" computation bring many edge cases depending on the
version under release. Add a basic test suite to validate currently implemented
computation strategy and to prevent mistakes when ediiting it in the future

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
 scripts/test_send_qa_email.py | 57 +++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100755 scripts/test_send_qa_email.py
diff mbox series

Patch

diff --git a/scripts/test_send_qa_email.py b/scripts/test_send_qa_email.py
new file mode 100755
index 0000000..6822451
--- /dev/null
+++ b/scripts/test_send_qa_email.py
@@ -0,0 +1,57 @@ 
+#!/usr/bin/env python3
+"""
+Test suite for send_qa_email.py
+
+The suite needs a valid poky clone to run since it will
+fetch and return revisions from remote repository. To run the suite,
+set POKY_PATH environment variable accordingly:
+`POKY_PATH=~/src/poky ./scripts/test_send_qa_email.py`
+"""
+import os
+import sys
+import unittest
+import send_qa_email
+
+
+class TestVersion(unittest.TestCase):
+    test_data_get_version = [
+        {"input": {"version": "4.1.2"}, "expected": "yocto-4.1.1"},
+        {"input": {"version": "4.1"}, "expected": "yocto-4.0"},
+        {"input": {"version": "4.1.1"}, "expected": "yocto-4.1"},
+        {"input": {"version": "4.1_M2"}, "expected": "4.1_M1"},
+        {"input": {"version": "4.1_M1"}, "expected": "yocto-4.0"},
+        {"input": {"version": "4.1.1.rc1"}, "expected": "yocto-4.1"},
+        {"input": {"version": "4.1.2.rc1"}, "expected": "yocto-4.1.1"},
+        {"input": {"version": "4.1_M3.rc1"}, "expected": "4.1_M2"},
+        {"input": {"version": "4.1_M3.rc4"}, "expected": "4.1_M2"},
+        {"input": {"version": "4.1_M1.rc1"}, "expected": "yocto-4.0"},
+        {"input": {"version": "4.1_M1.rc4"}, "expected": "yocto-4.0"},
+        {"input": {"version": "4.1.rc4"}, "expected": "yocto-4.0"},
+        {"input": {"version": "20230120-3"}, "expected": "origin/master"},
+    ]
+
+    test_data_get_sha1 = [
+        {"input": "yocto-4.0", "expected": "00cfdde791a0176c134f31e5a09eff725e75b905"},
+        {"input": "4.1_M1", "expected": "95066dde6861ee08fdb505ab3e0422156cc24fae"},
+    ]
+
+    def test_versions(self):
+        for data in self.test_data_get_version:
+            test_name = data["input"]["version"]
+            with self.subTest(f"Test {test_name} previous tag"):
+                self.assertEqual(send_qa_email.get_previous_tag(os.environ.get(
+                    "POKY_PATH"), data["input"]["version"]), data["expected"])
+
+    def test_get_sha1(self):
+        for data in self.test_data_get_sha1:
+            test_name = data["input"]
+            with self.subTest(f"Test SHA1 from {test_name}"):
+                self.assertEqual(send_qa_email.get_sha1(os.environ.get(
+                    "POKY_PATH"), data["input"]), data["expected"])
+
+
+if __name__ == '__main__':
+    if os.environ.get("POKY_PATH") is None:
+        print("Please set POKY_PATH to proper poky clone location before running tests")
+        sys.exit(1)
+    unittest.main()