Skip to content

Commit

Permalink
Fix type related errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaflight committed Aug 3, 2024
1 parent 277eaa9 commit a945b08
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions tests/history/coursereg_history/test_cleaned_csvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import os
import re
import unittest
from typing import Callable, Iterator, List
from collections.abc import Iterator
from typing import Callable


def is_int(val: str) -> bool:
Expand All @@ -13,7 +14,7 @@ def is_int(val: str) -> bool:
return False


def has_good_header(reader: Iterator[List[str]], file_path: str) -> None:
def has_good_header(reader: Iterator[list[str]], file_path: str) -> None:
header_row = next(reader)

expected_header = ["Faculty", "Department", "Code",
Expand All @@ -28,21 +29,21 @@ def has_good_header(reader: Iterator[List[str]], file_path: str) -> None:
f"{header_row} has incorrect column labels.")


def has_good_length(reader: Iterator[List[str]], file_path: str) -> None:
def has_good_length(reader: Iterator[list[str]], file_path: str) -> None:
for row in reader:
if len(row) != 13:
raise ValueError(f"In {file_path}:"
f"{row} has too few/many entries.")


def has_entries(reader: Iterator[List[str]], file_path: str) -> None:
def has_entries(reader: Iterator[list[str]], file_path: str) -> None:
for row in reader:
if any(item == "" for item in row):
raise ValueError(f"In {file_path}:"
f"{row} has empty entries.")


def has_valid_course_codes(reader: Iterator[List[str]],
def has_valid_course_codes(reader: Iterator[list[str]],
file_path: str) -> None:
# Valid codes: LL5009GRSI, GESS1025
course_code_pattern = r"^[A-Z]{2,4}\d{4}[A-Z]{0,4}$"
Expand All @@ -57,7 +58,7 @@ def has_valid_course_codes(reader: Iterator[List[str]],
f"{course_code} did not match the regex.")


def has_number_data(reader: Iterator[List[str]], file_path: str) -> None:
def has_number_data(reader: Iterator[list[str]], file_path: str) -> None:
# Skip the header row
next(reader)

Expand All @@ -67,7 +68,7 @@ def has_number_data(reader: Iterator[List[str]], file_path: str) -> None:
f"{row[5:]} did not have number data.")


def check_all_csvs(check_func: Callable[[Iterator[List[str]], str],
def check_all_csvs(check_func: Callable[[Iterator[list[str]], str],
None]) -> bool:
current_file_directory = os.path.dirname(os.path.abspath(__file__))
csv_directory = os.path.abspath(
Expand Down

0 comments on commit a945b08

Please sign in to comment.