[wpilib] Add AlertSim function to get only active alerts (#8732)

This commit is contained in:
Sam Freund
2026-04-10 00:25:26 -05:00
committed by GitHub
parent 02c6030251
commit ece8001b1e
7 changed files with 105 additions and 2 deletions

View File

@@ -143,3 +143,30 @@ def test_set_text_while_set(group_name):
assert alert.getText() == "AFTER"
assert not is_alert_active("BEFORE", Alert.Level.LOW)
assert is_alert_active("AFTER", Alert.Level.LOW)
def test_get_active(group_name):
with (
Alert(group_name, "A", Alert.Level.HIGH) as a,
Alert(group_name, "B", Alert.Level.HIGH) as b,
Alert(group_name, "C", Alert.Level.HIGH) as c,
):
a.set(True)
b.set(True)
c.set(False)
active = AlertSim.getActive()
allAlerts = AlertSim.getAll()
assert len(active) == 2
assert len(allAlerts) == 3
activeTexts = [a.text for a in active]
assert set(activeTexts) == {"A", "B"}
a.set(False)
active = AlertSim.getActive()
allAlerts = AlertSim.getAll()
assert len(active) == 1
assert len(allAlerts) == 3
assert active[0].text == "B"