Coverage for mlos_bench/mlos_bench/tests/services/mock_service.py: 100%
17 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-06 00:35 +0000
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-06 00:35 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""
6Basic MockService for testing.
8See Also: test_service_method_registering.py
9"""
11from typing import Callable, Dict, List, Optional, Protocol, Union, runtime_checkable
13from mlos_bench.services.base_service import Service
16@runtime_checkable
17class SupportsSomeMethod(Protocol):
18 """Protocol for some_method"""
20 def some_method(self) -> str:
21 """some_method"""
23 def some_other_method(self) -> str:
24 """some_other_method"""
27class MockServiceBase(Service, SupportsSomeMethod):
28 """A base service class for testing."""
30 def __init__(
31 self,
32 config: Optional[dict] = None,
33 global_config: Optional[dict] = None,
34 parent: Optional[Service] = None,
35 methods: Optional[Union[Dict[str, Callable], List[Callable]]] = None) -> None:
36 super().__init__(
37 config,
38 global_config,
39 parent,
40 self.merge_methods(methods, [
41 self.some_method,
42 self.some_other_method,
43 ]))
45 def some_method(self) -> str:
46 """some_method"""
47 return f"{self}: base.some_method"
49 def some_other_method(self) -> str:
50 """some_other_method"""
51 return f"{self}: base.some_other_method"
54class MockServiceChild(MockServiceBase, SupportsSomeMethod):
55 """A child service class for testing."""
57 # Intentionally includes no constructor.
59 def some_method(self) -> str:
60 """some_method"""
61 return f"{self}: child.some_method"