import csv from io import StringIO from pathlib import Path import unittest from unittest.mock import patch from calculate_interest_index import calculate, variants class ValueListTests(unittest.TestCase): def test_variant_extraction_keeps_shiny_separate_and_normalizes_case(self): self.assertEqual( variants("ROGER Evo | Shiny Roger Evo | Roger Unevo"), {"Roger Evo", "Shiny Roger Evo", "Roger Unevo"}, ) self.assertEqual( variants("my Aizen Evo for Homura Evo", request=True), {"Homura Evo"}, ) def test_counts_authors_once_and_excludes_nlf(self): stream = StringIO(newline="") writer = csv.DictWriter(stream, fieldnames=[ "offer", "lf", "mlf", "nlf", "author_hash" ]) writer.writeheader() for i in range(5): writer.writerow({"offer": "2 Aizen Evo | Aizen Evo", "author_hash": f"seller{i}"}) writer.writerow({"offer": "Aizen Evo", "author_hash": f"seller{i}"}) writer.writerow({"lf": "Aizen Evo", "nlf": "Homura Evo", "author_hash": f"buyer{i}"}) stream.seek(0) with patch.object(Path, "open", return_value=stream): path = Path("fixture.csv") result, summary = calculate(path, minimum_mentions=10) self.assertEqual(summary["source_rows"], 15) self.assertEqual(result[0]["unit_variant"], "Aizen Evo") self.assertEqual((result[0]["offered_by"], result[0]["requested_by"]), (5, 5)) self.assertEqual(len(result), 1) if __name__ == "__main__": unittest.main()