Coverage for mlos_bench/mlos_bench/tests/services/local/mock/mock_local_exec_service.py: 92%
12 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-21 01:50 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-21 01:50 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""A collection Service functions for mocking local exec."""
7import logging
8from collections.abc import Callable, Iterable, Mapping
9from typing import TYPE_CHECKING, Any
11from mlos_bench.services.base_service import Service
12from mlos_bench.services.local.temp_dir_context import TempDirContextService
13from mlos_bench.services.types.local_exec_type import SupportsLocalExec
15if TYPE_CHECKING:
16 from mlos_bench.tunables.tunable import TunableValue
18_LOG = logging.getLogger(__name__)
21class MockLocalExecService(TempDirContextService, SupportsLocalExec):
22 """Mock methods for LocalExecService testing."""
24 def __init__(
25 self,
26 config: dict[str, Any] | None = None,
27 global_config: dict[str, Any] | None = None,
28 parent: Service | None = None,
29 methods: dict[str, Callable] | list[Callable] | None = None,
30 ):
31 super().__init__(
32 config, global_config, parent, self.merge_methods(methods, [self.local_exec])
33 )
35 def local_exec(
36 self,
37 script_lines: Iterable[str],
38 env: Mapping[str, "TunableValue"] | None = None,
39 cwd: str | None = None,
40 ) -> tuple[int, str, str]:
41 return (0, "", "")