|
12 | 12 | class Container: |
13 | 13 | def __init__( |
14 | 14 | self, |
15 | | - ): |
| 15 | + ) -> None: |
16 | 16 | self._image_name: str = 'thenativeweb/eventsourcingdb' |
17 | 17 | self._image_tag: str = 'latest' |
18 | 18 | self._api_token: str = 'secret' |
@@ -57,7 +57,7 @@ def _create_container(self) -> None: |
57 | 57 | detach=True, |
58 | 58 | ) # type: ignore |
59 | 59 |
|
60 | | - def _extract_port_from_container_info(self, container_info): |
| 60 | + def _extract_port_from_container_info(self, container_info) -> int | None: |
61 | 61 | port = None |
62 | 62 | valid_mapping = True |
63 | 63 | port_mappings = None |
@@ -95,7 +95,7 @@ def _fetch_mapped_port(self) -> None: |
95 | 95 | self._stop_and_remove_container() |
96 | 96 | raise RuntimeError('Failed to determine mapped port') |
97 | 97 |
|
98 | | - def _get_container_info(self): |
| 98 | + def _get_container_info(self) -> dict | None: |
99 | 99 | if self._container is None: |
100 | 100 | return None |
101 | 101 | return self._docker_client.api.inspect_container(self._container.id) |
@@ -137,7 +137,12 @@ def start(self) -> 'Container': |
137 | 137 | return self |
138 | 138 |
|
139 | 139 | def _pull_or_get_image(self) -> None: |
140 | | - """Pull Docker image or use local image if pulling fails.""" |
| 140 | + try: |
| 141 | + self._docker_client.images.pull(self._image_name, self._image_tag) |
| 142 | + except errors.APIError as e: |
| 143 | + self._handle_image_pull_error(e) |
| 144 | + |
| 145 | + def _handle_image_pull_error(self, error) -> None: |
141 | 146 | image_name = f"{self._image_name}:{self._image_tag}" |
142 | 147 |
|
143 | 148 | # First check if the image is already available locally |
@@ -230,7 +235,7 @@ def _check_endpoint_available(self, url: str) -> bool: |
230 | 235 | return self._check_response_ok(response) |
231 | 236 |
|
232 | 237 | # pylint: disable=R6301 |
233 | | - def _check_response_ok(self, response) -> bool: |
| 238 | + def _check_response_ok(self, response: requests.Response) -> bool: |
234 | 239 | return response is not None and response.status_code == HTTPStatus.OK |
235 | 240 |
|
236 | 241 | def with_api_token(self, token: str) -> 'Container': |
|
0 commit comments