Skip to content

Commit 29e4b4b

Browse files
committed
Add type annotations for opensearch.
1 parent 087cada commit 29e4b4b

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

opensearch/testcontainers/opensearch/__init__.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,13 @@ class OpenSearchContainer(DockerContainer):
2828
... search_result = client.search(index="test", body={"query": {"match_all": {}}})
2929
"""
3030

31-
def __init__(
32-
self,
33-
image="opensearchproject/opensearch:2.4.0",
34-
port_to_expose=9200,
35-
security_enabled=False,
36-
**kwargs,
37-
):
31+
def __init__(self, image: str = "opensearchproject/opensearch:2.4.0",
32+
port_to_expose: int = 9200, security_enabled: bool = False, **kwargs) -> None:
3833
"""
3934
Args:
40-
image (str, optional): The Docker image to use for the container.
41-
Defaults to "opensearchproject/opensearch:2.4.0".
42-
port_to_expose (int, optional): The port to expose on the container.
43-
Defaults to 9200.
44-
security_enabled (bool, optional): `False` disables the security plugin in OpenSearch.
45-
Defaults to False.
35+
image: Docker image to use for the container.
36+
port_to_expose: Port to expose on the container.
37+
security_enabled: :code:`False` disables the security plugin in OpenSearch.
4638
"""
4739
super(OpenSearchContainer, self).__init__(image, **kwargs)
4840
self.port_to_expose = port_to_expose
@@ -54,7 +46,7 @@ def __init__(
5446
if security_enabled:
5547
self.with_env("plugins.security.allow_default_init_securityindex", "true")
5648

57-
def get_config(self):
49+
def get_config(self) -> dict:
5850
"""This method returns the configuration of the OpenSearch container,
5951
including the host, port, user, and password.
6052
@@ -91,13 +83,13 @@ def get_client(self, verify_certs: bool = False, **kwargs) -> OpenSearch:
9183
)
9284

9385
@wait_container_is_ready(ConnectionError, TransportError)
94-
def _healthcheck(self):
86+
def _healthcheck(self) -> None:
9587
"""This is an internal method used to check if the OpenSearch container
9688
is healthy and ready to receive requests."""
9789
client: OpenSearchContainer = self.get_client()
9890
client.cluster.health(wait_for_status="green")
9991

100-
def start(self):
92+
def start(self) -> "OpenSearchContainer":
10193
"""This method starts the OpenSearch container and runs the healthcheck
10294
to verify that the container is ready to use."""
10395
super().start()

0 commit comments

Comments
 (0)