Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding of runner mappings in Runner class #9

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/cloudai/runner/core/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ def register(cls, system_type: str) -> Callable:
"""

def decorator(runner_class: Type[BaseRunner]) -> Type[BaseRunner]:
if system_type in cls._runners:
raise KeyError(f"Runner for {system_type} already registered.")
cls._runners[system_type] = runner_class
return runner_class

Expand Down
21 changes: 21 additions & 0 deletions tests/runner/core/test_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from unittest.mock import patch

from cloudai.runner.core import BaseRunner, Runner


def test_register_multiple_runners():
"""
Test registering multiple different runners for the same type to ensure that
only the last registered runner is kept.
"""
with patch.dict("cloudai.runner.Runner._runners", clear=True):

@Runner.register("slurm")
class FirstSlurmRunner(BaseRunner):
pass

@Runner.register("slurm")
class SecondSlurmRunner(BaseRunner):
pass

assert Runner._runners["slurm"] is SecondSlurmRunner