From ab06197da1860bc406b5ac5ff2e07cf53642d9ba Mon Sep 17 00:00:00 2001 From: Mitchel Baker Date: Fri, 26 Jul 2024 19:23:48 +0000 Subject: [PATCH] refactor try/catch handlers into smoke test methods; remove ProviderSettingsExport and switch to ScubaResults.json --- .github/workflows/run_smoke_test.yml | 12 ++--- Testing/Functional/SmokeTests/smoke_test.py | 45 ++++++++++-------- .../Functional/SmokeTests/smoke_test_utils.py | 47 ++++++++----------- 3 files changed, 49 insertions(+), 55 deletions(-) diff --git a/.github/workflows/run_smoke_test.yml b/.github/workflows/run_smoke_test.yml index 319fea95..b5cb3995 100644 --- a/.github/workflows/run_smoke_test.yml +++ b/.github/workflows/run_smoke_test.yml @@ -42,22 +42,18 @@ jobs: python -m venv .venv .venv\Scripts\activate - - name: Install dependencies + - name: Install project dependencies and OPA run: | python -m pip install . pip install -r requirements.txt pip install pytest pip uninstall numpy pip install numpy==1.26.4 - - - name: Create credentials.json for service account - run: Set-Content -Path credentials.json -Value $env:GWS_GITHUB_AUTOMATION_CREDS - - - name: Download OPA executable - run: python download_opa.py -v 0.60.0 -os windows + python download_opa.py -v 0.60.0 -os windows - name: Execute ScubaGoggles and check for correct output run: | - echo "In step to execute ScubaGoggles smoke test" pip show scubagoggles + # Setup credentials for service account + Set-Content -Path credentials.json -Value $env:GWS_GITHUB_AUTOMATION_CREDS pytest -s ./Testing/Functional/SmokeTests/ --subjectemail="$env:GWS_SUBJECT_EMAIL" \ No newline at end of file diff --git a/Testing/Functional/SmokeTests/smoke_test.py b/Testing/Functional/SmokeTests/smoke_test.py index 1446cd20..99354261 100644 --- a/Testing/Functional/SmokeTests/smoke_test.py +++ b/Testing/Functional/SmokeTests/smoke_test.py @@ -1,6 +1,6 @@ """ -run_smoke_test.py is a test script to verify `scubagoggles gws` -outputs (i.e., files) are generated. +smoke_test.py is a test script to verify `scubagoggles gws` +generates the correct outputs (i.e., directories, files). """ import pytest @@ -11,27 +11,32 @@ class SmokeTest: def test_venv_creation(self): - result = subprocess.run(["ls", ".venv"], shell=True, capture_output=True, text=True) - if "Scripts" in result.stdout: - assert True - else: - assert False, f"Scripts was not found in the virtual environment" + try: + result = subprocess.run(["ls", ".venv"], shell=True, capture_output=True, text=True) + if "Scripts" in result.stdout: + assert True + else: + assert False, f"Scripts was not found in the virtual environment" + except Exception as e: + pytest.fail(f"An error occurred, {e}") def test_scubagoggles(self, subjectemail): - command = f"scubagoggles gws --subjectemail {subjectemail} --quiet" - subprocess.run(command, shell=True) - - prefix = "GWSBaselineConformance" - directories = [d for d in os.listdir() if os.path.isdir(d) and d.startswith(prefix)] - directories.sort(key=lambda d: os.path.getctime(d), reverse=True) - print(directories) - - cwd = os.getcwd() - output_path = os.path.join(cwd, directories[0]) - print(cwd, directories[0]) - contents = verify_output_type(output_path, []) - verify_all_outputs_exist(contents) + try: + command = f"scubagoggles gws --subjectemail {subjectemail} --quiet" + subprocess.run(command, shell=True) + + prefix = "GWSBaselineConformance" + directories = [d for d in os.listdir() if os.path.isdir(d) and d.startswith(prefix)] + directories.sort(key=lambda d: os.path.getctime(d), reverse=True) + + cwd = os.getcwd() + output_path = os.path.join(cwd, directories[0]) + contents = verify_output_type(output_path, []) + print(contents) + verify_all_outputs_exist(contents) + except Exception as e: + pytest.fail(f"An error occurred, {e}") diff --git a/Testing/Functional/SmokeTests/smoke_test_utils.py b/Testing/Functional/SmokeTests/smoke_test_utils.py index b80f8f79..2bea85d0 100644 --- a/Testing/Functional/SmokeTests/smoke_test_utils.py +++ b/Testing/Functional/SmokeTests/smoke_test_utils.py @@ -3,7 +3,7 @@ required_contents = [ "BaselineReports.html", "IndividualReports", - "ProviderSettingsExport.json", + "ScubaResults.json", "TestResults.json", "images", "CalendarReport.html", @@ -21,33 +21,26 @@ ] def verify_all_outputs_exist(contents): - try: - for required_content in required_contents: - if required_content in contents: - assert True - else: - assert False, f"{required_content} was not found in the generated report" - except Exception as e: - assert False, f"An error occurred, {e}" + for required_content in required_contents: + if required_content in contents: + assert True + else: + assert False, f"{required_content} was not found in the generated report" def verify_output_type(output_path, contents): - try: - entries = os.listdir(output_path) - for entry in entries: - contents.append(entry) + entries = os.listdir(output_path) - # Check if entry is a valid directory or file - child_path = os.path.join(output_path, entry) - if os.path.isdir(child_path): - assert True - verify_output_type(child_path, contents) - elif os.path.isfile(child_path): - assert True - else: - assert False, f"Entry is not a directory or file (symlink, etc.)" + for entry in entries: + contents.append(entry) - return contents - except FileNotFoundError: - assert False, f"The directory {output_path} does not exist" - except Exception as e: - assert False, f"An error occurred, {e}" \ No newline at end of file + # Check if entry is a valid directory or file + child_path = os.path.join(output_path, entry) + if os.path.isdir(child_path): + assert True + verify_output_type(child_path, contents) + elif os.path.isfile(child_path): + assert True + else: + assert False, f"Entry is not a directory or file (symlink, etc.)" + + return contents \ No newline at end of file