Add test support for xlsx file (not tested)

This commit is contained in:
2025-04-25 10:49:51 -04:00
parent 86dfe349e8
commit 6672536508

View File

@@ -1,7 +1,7 @@
import unittest
from pathlib import Path
# from convert_to_sportspress
from src.utils.common import validate_csv_header, normalize_header_key, read_and_normalize_csv, parse_score, is_visitor_home_order_reversed, import_gamebygame, aggregate_teams
from src.utils.common import validate_csv_header, normalize_header_key, read_and_normalize_csv_or_xlsx, parse_score, is_visitor_home_order_reversed, import_gamebygame, aggregate_teams
from src.utils.normalize import normalize_value, normalize_header_key, load_config
import toml
@@ -25,11 +25,11 @@ class TestConvertToSportsPress(unittest.TestCase):
def test_read_csv(self):
# Assuming that the CSV file has a valid header
with self.subTest("Read CSV data"):
data = read_and_normalize_csv(self.test_csv_path_2009)
data = read_and_normalize_csv_or_xlsx(self.test_csv_path_2009)
self.assertIsInstance(data, list)
self.assertTrue(all(isinstance(row, dict) for row in data))
with self.subTest("Normalized keys"):
normalized_data = read_and_normalize_csv(self.test_csv_path_2009)
normalized_data = read_and_normalize_csv_or_xlsx(self.test_csv_path_2009)
self.assertTrue(all("visitor" in row.keys() and "results" in row.keys() for row in normalized_data))
def test_parse_score_visitor_first(self):
@@ -117,7 +117,7 @@ class TestConvertToSportsPress(unittest.TestCase):
def test_process_data(self):
# Assuming that the CSV file has a valid header and read_csv is good
data = read_and_normalize_csv(self.test_csv_path_2009)
data = read_and_normalize_csv_or_xlsx(self.test_csv_path_2009)
processed_data = import_gamebygame(data)
aggregate_team_data = aggregate_teams(processed_data)
expected_result = [