12
12
# under the License.
13
13
import os
14
14
import socket
15
+ from typing import Iterable , Optional
15
16
16
17
from testcontainers .core .container import DockerContainer
17
18
from testcontainers .core .waiting_utils import wait_container_is_ready
@@ -48,21 +49,14 @@ class AzuriteContainer(DockerContainer):
48
49
_QUEUE_SERVICE_PORT = 10_001
49
50
_TABLE_SERVICE_PORT = 10_002
50
51
51
- def __init__ (
52
- self ,
53
- image = "mcr.microsoft.com/azure-storage/azurite:latest" ,
54
- ports_to_expose = None ,
55
- ** kwargs
56
- ):
52
+ def __init__ (self , image : str = "mcr.microsoft.com/azure-storage/azurite:latest" ,
53
+ ports_to_expose : Optional [Iterable [int ]] = None , ** kwargs ) -> None :
57
54
""" Constructs an AzuriteContainer.
58
55
59
- Parameters
60
- ----------
61
- image: str
62
- Expects an image with tag.
63
- ports_to_expose: List[int]
64
- Expects a list with port numbers to expose.
65
- kwargs
56
+ Args:
57
+ image: Expects an image with tag.
58
+ ports_to_expose: List with port numbers to expose.
59
+ **kwargs: Keyword arguments passed to super class.
66
60
"""
67
61
super ().__init__ (image = image , ** kwargs )
68
62
@@ -80,7 +74,7 @@ def __init__(
80
74
self .with_env ("AZURITE_ACCOUNTS" ,
81
75
f"{ self ._AZURITE_ACCOUNT_NAME } :{ self ._AZURITE_ACCOUNT_KEY } " )
82
76
83
- def get_connection_string (self ):
77
+ def get_connection_string (self ) -> str :
84
78
host_ip = self .get_container_host_ip ()
85
79
connection_string = f"DefaultEndpointsProtocol=http;" \
86
80
f"AccountName={ self ._AZURITE_ACCOUNT_NAME } ;" \
@@ -103,13 +97,13 @@ def get_connection_string(self):
103
97
104
98
return connection_string
105
99
106
- def start (self ):
100
+ def start (self ) -> 'AzuriteContainer' :
107
101
super ().start ()
108
102
self ._connect ()
109
103
return self
110
104
111
105
@wait_container_is_ready (OSError )
112
- def _connect (self ):
106
+ def _connect (self ) -> None :
113
107
with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
114
108
s .connect ((self .get_container_host_ip (),
115
109
int (self .get_exposed_port (next (iter (self .ports ))))))
0 commit comments