Sobes.tech
Junior — Senior

Test set for CSV data sum comparison function

livecode

Task condition

Create several unit tests for the check_data function, which reads a CSV file, calculates the sum of all numbers, and compares it with a given value.

def check_data(file_name: str, target_sum: int = 10) -> bool | NoReturn:
    file_path = Path.join(settings.BASE_PATH, file_name)
    if not file_path.exists():
        raise NoFileError

    df = pd.read_csv(file_path, sep=",", header=None)
    if df.values.sum() == target_sum:
        return True
    return False

Tests should verify the correctness of the function when the file exists, when it does not exist, and with different sum values.