From a945b084f056e02286cd7ebe62adba4a62c66aa3 Mon Sep 17 00:00:00 2001 From: lunaflight Date: Sun, 4 Aug 2024 01:03:07 +0800 Subject: [PATCH] Fix type related errors --- .../coursereg_history/test_cleaned_csvs.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/history/coursereg_history/test_cleaned_csvs.py b/tests/history/coursereg_history/test_cleaned_csvs.py index 7d0a9ee5..7814922d 100644 --- a/tests/history/coursereg_history/test_cleaned_csvs.py +++ b/tests/history/coursereg_history/test_cleaned_csvs.py @@ -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: @@ -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", @@ -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}$" @@ -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) @@ -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(