Skip to content

Commit

Permalink
Merge pull request #9 from TaekyungHeo/allow-override
Browse files Browse the repository at this point in the history
Allow overriding of runner mappings in Runner class
  • Loading branch information
srinivas212 authored May 15, 2024
2 parents f3c6951 + 9749e3a commit 3a8b092
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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

0 comments on commit 3a8b092

Please sign in to comment.