| 1 | """Polymarket names from five live runs on 2026-11-10. |
| 2 | |
| 3 | Footer lines those runs printed: |
| 4 | |
| 5 | Anthropic's market cap be between $2.0T 42%, Anthropic IPO 97%, |
| 6 | Anthropic's valuation hit (HIGH) $3.0T 70% |
| 7 | Waymo operate in 12-15 cities on 79%, Waymo launch in Denver, CO by 74% |
| 8 | Jensen Huang announced resignation or removal by December 31, 2027 38%, |
| 9 | Jensen Huang divorce by March 31, 2027 18%, |
| 10 | WTT Contender: Anders Lind vs Youzheng: Youzheng Huang 50% |
| 11 | |
| 12 | and evidence lines in the saved files: |
| 13 | |
| 14 | Odds: Waymo: 79% | Waymo: 12% | Waymo: 4.6% |
| 15 | Odds: Anthropic's market cap: 42% | Anthropic's market cap: 24% | ... |
| 16 | |
| 17 | The events below are those events as the Gamma API returns them: titles, |
| 18 | questions, sub-market labels (``groupItemTitle``) and end dates as served, |
| 19 | prices as the saved files hold them, cut to a few sub-markets each. |
| 20 | """ |
| 21 | |
| 22 | import pytest |
| 23 | |
| 24 | from lib import normalize, polymarket, render |
| 25 | |
| 26 | TODAY = "2026-11-10" |
| 27 | |
| 28 | |
| 29 | @pytest.fixture(autouse=True) |
| 30 | def _fixed_today(monkeypatch): |
| 31 | monkeypatch.setattr(polymarket, "_today", lambda: TODAY, raising=False) |
| 32 | |
| 33 | |
| 34 | def _market(question, label, yes, volume, end="2027-01-01"): |
| 35 | return { |
| 36 | "question": question, "groupItemTitle": label, |
| 37 | "outcomes": '["Yes", "No"]', "outcomePrices": f'["{yes}", "{round(1 - yes, 4)}"]', |
| 38 | "volume": volume, "liquidity": 5000, "endDate": f"{end}T00:00:00Z", |
| 39 | "active": True, "closed": False, |
| 40 | } |
| 41 | |
| 42 | |
| 43 | def _event(event_id, title, markets, slug="event"): |
| 44 | return { |
| 45 | "id": event_id, "title": title, "slug": slug, "active": True, "closed": False, |
| 46 | "volume1mo": sum(float(market.get("volume") or 0) for market in markets), |
| 47 | "liquidity": 100000, "updatedAt": "2026-11-11T00:00:00Z", "markets": markets, |
| 48 | } |
| 49 | |
| 50 | |
| 51 | CITIES = "Will Waymo operate in {} cities on December 31 2026?" |
| 52 | WAYMO_CITIES = _event("638395", "How many cities will Waymo operate in by December 31?", [ |
| 53 | _market(CITIES.format("fewer than 12"), "<12", 0.046, 43441), |
| 54 | _market(CITIES.format("12-15"), "12-15", 0.79, 72439), |
| 55 | _market(CITIES.format("16-19"), "16-19", 0.12, 55018), |
| 56 | _market(CITIES.format("20-23"), "20-23", 0.03, 25429), |
| 57 | ]) |
| 58 | LAUNCH = "Will Waymo launch in {} by December 31 2026?" |
| 59 | WAYMO_LAUNCH = _event("638245", "Which cities will Waymo launch in by December 31?", [ |
| 60 | _market(LAUNCH.format("Denver, CO"), "Denver, CO", 0.74, 13209), |
| 61 | _market(LAUNCH.format("Las Vegas, NV"), "Las Vegas, NV", 0.70, 12360), |
| 62 | _market(LAUNCH.format("Detroit, MI"), "Detroit, MI", 0.08, 5812), |
| 63 | _market(LAUNCH.format("Sacramento, CA"), "Sacramento, CA", 0.065, 12707), |
| 64 | ]) |
| 65 | CAP = "Will Anthropic's market cap be {} at market close on IPO day?" |
| 66 | ANTHROPIC_CAP = _event("548858", "Anthropic IPO Closing Market Cap", [ |
| 67 | _market(CAP.format("less than $1.25T"), "<$1.25T", 0.24, 598704, "2028-01-01"), |
| 68 | _market(CAP.format("between $1.25T and $1.5T"), "$1.25–$1.5T", 0.42, 460473, "2028-01-01"), |
| 69 | _market(CAP.format("between $1.5T and $1.75T"), "$1.5–$1.75T", 0.21, 576313, "2028-01-01"), |
| 70 | # The busiest sub-market, so the event's own question: a 2% bracket. |
| 71 | _market(CAP.format("between $2.0T and $2.25T"), "$2.0–$2.25T", 0.02, 938512, "2028-01-01"), |
| 72 | ]) |
| 73 | HIT = "Will Anthropic's valuation hit (HIGH) {} by December 31?" |
| 74 | ANTHROPIC_HIT = _event("500753", "Will Anthropic’s valuation hit __ by December 31?", [ |
| 75 | _market(HIT.format("$3.0T"), "↑$3.0T", 0.10, 1828316, "2027-01-05"), |
| 76 | _market(HIT.format("$2.0T"), "↑$2.0T", 0.28, 1054604, "2027-01-05"), |
| 77 | _market(HIT.format("$1.5T"), "↑$1.5T", 0.70, 461457, "2027-01-05"), |
| 78 | ]) |
| 79 | RESIGN = "Jensen Huang announced resignation or removal by {}?" |
| 80 | JENSEN_RESIGN = _event("1343940", "Jensen Huang announced resignation or removal by...?", [ |
| 81 | _market(RESIGN.format("December 31, 2026"), "December 31, 2026", 0.16, 743121, "2027-01-01"), |
| 82 | _market(RESIGN.format("March 31, 2027"), "March 31, 2027", 0.24, 95669, "2027-04-01"), |
| 83 | _market(RESIGN.format("December 31, 2027"), "December 31, 2027", 0.38, 10374, "2028-01-01"), |
| 84 | ]) |
| 85 | DIVORCE = "Jensen Huang divorce by {}?" |
| 86 | JENSEN_DIVORCE = _event("1344318", "Jensen Huang divorce by...?", [ |
| 87 | _market(DIVORCE.format("December 31, 2026"), "December 31, 2026", 0.095, 150000, "2027-01-01"), |
| 88 | _market(DIVORCE.format("March 31, 2027"), "March 31, 2027", 0.18, 80000, "2027-04-01"), |
| 89 | ]) |
| 90 | TABLE_TENNIS = _event("1358638", "WTT Contender: Anders Lind vs Youzheng Huang", [{ |
| 91 | "question": "WTT Contender: Anders Lind vs Youzheng Huang", |
| 92 | "outcomes": '["Youzheng Huang", "Anders Lind"]', "outcomePrices": '["0.5", "0.5"]', |
| 93 | "volume": 0, "liquidity": 42.7597, "endDate": "2026-11-19T00:00:00Z", |
| 94 | "active": True, "closed": False, |
| 95 | }]) |
| 96 | IPO_ON = "Will Anthropic IPO on {}?" |
| 97 | ANTHROPIC_IPO_DATE = _event("1262075", "Anthropic IPO Date", [ |
| 98 | _market(IPO_ON.format("November 19, 2026"), "November 19", 0.15, 9000, "2026-11-20"), |
| 99 | _market(IPO_ON.format("November 20, 2026"), "November 20", 0.72, 8000, "2026-11-21"), |
| 100 | ]) |
| 101 | |
| 102 | |
| 103 | def _parsed(topic, *events): |
| 104 | return polymarket.parse_polymarket_response({"events": list(events)}, topic=topic) |
| 105 | |
| 106 | |
| 107 | def _items(topic, *events): |
| 108 | return normalize.normalize_source_items( |
| 109 | "polymarket", _parsed(topic, *events), "2026-10-12", "2026-11-11", |
| 110 | ) |
| 111 | |
| 112 | |
| 113 | def _footer(topic, *events): |
| 114 | return render._polymarket_top_markets(_items(topic, *events), limit=3, topic=topic) |
| 115 | |
| 116 | |
| 117 | # --- Evidence lines: each outcome keeps its own label --- |
| 118 | |
| 119 | |
| 120 | def test_bracket_sub_markets_keep_their_own_labels(): |
| 121 | names = [name for name, _price in _parsed("Waymo", WAYMO_CITIES)[0]["outcome_prices"]] |
| 122 | assert names == ["12-15", "16-19", "<12"] |
| 123 | |
| 124 | |
| 125 | def test_city_and_price_sub_markets_keep_their_own_labels(): |
| 126 | launch = _parsed("Waymo", WAYMO_LAUNCH)[0]["outcome_prices"] |
| 127 | cap = _parsed("Anthropic", ANTHROPIC_CAP)[0]["outcome_prices"] |
| 128 | assert launch == [("Denver, CO", 0.74), ("Las Vegas, NV", 0.70), ("Detroit, MI", 0.08)] |
| 129 | assert [name for name, _price in cap] == ["$1.25–$1.5T", "<$1.25T", "$1.5–$1.75T"] |
| 130 | |
| 131 | |
| 132 | def test_saved_file_odds_line_names_each_outcome(): |
| 133 | text = render.render_full(_report("Waymo", WAYMO_CITIES)) |
| 134 | assert " Odds: 12-15: 79% | 16-19: 12% | <12: 4.6%" in text |
| 135 | assert "Waymo: 79%" not in text |
| 136 | |
| 137 | |
| 138 | def test_sub_market_with_no_label_of_its_own_is_named_by_its_question(): |
| 139 | event = _event("1", "How many cities will Waymo operate in by December 31?", [ |
| 140 | {**_market(CITIES.format("12-15"), "", 0.79, 100)}, |
| 141 | {**_market(CITIES.format("16-19"), "", 0.12, 90)}, |
| 142 | ]) |
| 143 | names = [name for name, _price in _parsed("Waymo", event)[0]["outcome_prices"]] |
| 144 | assert names == [ |
| 145 | "Will Waymo operate in 12-15 cities on December 31 2026", |
| 146 | "Will Waymo operate in 16-19 cities on December 31 2026", |
| 147 | ] |
| 148 | |
| 149 | |
| 150 | def test_subjects_that_tell_the_outcomes_apart_are_kept(): |
| 151 | event = _event("2", "2027 NCAA Tournament Winner", [ |
| 152 | _market("Will Arizona win the 2027 NCAA Tournament?", "Arizona", 0.2, 100), |
| 153 | _market("Will Duke win the 2027 NCAA Tournament?", "Duke", 0.3, 90), |
| 154 | ]) |
| 155 | assert _parsed("NCAA Tournament", event)[0]["outcome_prices"] == [("Duke", 0.3), ("Arizona", 0.2)] |
| 156 | |
| 157 | |
| 158 | # --- The footer: whole phrases, and the price of the market that is named --- |
| 159 | |
| 160 | |
| 161 | def test_waymo_footer_names_end_with_their_bracket_place_and_date(): |
| 162 | assert _footer("Waymo", WAYMO_CITIES, WAYMO_LAUNCH) == [ |
| 163 | "Waymo operate in 12-15 cities on Dec 31, 2026 79%", |
| 164 | "Waymo launch in Denver, CO by Dec 31, 2026 74%", |
| 165 | ] |
| 166 | |
| 167 | |
| 168 | def test_footer_price_is_the_named_brackets_own_price(): |
| 169 | # The live footer put the 42% of the $1.25T-$1.5T bracket beside the |
| 170 | # question of the $2.0T-$2.25T one, and the 70% of $1.5T beside $3.0T. |
| 171 | assert _footer("Anthropic", ANTHROPIC_CAP, ANTHROPIC_HIT) == [ |
| 172 | "Anthropic's valuation hit (HIGH) $1.5T by Dec 31 70%", |
| 173 | "Anthropic's market cap between $1.25T and $1.5T at market close on IPO day 42%", |
| 174 | ] |
| 175 | |
| 176 | |
| 177 | def test_footer_names_never_end_mid_phrase(): |
| 178 | for line in _footer("Waymo", WAYMO_CITIES, WAYMO_LAUNCH) + _footer( |
| 179 | "Anthropic", ANTHROPIC_CAP, ANTHROPIC_HIT, |
| 180 | ): |
| 181 | name = line.rsplit(" ", 1)[0] |
| 182 | assert name.split()[-1].lower() not in {"on", "by", "between", "in", "at", "and", "be"} |
| 183 | |
| 184 | |
| 185 | # --- A deadline ladder shows its nearest open deadline --- |
| 186 | |
| 187 | |
| 188 | def test_deadline_ladder_shows_the_nearest_deadline_that_has_not_passed(): |
| 189 | assert _footer("Jensen Huang", JENSEN_RESIGN, JENSEN_DIVORCE) == [ |
| 190 | "Jensen Huang announced resignation or removal by Dec 31, 2026 16%", |
| 191 | "Jensen Huang divorce by Dec 31, 2026 9.5%", |
| 192 | ] |
| 193 | |
| 194 | |
| 195 | def test_deadline_that_has_passed_is_skipped(monkeypatch): |
| 196 | monkeypatch.setattr(polymarket, "_today", lambda: "2027-02-01", raising=False) |
| 197 | assert _footer("Jensen Huang", JENSEN_RESIGN) == [ |
| 198 | "Jensen Huang announced resignation or removal by Mar 31, 2027 24%", |
| 199 | ] |
| 200 | |
| 201 | |
| 202 | def test_outcomes_on_different_days_are_not_a_deadline_ladder(): |
| 203 | # "IPO on November 20" excludes "on November 19": the likeliest day leads. |
| 204 | assert _footer("Anthropic", ANTHROPIC_IPO_DATE) == ["Anthropic IPO on Nov 20, 2026 72%"] |
| 205 | |
| 206 | |
| 207 | def test_deadline_ladder_keeps_its_saved_names_and_price_order(): |
| 208 | # The names and order saved runs are compared by (tests/test_freshness.py). |
| 209 | assert _parsed("Jensen Huang", JENSEN_RESIGN)[0]["outcome_prices"] == [ |
| 210 | (RESIGN.format("December 31, 2027").rstrip("?"), 0.38), |
| 211 | (RESIGN.format("March 31, 2027").rstrip("?"), 0.24), |
| 212 | (RESIGN.format("December 31, 2026").rstrip("?"), 0.16), |
| 213 | ] |
| 214 | |
| 215 | |
| 216 | # --- A market must name the whole topic to be named in the footer --- |
| 217 | |
| 218 | |
| 219 | def test_market_sharing_one_word_of_the_topic_is_not_named_in_the_footer(): |
| 220 | lines = _footer("Jensen Huang", JENSEN_RESIGN, JENSEN_DIVORCE, TABLE_TENNIS) |
| 221 | assert len(lines) == 2 |
| 222 | assert not any("WTT" in line or "Youzheng" in line for line in lines) |
| 223 | |
| 224 | |
| 225 | def test_market_naming_one_word_of_the_topic_is_not_parsed(): |
| 226 | # The table tennis match names "Huang", not "Jensen Huang", so it never |
| 227 | # becomes an item and the footer counts the two markets that do. |
| 228 | assert [item["event_id"] for item in _parsed("Jensen Huang", TABLE_TENNIS)] == [] |
| 229 | report = _report("Jensen Huang", JENSEN_RESIGN, JENSEN_DIVORCE, TABLE_TENNIS) |
| 230 | line = next(line for line in render._render_emoji_footer(report, None) if "Polymarket" in line) |
| 231 | assert "📊 Polymarket: 2 markets │ " in line |
| 232 | assert "WTT" not in line |
| 233 | |
| 234 | |
| 235 | @pytest.mark.parametrize("topic, texts, expected", [ |
| 236 | ("Jensen Huang", ["WTT Contender: Anders Lind vs Youzheng Huang"], False), |
| 237 | ("Jensen Huang", ["Jensen Huang divorce by...?"], True), |
| 238 | ("Anthropic", ["Will Anthropic’s valuation hit __ by December 31?"], True), |
| 239 | ("Anthropic", ["What will Anthropic's public ticker be?"], True), |
| 240 | ("Kanye West", ["NFC West winner"], False), |
| 241 | ("OpenClaw vs Hermes", ["Will Hermes ship by June?"], True), |
| 242 | ("SpaceX", ["Tesla and SpaceX merger officially announced by December 31, 2027"], True), |
| 243 | ("", ["Anything at all"], True), |
| 244 | ]) |
| 245 | def test_names_whole_topic(topic, texts, expected): |
| 246 | assert polymarket.names_whole_topic(topic, *texts) is expected |
| 247 | |
| 248 | |
| 249 | # --- An event that is one market --- |
| 250 | |
| 251 | |
| 252 | def test_single_yes_no_market_is_named_by_its_whole_question(): |
| 253 | event = _event("3", "Tesla and SpaceX merger officially announced by December 31, 2027?", [ |
| 254 | _market("Tesla and SpaceX merger officially announced by December 31, 2027?", "", 0.68, 500), |
| 255 | ]) |
| 256 | assert _footer("SpaceX", event) == [ |
| 257 | "Tesla and SpaceX merger officially announced by Dec 31, 2027 68%", |
| 258 | ] |
| 259 | |
| 260 | |
| 261 | def test_single_market_with_named_outcomes_keeps_the_leading_outcome(): |
| 262 | assert render._polymarket_top_markets(_items("Youzheng Huang", TABLE_TENNIS)) == [ |
| 263 | "WTT Contender: Anders Lind vs Youzheng Huang: Youzheng Huang 50%", |
| 264 | ] |
| 265 | |
| 266 | |
| 267 | def _report(topic, *events): |
| 268 | from lib import schema |
| 269 | |
| 270 | return schema.Report( |
| 271 | topic=topic, range_from="2026-10-12", range_to="2026-11-11", |
| 272 | generated_at="2026-11-11T00:00:00Z", |
| 273 | provider_runtime=schema.ProviderRuntime("mock", "mock", "mock"), |
| 274 | query_plan=schema.QueryPlan( |
| 275 | intent="company", freshness_mode="balanced_recent", cluster_mode="none", |
| 276 | raw_topic=topic, subqueries=[], source_weights={}, |
| 277 | ), |
| 278 | clusters=[], ranked_candidates=[], |
| 279 | items_by_source={"polymarket": _items(topic, *events)}, |
| 280 | errors_by_source={}, |
| 281 | ) |
| 282 | |
| 283 | |
| 284 | def test_deadline_rung_the_market_gives_almost_no_chance_is_passed_over(): |
| 285 | # Live: "Anthropic IPO by Nov 17" sat at 0.8% beside "by Dec 31" at 97%. |
| 286 | ipo = "Anthropic IPO by {}?" |
| 287 | event = _event("77", "Anthropic IPO by...?", [ |
| 288 | _market(ipo.format("November 17, 2026"), "November 17, 2026", 0.008, 900000, "2026-11-18"), |
| 289 | _market(ipo.format("December 31, 2026"), "December 31, 2026", 0.97, 500000, "2027-01-01"), |
| 290 | ]) |
| 291 | assert _footer("Anthropic", event) == ["Anthropic IPO by Dec 31, 2026 97%"] |
| 292 | |
| 293 | |
| 294 | def test_deadline_ladder_of_long_shots_headlines_its_live_rung(): |
| 295 | # 2% is under the 3% floor for a yes/no market; 4% is not. |
| 296 | q = "Jensen Huang arrested by {}?" |
| 297 | event = _event("78", "Jensen Huang arrested by...?", [ |
| 298 | _market(q.format("December 31, 2026"), "December 31, 2026", 0.02, 9000, "2027-01-01"), |
| 299 | _market(q.format("March 31, 2027"), "March 31, 2027", 0.04, 5000, "2027-04-01"), |
| 300 | ]) |
| 301 | assert _footer("Jensen Huang", event) == ["Jensen Huang arrested by Mar 31, 2027 4.0%"] |
| 302 | |
| 303 | |
| 304 | def test_deadline_ladder_with_no_live_rung_keeps_its_nearest_rung(): |
| 305 | q = "Jensen Huang arrested by {}?" |
| 306 | event = _event("78", "Jensen Huang arrested by...?", [ |
| 307 | _market(q.format("December 31, 2026"), "December 31, 2026", 0.01, 9000, "2027-01-01"), |
| 308 | _market(q.format("March 31, 2027"), "March 31, 2027", 0.02, 5000, "2027-04-01"), |
| 309 | ]) |
| 310 | assert _footer("Jensen Huang", event) == ["Jensen Huang arrested by Dec 31, 2026 1.0%"] |
| 311 | |
| 312 | |
| 313 | # --- Odds lines: one ready-to-copy line per market in compact output --- |
| 314 | |
| 315 | |
| 316 | def _moved(market, **changes): |
| 317 | return {**market, **changes} |
| 318 | |
| 319 | |
| 320 | def _odds_entries(topic, *events): |
| 321 | block = render._render_polymarket_markets(_report(topic, *events)) |
| 322 | return [line[2:] for line in block if line.startswith("- ")] |
| 323 | |
| 324 | |
| 325 | def _odds_line(entry): |
| 326 | return entry.split(" — ", 1)[0] |
| 327 | |
| 328 | |
| 329 | def test_deadline_ladder_odds_line_lists_the_nearest_live_deadlines_in_date_order(): |
| 330 | (entry,) = _odds_entries("Jensen Huang", JENSEN_RESIGN) |
| 331 | assert _odds_line(entry) == ( |
| 332 | "📊 Polymarket · Jensen Huang announced resignation or removal: " |
| 333 | "16% by Dec 31 · 24% by Mar 31, 2027 · 38% by Dec 31, 2027" |
| 334 | ) |
| 335 | assert entry.split(" — ")[1] == "https://polymarket.com/event/event" |
| 336 | |
| 337 | |
| 338 | def test_odds_line_puts_movement_in_points_after_the_outcome_it_belongs_to(): |
| 339 | divorce = _event("1344318", "Jensen Huang divorce by...?", [ |
| 340 | _moved(JENSEN_DIVORCE["markets"][0], oneDayPriceChange=-0.01, oneWeekPriceChange=0.004), |
| 341 | _moved(JENSEN_DIVORCE["markets"][1], oneMonthPriceChange=0.07), |
| 342 | ]) |
| 343 | (entry,) = _odds_entries("Jensen Huang", divorce) |
| 344 | assert _odds_line(entry) == ( |
| 345 | "📊 Polymarket · Jensen Huang divorce: 9.5% by Dec 31 (down 1 pt today)" |
| 346 | " · 18% by Mar 31, 2027 (up 7 pts this month)" |
| 347 | ) |
| 348 | assert "%)" not in entry and "% today" not in entry |
| 349 | |
| 350 | |
| 351 | def test_bracket_odds_line_gives_the_top_outcomes_their_own_labels(): |
| 352 | cities = _event("638395", WAYMO_CITIES["title"], [ |
| 353 | WAYMO_CITIES["markets"][0], |
| 354 | _moved(WAYMO_CITIES["markets"][1], oneWeekPriceChange=0.188), |
| 355 | *WAYMO_CITIES["markets"][2:], |
| 356 | ]) |
| 357 | (entry,) = _odds_entries("Waymo", cities) |
| 358 | assert _odds_line(entry) == ( |
| 359 | "📊 Polymarket · How many cities will Waymo operate in by Dec 31: " |
| 360 | "12-15 at 79% (up 18.8 pts this week) · 16-19 at 12%" |
| 361 | ) |
| 362 | |
| 363 | |
| 364 | def test_bracket_odds_line_holds_at_most_three_outcomes_and_no_long_dash(): |
| 365 | (entry,) = _odds_entries("Anthropic", ANTHROPIC_CAP) |
| 366 | line = _odds_line(entry) |
| 367 | assert line == ( |
| 368 | "📊 Polymarket · Anthropic IPO Closing Market Cap: " |
| 369 | "$1.25-$1.5T at 42% · <$1.25T at 24% · $1.5-$1.75T at 21%" |
| 370 | ) |
| 371 | assert line.count(" at ") == 3 |
| 372 | assert "–" not in line and "—" not in line |
| 373 | assert " — +1 more outcome" in entry |
| 374 | |
| 375 | |
| 376 | def test_placeholder_in_an_event_title_is_dropped_from_the_subject(): |
| 377 | (entry,) = _odds_entries("Anthropic", ANTHROPIC_HIT) |
| 378 | assert _odds_line(entry) == ( |
| 379 | "📊 Polymarket · Anthropic’s valuation hit by Dec 31: " |
| 380 | "↑$1.5T at 70% · ↑$2.0T at 28% · ↑$3.0T at 10%" |
| 381 | ) |
| 382 | |
| 383 | |
| 384 | def test_single_market_odds_line_is_the_one_price(): |
| 385 | event = _event("3", "Tesla and SpaceX merger officially announced by December 31, 2027?", [ |
| 386 | _moved( |
| 387 | _market("Tesla and SpaceX merger officially announced by December 31, 2027?", "", 0.68, 500), |
| 388 | oneMonthPriceChange=-0.135, |
| 389 | ), |
| 390 | ]) |
| 391 | (entry,) = _odds_entries("SpaceX", event) |
| 392 | assert _odds_line(entry) == ( |
| 393 | "📊 Polymarket · Tesla and SpaceX merger officially announced by Dec 31, 2027: " |
| 394 | "68% (down 13.5 pts this month)" |
| 395 | ) |
| 396 | assert entry.endswith(" — https://polymarket.com/event/event — closes 2027-01-01") |
| 397 | |
| 398 | |
| 399 | def test_long_market_question_keeps_its_ending_on_the_odds_line(): |
| 400 | question = ( |
| 401 | "Will the Nvidia board announce the result of its independent investigation " |
| 402 | "into Jensen Huang before the congressional briefing on November 18, 2026?" |
| 403 | ) |
| 404 | event = _event("9", question, [_market(question, "", 0.31, 500)]) |
| 405 | (entry,) = _odds_entries("Jensen Huang", event) |
| 406 | line = _odds_line(entry) |
| 407 | assert "congressional briefing on Nov 18" in line |
| 408 | assert line.endswith(": 31%") |
| 409 | assert "..." not in line |
| 410 | |
| 411 | |
| 412 | def test_single_market_with_named_outcomes_lists_them(): |
| 413 | (entry,) = _odds_entries("Youzheng Huang", TABLE_TENNIS) |
| 414 | assert _odds_line(entry) == ( |
| 415 | "📊 Polymarket · WTT Contender: Anders Lind vs Youzheng Huang: " |
| 416 | "Youzheng Huang at 50% · Anders Lind at 50%" |
| 417 | ) |
| 418 | |
| 419 | |
| 420 | def test_ladder_odds_line_skips_passed_and_dead_rungs(monkeypatch): |
| 421 | monkeypatch.setattr(polymarket, "_today", lambda: "2027-02-01", raising=False) |
| 422 | (entry,) = _odds_entries("Jensen Huang", JENSEN_RESIGN) |
| 423 | assert _odds_line(entry).endswith(": 24% by Mar 31, 2027 · 38% by Dec 31, 2027") |
| 424 | monkeypatch.setattr(polymarket, "_today", lambda: TODAY, raising=False) |
| 425 | ipo = "Anthropic IPO by {}?" |
| 426 | event = _event("77", "Anthropic IPO by...?", [ |
| 427 | _market(ipo.format("November 17, 2026"), "November 17, 2026", 0.008, 900000, "2026-11-18"), |
| 428 | _market(ipo.format("December 31, 2026"), "December 31, 2026", 0.97, 500000, "2027-01-01"), |
| 429 | ]) |
| 430 | (entry,) = _odds_entries("Anthropic", event) |
| 431 | assert _odds_line(entry) == "📊 Polymarket · Anthropic IPO: 97% by Dec 31" |
| 432 | |
| 433 | |
| 434 | def test_odds_lines_never_print_a_volume_and_stay_within_eight_markets(): |
| 435 | events = [ |
| 436 | _event(str(index), f"Will Waymo do thing {index} in 2027?", [ |
| 437 | _market(f"Will Waymo do thing {index} in 2027?", "", 0.5, 123456 + index), |
| 438 | ], slug=f"e{index}") |
| 439 | for index in range(12) |
| 440 | ] |
| 441 | entries = _odds_entries("Waymo", *events) |
| 442 | assert len(entries) == render.POLYMARKET_MARKETS_LIMIT == 8 |
| 443 | for entry in entries: |
| 444 | assert "123" not in entry and "$" not in entry |
| 445 | assert entry.startswith("📊 Polymarket · Waymo do thing ") |
| 446 | |
| 447 | |
| 448 | def test_item_saved_before_odds_were_stored_still_gets_a_line(): |
| 449 | (item,) = _items("Waymo", WAYMO_CITIES) |
| 450 | del item.metadata["odds"] |
| 451 | item.snippet = "up 18.8% this week" |
| 452 | report = _report("Waymo", WAYMO_CITIES) |
| 453 | report.items_by_source["polymarket"] = [item] |
| 454 | (entry,) = [line[2:] for line in render._render_polymarket_markets(report) if line.startswith("- ")] |
| 455 | assert _odds_line(entry) == ( |
| 456 | "📊 Polymarket · How many cities will Waymo operate in by Dec 31: " |
| 457 | "12-15 at 79% · 16-19 at 12%" |
| 458 | ) |
| 459 |