Skip to content

Commit

Permalink
readability improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelbaker-cisa committed Aug 1, 2024
1 parent d6bdb8c commit 3bc5eab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/run_smoke_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ jobs:
fail-fast: false
matrix:
os: [windows-latest, macos-latest]
python-version: [3.9, 3.12]
python-version: ["3.8.4", "3.12"]
runs-on: ${{ matrix.os }}
environment: Development
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Python
- name: Setup Python v${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: "requirements.txt"

- name: Setup Dependencies (Windows)
- name: Setup Dependencies (${{ matrix.os }})
if: ${{ matrix.os == 'windows-latest' }}
uses: ./.github/actions/setup-dependencies-windows
with:
operating-system: "windows"
opa-version: "0.60.0"

- name: Setup Dependencies (macOS)
- name: Setup Dependencies (${{ matrix.os }})
if: ${{ matrix.os == 'macos-latest' }}
uses: ./.github/actions/setup-dependencies-macos
with:
Expand All @@ -58,5 +58,5 @@ jobs:
name: "credentials.json"
json: ${{ secrets.GWS_GITHUB_AUTOMATION_CREDS }}

- name: Execute ScubaGoggles and check for correct output
- name: Run ScubaGoggles and check for correct output
run: pytest -s ./Testing/Functional/SmokeTests/ --subjectemail="${{ secrets.GWS_SUBJECT_EMAIL }}" --domain="${{ secrets.GWS_DOMAIN }}"
11 changes: 7 additions & 4 deletions Testing/Functional/SmokeTests/smoke_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""
smoke_test.py is a test script to verify `scubagoggles gws`
generates the correct outputs (i.e., directories, files).
smoke_test.py is a test script to verify `scubagoggles gws`.
It checks for the following cases:
- Generate the correct output files (BaselineReports.html, ScubaResults.json, etc)
- Check the content of html files, verify href attributes are correct, etc
"""

import pytest
Expand All @@ -23,8 +26,8 @@ def test_scubagoggles_output(self, subjectemail):
subprocess.run(command, shell=True)

output_path: str = get_output_path()
contents: list[str] = verify_output_type(output_path, [])
verify_all_outputs_exist(contents)
output: list[str] = verify_output_type(output_path, [])
verify_all_outputs_exist(output)
except (OSError, ValueError, Exception) as e:
pytest.fail(f"An error occurred, {e}")

Expand Down
21 changes: 11 additions & 10 deletions Testing/Functional/SmokeTests/smoke_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,30 @@ def prepend_file_protocol(path: str) -> str:
path = "file://" + path
return path

def verify_output_type(output_path: str, contents: list[str]) -> list[str]:
def verify_output_type(output_path: str, output: list[str]) -> list[str]:
entries: list[str] = os.listdir(output_path)
for entry in entries:
contents.append(entry)
output.append(entry)
# Check if entry is a valid directory or file
# If a valid directory, then recurse
child_path: str = os.path.join(output_path, entry)
if os.path.isdir(child_path):
assert True
verify_output_type(child_path, contents)
verify_output_type(child_path, output)
elif os.path.isfile(child_path):
# Check for valid json
if child_path.endswith(".json"):
try:
with open(child_path) as jsonfile:
json.load(jsonfile)
except ValueError as e:
pytest.fail(f"Invalid json, ${e}")
raise ValueError(f"{child_path} contains invalid json, {e}")
assert True
else:
raise OSError(f"Entry is not a directory or file (symlink, etc.)")
return contents
return output

required_contents = [
required_entries = [
"BaselineReports.html",
"IndividualReports",
"ScubaResults.json",
Expand All @@ -54,9 +55,9 @@ def verify_output_type(output_path: str, contents: list[str]) -> list[str]:
"triangle-exclamation-solid.svg"
]

def verify_all_outputs_exist(contents: list[str]):
for required_content in required_contents:
if required_content in contents:
def verify_all_outputs_exist(output: list[str]):
for required_entry in required_entries:
if required_entry in output:
assert True
else:
raise ValueError(f"{required_content} was not found in the generated report")
raise ValueError(f"{required_entry} was not found in the generated report")

0 comments on commit 3bc5eab

Please sign in to comment.