Coverage for mlos_bench/mlos_bench/tests/services/local/mock/mock_local_exec_service.py: 92%

12 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-05 00:36 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5""" 

6A collection Service functions for mocking local exec. 

7""" 

8 

9import logging 

10from typing import ( 

11 Any, Callable, Dict, Iterable, List, Mapping, Optional, Tuple, TYPE_CHECKING, Union 

12) 

13 

14from mlos_bench.services.base_service import Service 

15from mlos_bench.services.local.temp_dir_context import TempDirContextService 

16from mlos_bench.services.types.local_exec_type import SupportsLocalExec 

17 

18if TYPE_CHECKING: 

19 from mlos_bench.tunables.tunable import TunableValue 

20 

21_LOG = logging.getLogger(__name__) 

22 

23 

24class MockLocalExecService(TempDirContextService, SupportsLocalExec): 

25 """ 

26 Mock methods for LocalExecService testing. 

27 """ 

28 

29 def __init__(self, config: Optional[Dict[str, Any]] = None, 

30 global_config: Optional[Dict[str, Any]] = None, 

31 parent: Optional[Service] = None, 

32 methods: Union[Dict[str, Callable], List[Callable], None] = None): 

33 super().__init__( 

34 config, global_config, parent, 

35 self.merge_methods(methods, [self.local_exec]) 

36 ) 

37 

38 def local_exec(self, script_lines: Iterable[str], 

39 env: Optional[Mapping[str, "TunableValue"]] = None, 

40 cwd: Optional[str] = None) -> Tuple[int, str, str]: 

41 return (0, "", "")