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

11 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 00:44 +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 typing import ( 

9 TYPE_CHECKING, 

10 Any, 

11 Callable, 

12 Dict, 

13 Iterable, 

14 List, 

15 Mapping, 

16 Optional, 

17 Tuple, 

18 Union, 

19) 

20 

21from mlos_bench.services.base_service import Service 

22from mlos_bench.services.local.temp_dir_context import TempDirContextService 

23from mlos_bench.services.types.local_exec_type import SupportsLocalExec 

24 

25if TYPE_CHECKING: 

26 from mlos_bench.tunables.tunable import TunableValue 

27 

28_LOG = logging.getLogger(__name__) 

29 

30 

31class MockLocalExecService(TempDirContextService, SupportsLocalExec): 

32 """Mock methods for LocalExecService testing.""" 

33 

34 def __init__( 

35 self, 

36 config: Optional[Dict[str, Any]] = None, 

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

38 parent: Optional[Service] = None, 

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

40 ): 

41 super().__init__( 

42 config, global_config, parent, self.merge_methods(methods, [self.local_exec]) 

43 ) 

44 

45 def local_exec( 

46 self, 

47 script_lines: Iterable[str], 

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

49 cwd: Optional[str] = None, 

50 ) -> Tuple[int, str, str]: 

51 return (0, "", "")