From bc6e6d6e29803c9c3f41ef80e4ae5adfb29b1188 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Fri, 28 Feb 2025 11:15:08 -0500 Subject: [PATCH 1/6] Add function --- commands2/commandscheduler.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/commands2/commandscheduler.py b/commands2/commandscheduler.py index 7eba7a4..e85ebe7 100644 --- a/commands2/commandscheduler.py +++ b/commands2/commandscheduler.py @@ -334,6 +334,12 @@ def unregisterSubsystem(self, *subsystems: Subsystem) -> None: for subsystem in subsystems: self._subsystems.pop(subsystem, None) + def getAllSubsystems(self) -> tuple[Subsystem]: + """ + Gets all registered subsystems as an immutable tuple. + """ + return tuple(self._subsystems.keys()) + def unregisterAllSubsystems(self): """ Un-registers all registered Subsystems with the scheduler. All currently registered subsystems From 07ad2df443925cbe30289b3f8527c05f943994ee Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Fri, 28 Feb 2025 11:25:43 -0500 Subject: [PATCH 2/6] Add test --- tests/test_command_schedule.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_command_schedule.py b/tests/test_command_schedule.py index 62d2182..a20c954 100644 --- a/tests/test_command_schedule.py +++ b/tests/test_command_schedule.py @@ -88,3 +88,16 @@ def test_notScheduledCancel(scheduler: commands2.CommandScheduler): command = commands2.Command() scheduler.cancel(command) + +def test_getAllSubystems(scheduler: commands2.CommandScheduler): + sub1 = commands2.Subsystem() + sub1.setName("test123") + sub2 = commands2.Subsystem() + sub2.setName("hey") + start_spying_on(sub1) + start_spying_on(sub2) + scheduler.registerSubsystem(sub1) + scheduler.registerSubsystem(sub2) + sublist = scheduler.getAllSubsystems() + assert sublist[0].getName() == "test123" + assert sublist[1].getName() == "hey" \ No newline at end of file From c567484244759b814f94d9c09785aafb6dbc2f5d Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Fri, 28 Feb 2025 11:35:13 -0500 Subject: [PATCH 3/6] test reliability --- tests/test_command_schedule.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_command_schedule.py b/tests/test_command_schedule.py index a20c954..7434da1 100644 --- a/tests/test_command_schedule.py +++ b/tests/test_command_schedule.py @@ -99,5 +99,10 @@ def test_getAllSubystems(scheduler: commands2.CommandScheduler): scheduler.registerSubsystem(sub1) scheduler.registerSubsystem(sub2) sublist = scheduler.getAllSubsystems() - assert sublist[0].getName() == "test123" - assert sublist[1].getName() == "hey" \ No newline at end of file + con1 = sublist[0].getName() == "test123" + con2 = sublist[0].getName() == "hey" + assert con1 or con2 + if(con1): + assert sublist[1].getName() == "hey" + else: + assert sublist[1].getName() == "test123" \ No newline at end of file From aeb61c85895af21558b184b434c225246c95d18b Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Fri, 28 Feb 2025 14:17:51 -0500 Subject: [PATCH 4/6] Fix return value type --- commands2/commandscheduler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands2/commandscheduler.py b/commands2/commandscheduler.py index e85ebe7..6cbbe53 100644 --- a/commands2/commandscheduler.py +++ b/commands2/commandscheduler.py @@ -334,7 +334,7 @@ def unregisterSubsystem(self, *subsystems: Subsystem) -> None: for subsystem in subsystems: self._subsystems.pop(subsystem, None) - def getAllSubsystems(self) -> tuple[Subsystem]: + def getAllSubsystems(self) -> tuple[Subsystem, ...]: """ Gets all registered subsystems as an immutable tuple. """ From 06826244cd3dc01cdd41a1b87130d6662e2e4a02 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Fri, 28 Feb 2025 14:18:36 -0500 Subject: [PATCH 5/6] Add newline at end of test file --- tests/test_command_schedule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_command_schedule.py b/tests/test_command_schedule.py index 7434da1..68d9ffe 100644 --- a/tests/test_command_schedule.py +++ b/tests/test_command_schedule.py @@ -105,4 +105,4 @@ def test_getAllSubystems(scheduler: commands2.CommandScheduler): if(con1): assert sublist[1].getName() == "hey" else: - assert sublist[1].getName() == "test123" \ No newline at end of file + assert sublist[1].getName() == "test123" From 1c6f1f4819a21b0a46b76b47cba1870988c373f5 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Fri, 28 Feb 2025 14:19:22 -0500 Subject: [PATCH 6/6] Remove unneeded table in commandscheduler.py --- commands2/commandscheduler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands2/commandscheduler.py b/commands2/commandscheduler.py index 6cbbe53..be362bc 100644 --- a/commands2/commandscheduler.py +++ b/commands2/commandscheduler.py @@ -339,7 +339,7 @@ def getAllSubsystems(self) -> tuple[Subsystem, ...]: Gets all registered subsystems as an immutable tuple. """ return tuple(self._subsystems.keys()) - + def unregisterAllSubsystems(self): """ Un-registers all registered Subsystems with the scheduler. All currently registered subsystems