X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=checks.py;h=4e5fb13934fcee346582b2593c948061df61d59c;hb=1bc097aa957e560147b4d9af49d25e69a6692702;hp=b43d6c76f8949bd2686c3d220591a79b214d6f70;hpb=9da2967e6c91d12359896ef3906c47e51d030959;p=vvp%2Fvalidation-scripts.git diff --git a/checks.py b/checks.py index b43d6c7..4e5fb13 100644 --- a/checks.py +++ b/checks.py @@ -40,7 +40,7 @@ import csv import io import json import os -import subprocess #nosec +import subprocess # nosec 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") +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") @@ -145,18 +155,20 @@ def check_requirements_up_to_date(): return None +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(): - """ - 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(): @@ -180,12 +192,12 @@ def check_flake8_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 [] return ["bandit errors detected:"] + [f" {e}" for e in msgs] if msgs else []