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

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5"""A collection Service functions for mocking local exec.""" 

6 

7import logging 

8from collections.abc import Callable, Iterable, Mapping 

9from typing import TYPE_CHECKING, Any 

10 

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 

14 

15if TYPE_CHECKING: 

16 from mlos_bench.tunables.tunable import TunableValue 

17 

18_LOG = logging.getLogger(__name__) 

19 

20 

21class MockLocalExecService(TempDirContextService, SupportsLocalExec): 

22 """Mock methods for LocalExecService testing.""" 

23 

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 ) 

34 

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, "", "")