Skip to content

Commit

Permalink
simplify test functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaiahWren committed Jan 21, 2025
1 parent 192e6c3 commit 08d868e
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions metrics_utility/test/ccspv_reports/test_CCSPv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,38 +74,37 @@ def test_command():

assert result.returncode == 0

for sheet_name, expected_columns in EXPECTED_SHEETS.items():
validate_sheet_columns(sheet_name=sheet_name, expected_columns=expected_columns)
validate_sheet_columns()
validate_sheet_tab_names()
cleanup()

def validate_sheet_columns(sheet_name, expected_columns):
def validate_sheet_tab_names():
"""Test the sheet names in the Excel file."""
excel_data = pd.ExcelFile(file_path)
assert excel_data.sheet_names == list(
EXPECTED_SHEETS.keys()
), "Sheet names do not match."

def validate_sheet_columns():
"""Test the column names for each sheet."""

def normalize_column(col):
return col.strip().replace("\n", " ").lower()

df = pd.read_excel(file_path, sheet_name=sheet_name)
actual_columns = [normalize_column(col) for col in df.columns.tolist()]
expected_columns = [normalize_column(col) for col in expected_columns]

if actual_columns != expected_columns:
print(f"Mismatch for sheet: {sheet_name}")
print(f"Actual columns (normalized): {actual_columns}")
print(f"Expected columns (normalized): {expected_columns}")
print(f"Mismatched columns: {set(actual_columns) ^ set(expected_columns)}")
for sheet_name, expected_columns in EXPECTED_SHEETS.items():
df = pd.read_excel(file_path, sheet_name=sheet_name)
actual_columns = [normalize_column(col) for col in df.columns.tolist()]
expected_columns = [normalize_column(col) for col in expected_columns]

assert (
actual_columns == expected_columns
), f"Column names do not match for sheet: {sheet_name}"
if actual_columns != expected_columns:
print(f"Mismatch for sheet: {sheet_name}")
print(f"Actual columns (formatted): {actual_columns}")
print(f"Expected columns (formatted): {expected_columns}")

assert (
actual_columns == expected_columns
), f"Column names do not match for sheet: {sheet_name}"

def validate_sheet_tab_names():
"""Test the sheet names in the Excel file."""
excel_data = pd.ExcelFile(file_path)
assert excel_data.sheet_names == list(
EXPECTED_SHEETS.keys()
), "Sheet names do not match."

def cleanup():
if os.path.exists(file_path):
Expand Down

0 comments on commit 08d868e

Please sign in to comment.