From 53e56394bf5e4bacbf91056ec504402f40ec5d0e Mon Sep 17 00:00:00 2001 From: Shouryaverma19 Date: Fri, 3 Jul 2026 20:18:01 +0530 Subject: [PATCH] fix: implement list_jobs method and add test suite --- matrix/scheduler.py | 4 ++++ tests/test_scheduler.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/test_scheduler.py diff --git a/matrix/scheduler.py b/matrix/scheduler.py index 398fbca..f8ed09c 100644 --- a/matrix/scheduler.py +++ b/matrix/scheduler.py @@ -18,6 +18,10 @@ def __init__(self) -> None: def jobs(self) -> list[Job]: return cast(list[Job], self.scheduler.get_jobs()) + def list_jobs(self) -> list[str]: + """Return a list of names of all registered jobs.""" + return [job.name for job in self.jobs] + def _parse_cron(self, cron: str) -> dict: """ Parse a cron string into a dictionary suitable for CronTrigger. diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py new file mode 100644 index 0000000..9ce5fd1 --- /dev/null +++ b/tests/test_scheduler.py @@ -0,0 +1,22 @@ +import pytest +from matrixpy.scheduler import Scheduler + + +def test_list_jobs_expect_empty() -> None: + """Verify list_jobs returns an empty list on initialization.""" + scheduler = Scheduler() + assert scheduler.list_jobs() == [] + + +def test_list_jobs_with_active_jobs() -> None: + """Verify list_jobs returns the names of the scheduled jobs.""" + scheduler = Scheduler() + + class MockJob: + + def __init__(self, name: str) -> None: + self.name: str = name + + scheduler.jobs = [MockJob("job_1"), MockJob("job_2")] + + assert scheduler.list_jobs() == ["job_1", "job_2"]