forked from sass/tipibot
CS2 team dividers.
This commit is contained in:
@@ -87,6 +87,108 @@ def test_parse_team_rosters_ignores_non_table_content():
|
||||
assert sheets.parse_team_rosters([["just", "some", "prose"], ["more"]]) == {}
|
||||
|
||||
|
||||
# --- parse_team_sections (which game/year a block of teams came from) ------
|
||||
|
||||
def test_parse_team_sections_tags_each_block_with_its_title():
|
||||
sections = sheets.parse_team_sections(SHEET_ROWS)
|
||||
assert [(s.title, sorted(s.rosters)) for s in sections] == [
|
||||
("[merged] TipiLAN 2026 CS2 Registration Log", ["GENESIS", "Piirivalvurid"]),
|
||||
("[merged] TipiLAN 2026 LoL Registration Log", ["Pushing 30s"]),
|
||||
]
|
||||
|
||||
|
||||
def test_parse_team_sections_title_does_not_leak_to_untitled_block():
|
||||
rows = [
|
||||
["[merged] TipiLAN 2026 CS2 Registration Log"] + [""] * 2,
|
||||
["No", "Team Name", "Lineup (nickname)"],
|
||||
["1", "GENESIS", "kapa (EST)"],
|
||||
["", "", ""],
|
||||
["No", "Team Name", "Lineup (nickname)"], # second block, no title above it
|
||||
["1", "Nameless", "someone (EST)"],
|
||||
]
|
||||
titles = [s.title for s in sheets.parse_team_sections(rows)]
|
||||
assert titles == ["[merged] TipiLAN 2026 CS2 Registration Log", ""]
|
||||
|
||||
|
||||
# --- resolve_divider (section title -> configured divider role) ------------
|
||||
|
||||
DIVIDERS = {
|
||||
"cs2_2026": "====== COUNTER-STRIKE 2 2026 ======",
|
||||
"lol_2026": "===== LEAGUE OF LEGENDS 2026 =====",
|
||||
}
|
||||
|
||||
|
||||
def test_resolve_divider_matches_game_and_year():
|
||||
assert sheets.resolve_divider(
|
||||
"[merged] TipiLAN 2026 CS2 Registration Log", DIVIDERS
|
||||
) == "====== COUNTER-STRIKE 2 2026 ======"
|
||||
assert sheets.resolve_divider(
|
||||
"[merged] TipiLAN 2026 LoL Registration Log", DIVIDERS
|
||||
) == "===== LEAGUE OF LEGENDS 2026 ====="
|
||||
|
||||
|
||||
def test_resolve_divider_year_scoped_key_ignores_other_years():
|
||||
assert sheets.resolve_divider("TipiLAN 2025 CS2 Registration Log", DIVIDERS) is None
|
||||
|
||||
|
||||
def test_resolve_divider_prefers_the_most_specific_match():
|
||||
dividers = {"cs2": "== CS2 ALL YEARS ==", "cs2_2026": "== CS2 2026 =="}
|
||||
assert sheets.resolve_divider("TipiLAN 2026 CS2 Log", dividers) == "== CS2 2026 =="
|
||||
assert sheets.resolve_divider("TipiLAN 2025 CS2 Log", dividers) == "== CS2 ALL YEARS =="
|
||||
|
||||
|
||||
def test_resolve_divider_no_config_or_no_title_is_none():
|
||||
assert sheets.resolve_divider("TipiLAN 2026 CS2 Log", {}) is None
|
||||
assert sheets.resolve_divider("", DIVIDERS) is None
|
||||
|
||||
|
||||
# --- plan_team_positions (pure role-ordering maths) ------------------------
|
||||
|
||||
def test_plan_moves_teams_directly_under_their_divider():
|
||||
# Ascending = bottom-up, so the Discord UI renders this list reversed.
|
||||
ordered = ["@everyone", "60hz", "999", "Raid", "CS2-2026", "LOL-2026", "Bot"]
|
||||
plan = member_sync.plan_team_positions(
|
||||
ordered, {"Bot"}, {"CS2-2026": ["60hz", "999", "Raid"]}
|
||||
)
|
||||
final = sorted(set(ordered), key=lambda n: plan.get(n, ordered.index(n)))
|
||||
# Teams end up just below the divider, alphabetical downwards in the UI.
|
||||
assert final == ["@everyone", "Raid", "999", "60hz", "CS2-2026", "LOL-2026", "Bot"]
|
||||
|
||||
|
||||
def test_plan_groups_each_divider_separately():
|
||||
ordered = ["@everyone", "Alpha", "Pushing 30s", "CS2-2026", "LOL-2026", "Bot"]
|
||||
plan = member_sync.plan_team_positions(
|
||||
ordered,
|
||||
{"Bot"},
|
||||
{"CS2-2026": ["Alpha"], "LOL-2026": ["Pushing 30s"]},
|
||||
)
|
||||
final = sorted(set(ordered), key=lambda n: plan.get(n, ordered.index(n)))
|
||||
assert final == ["@everyone", "Alpha", "CS2-2026", "Pushing 30s", "LOL-2026", "Bot"]
|
||||
|
||||
|
||||
def test_plan_is_a_noop_when_already_positioned():
|
||||
ordered = ["@everyone", "Raid", "999", "60hz", "CS2-2026", "Bot"]
|
||||
assert member_sync.plan_team_positions(
|
||||
ordered, {"Bot"}, {"CS2-2026": ["60hz", "999", "Raid"]}
|
||||
) == {}
|
||||
|
||||
|
||||
def test_plan_skips_missing_divider_and_leaves_its_teams_alone():
|
||||
ordered = ["@everyone", "60hz", "CS2-2026", "Bot"]
|
||||
plan = member_sync.plan_team_positions(
|
||||
ordered, {"Bot"}, {"LOL-2026": ["60hz"]} # divider not in the guild
|
||||
)
|
||||
assert plan == {}
|
||||
|
||||
|
||||
def test_plan_never_moves_managed_roles():
|
||||
ordered = ["@everyone", "60hz", "CS2-2026", "Nitro", "Bot"]
|
||||
plan = member_sync.plan_team_positions(
|
||||
ordered, {"Nitro", "Bot"}, {"CS2-2026": ["60hz", "Nitro"]}
|
||||
)
|
||||
assert "Nitro" not in plan and "Bot" not in plan
|
||||
|
||||
|
||||
def test_build_username_index_is_case_insensitive():
|
||||
index = sheets.build_username_index({"GENESIS": ["Kapa", "neaQ"]})
|
||||
assert index == {"kapa": "GENESIS", "neaq": "GENESIS"}
|
||||
|
||||
Reference in New Issue
Block a user