Files
last30days-skill/tests/test_polymarket_disambiguation.py
T
Yong-yuan-X e74b0e1e93 tests: centralize script path setup in conftest.py
Add a pytest-discovered tests/conftest.py for the last30days scripts path and
remove duplicate per-file sys.path.insert boilerplate from tests.

Normalize affected imports to rely on the shared scripts path and remove the
now-unneeded E402 suppressions.
2026-05-21 00:04:03 +08:00

68 lines
2.3 KiB
Python

"""Tests for --polymarket-keywords filter and filter_items_against_keywords."""
from __future__ import annotations
import unittest
from lib import polymarket
def _item(title: str) -> dict:
return {"title": title}
class FilterItemsAgainstKeywordsTests(unittest.TestCase):
def test_no_keywords_returns_all(self):
items = [_item("NBA Finals"), _item("Glasgow Warriors")]
out = polymarket.filter_items_against_keywords(items, [])
self.assertEqual(out, items)
def test_single_keyword_filters(self):
items = [
_item("Golden State Warriors win title"),
_item("Glasgow Warriors rugby"),
_item("Honor of Kings: Rogue Warriors"),
]
out = polymarket.filter_items_against_keywords(items, ["golden"])
self.assertEqual(len(out), 1)
self.assertIn("Golden State", out[0]["title"])
def test_multiple_keywords_any_match(self):
items = [
_item("NBA Finals: Warriors vs Celtics"),
_item("Glasgow rugby"),
_item("GSW schedule"),
]
out = polymarket.filter_items_against_keywords(items, ["nba", "gsw"])
self.assertEqual(len(out), 2)
def test_case_insensitive_match(self):
items = [_item("Golden State Warriors"), _item("GLASGOW WARRIORS")]
out = polymarket.filter_items_against_keywords(items, ["GOLDEN"])
self.assertEqual(len(out), 1)
self.assertIn("Golden State", out[0]["title"])
def test_empty_keyword_strings_ignored(self):
items = [_item("NBA Finals")]
out = polymarket.filter_items_against_keywords(items, ["", " ", ""])
# All keywords are empty → treated as no filter
self.assertEqual(out, items)
def test_sourceitem_like_objects(self):
class _SI:
def __init__(self, t):
self.title = t
items = [_SI("NBA Finals"), _SI("Glasgow Warriors rugby")]
out = polymarket.filter_items_against_keywords(items, ["nba"])
self.assertEqual(len(out), 1)
self.assertEqual(out[0].title, "NBA Finals")
def test_no_match_returns_empty(self):
items = [_item("Glasgow Warriors"), _item("Rogue Warriors")]
out = polymarket.filter_items_against_keywords(items, ["nba", "gsw"])
self.assertEqual(out, [])
if __name__ == "__main__":
unittest.main()