Remove unnecessary check for pytest.skip
[vvp/validation-scripts.git] / checks.py
index b43d6c7..9f8740a 100644 (file)
--- a/checks.py
+++ b/checks.py
@@ -40,7 +40,7 @@ import csv
 import io
 import json
 import os
 import io
 import json
 import os
-import subprocess  #nosec
+import subprocess  # nosec
 import sys
 
 import pytest
 import sys
 
 import pytest
@@ -52,6 +52,16 @@ THIS_DIR = os.path.dirname(os.path.abspath(__file__))
 CURRENT_NEEDS_PATH = os.path.join(THIS_DIR, "ice_validator/heat_requirements.json")
 
 
 CURRENT_NEEDS_PATH = os.path.join(THIS_DIR, "ice_validator/heat_requirements.json")
 
 
+def run_pytest(*args, msg="pytest failed"):
+    original_dir = os.getcwd()
+    try:
+        os.chdir(os.path.join(THIS_DIR, "ice_validator"))
+        if pytest.main(list(args)) != 0:
+            return [msg]
+    finally:
+        os.chdir(original_dir)
+
+
 class Traceability:
 
     PATH = os.path.join(THIS_DIR, "ice_validator/output/traceability.csv")
 class Traceability:
 
     PATH = os.path.join(THIS_DIR, "ice_validator/output/traceability.csv")
@@ -72,7 +82,7 @@ class Traceability:
         """
         testable_mappings = [m for m in self.mappings if m[self.IS_TESTABLE] == "True"]
         return [
         """
         testable_mappings = [m for m in self.mappings if m[self.IS_TESTABLE] == "True"]
         return [
-            f"Missing test for {m[self.REQ_ID]}"
+            f"WARN: Missing test for {m[self.REQ_ID]}"
             for m in testable_mappings
             if not m[self.TEST_NAME]
         ]
             for m in testable_mappings
             if not m[self.TEST_NAME]
         ]
@@ -127,41 +137,41 @@ def check_requirements_up_to_date():
     """
     Checks if the requirements file packaged with VVP has meaningful differences
     to the requirements file published from VNFRQTS.
     """
     Checks if the requirements file packaged with VVP has meaningful differences
     to the requirements file published from VNFRQTS.
-    :return: list of errors found
     """
     """
-    msg = ["heat_requirements.json is out-of-date. Run update_reqs.py to update."]
+    msg = "WARN: heat_requirements.json is out-of-date. Run update_reqs.py to update."
     latest_needs = json.load(get_requirements())
     with open(CURRENT_NEEDS_PATH, "r") as f:
         current_needs = json.load(f)
     latest_reqs = select_items(in_scope, current_version(latest_needs))
     current_reqs = select_items(in_scope, current_version(current_needs))
     if set(latest_reqs.keys()) != set(current_reqs.keys()):
     latest_needs = json.load(get_requirements())
     with open(CURRENT_NEEDS_PATH, "r") as f:
         current_needs = json.load(f)
     latest_reqs = select_items(in_scope, current_version(latest_needs))
     current_reqs = select_items(in_scope, current_version(current_needs))
     if set(latest_reqs.keys()) != set(current_reqs.keys()):
-        return msg
-    if not all(
+        print(msg)
+    elif not all(
         latest["description"] == current_reqs[r_id]["description"]
         for r_id, latest in latest_reqs.items()
     ):
         latest["description"] == current_reqs[r_id]["description"]
         for r_id, latest in latest_reqs.items()
     ):
-        return msg
-    return None
+        print(msg)
+
+
+def check_app_tests_pass():
+    return run_pytest(
+        "tests",
+        "--self-test",
+        msg="app_tests failed. Run pytest app_tests and fix errors.",
+    )
 
 
 def check_self_test_pass():
 
 
 def check_self_test_pass():
-    """
-    Run pytest self-test and ensure it passes
-    :return:
-    """
-    original_dir = os.getcwd()
-    try:
-        os.chdir(os.path.join(THIS_DIR, "ice_validator"))
-        if pytest.main(["tests", "--self-test"]) != 0:
-            return ["VVP self-test failed. Run pytest --self-test and fix errors."]
-    finally:
-        os.chdir(original_dir)
+    return run_pytest(
+        "tests",
+        "--self-test",
+        msg="self-test failed. Run pytest --self-test and fix errors.",
+    )
 
 
 def check_testable_requirements_are_mapped():
     tracing = Traceability()
 
 
 def check_testable_requirements_are_mapped():
     tracing = Traceability()
-    return tracing.unmapped_requirement_errors()
+    print("\n".join(tracing.unmapped_requirement_errors()))
 
 
 def check_non_testable_requirements_are_not_mapped():
 
 
 def check_non_testable_requirements_are_not_mapped():
@@ -180,21 +190,22 @@ def check_flake8_passes():
 
 
 def check_bandit_passes():
 
 
 def check_bandit_passes():
-    result = subprocess.run(                                            #nosec
-        ["bandit", "-c", "bandit.yaml", "-r", ".", "-x", "./.tox/**"],  #nosec
-        encoding="utf-8",                                               #nosec
-        stdout=subprocess.PIPE,                                         #nosec
-        stderr=subprocess.PIPE,                                         #nosec
-    )                                                                   #nosec
+    result = subprocess.run(  nosec
+        ["bandit", "-c", "bandit.yaml", "-r", ".", "-x", "./.tox/**"],  # nosec
+        encoding="utf-8",  nosec
+        stdout=subprocess.PIPE,  nosec
+        stderr=subprocess.PIPE,  nosec
+    )  nosec
     msgs = result.stdout.split("\n") if result.returncode != 0 else []
     msgs = result.stdout.split("\n") if result.returncode != 0 else []
-    return ["bandit errors detected:"] + [f"  {e}" for e in msgs] if msgs else []
+    return (
+        ["bandit errors detected:"] + ["  {}".format(e) for e in msgs] if msgs else []
+    )
 
 
 if __name__ == "__main__":
 
 
 if __name__ == "__main__":
+
     checks = [
         check_self_test_pass,
     checks = [
         check_self_test_pass,
-        check_requirements_up_to_date,
-        check_testable_requirements_are_mapped,
         check_non_testable_requirements_are_not_mapped,
         check_flake8_passes,
         check_bandit_passes,
         check_non_testable_requirements_are_not_mapped,
         check_flake8_passes,
         check_bandit_passes,
@@ -202,4 +213,6 @@ if __name__ == "__main__":
     results = [check() for check in checks]
     errors = "\n".join("\n".join(msg) for msg in results if msg)
     print(errors or "Everything looks good!")
     results = [check() for check in checks]
     errors = "\n".join("\n".join(msg) for msg in results if msg)
     print(errors or "Everything looks good!")
+    check_requirements_up_to_date()
+    check_testable_requirements_are_mapped()
     sys.exit(1 if errors else 0)
     sys.exit(1 if errors else 0)