Skip to content

fix(core): Typing in config + utils #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/testcontainers/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
tc_files = [item for item in [TC_GLOBAL] if exists(item)]
if not tc_files:
return {}
settings = {}
settings: dict[str, str] = {}

Check warning on line 33 in core/testcontainers/core/config.py

View check run for this annotation

Codecov / codecov/patch

core/testcontainers/core/config.py#L33

Added line #L33 was not covered by tests

for file in tc_files:
with open(file) as contents:
Expand Down Expand Up @@ -60,14 +60,14 @@
"""

@property
def docker_auth_config(self):
def docker_auth_config(self) -> Optional[str]:
config = self._docker_auth_config
if config and "DOCKER_AUTH_CONFIG" in _WARNINGS:
warning(_WARNINGS.pop("DOCKER_AUTH_CONFIG"))
return config

@docker_auth_config.setter
def docker_auth_config(self, value: str):
def docker_auth_config(self, value: str) -> None:
if "DOCKER_AUTH_CONFIG" in _WARNINGS:
warning(_WARNINGS.pop("DOCKER_AUTH_CONFIG"))
self._docker_auth_config = value
Expand All @@ -76,7 +76,7 @@
return self.tc_properties.get("tc.host")

@property
def timeout(self):
def timeout(self) -> int:
return self.max_tries * self.sleep_time


Expand Down
9 changes: 6 additions & 3 deletions core/testcontainers/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import platform
import subprocess
import sys
from typing import Any, Optional

LINUX = "linux"
MAC = "mac"
Expand All @@ -18,14 +19,15 @@
return logger


def os_name() -> str:
def os_name() -> Optional[str]:
pl = sys.platform
if pl == "linux" or pl == "linux2":
return LINUX
elif pl == "darwin":
return MAC
elif pl == "win32":
return WIN
return None

Check warning on line 30 in core/testcontainers/core/utils.py

View check run for this annotation

Codecov / codecov/patch

core/testcontainers/core/utils.py#L30

Added line #L30 was not covered by tests


def is_mac() -> bool:
Expand Down Expand Up @@ -53,7 +55,7 @@
return os.path.exists("/.dockerenv")


def default_gateway_ip() -> str:
def default_gateway_ip() -> Optional[str]:
"""
Returns gateway IP address of the host that testcontainer process is
running on
Expand All @@ -66,11 +68,12 @@
ip_address = process.communicate()[0]
if ip_address and process.returncode == 0:
return ip_address.decode("utf-8").strip().strip("\n")
return None

Check warning on line 71 in core/testcontainers/core/utils.py

View check run for this annotation

Codecov / codecov/patch

core/testcontainers/core/utils.py#L71

Added line #L71 was not covered by tests
except subprocess.SubprocessError:
return None


def raise_for_deprecated_parameter(kwargs: dict, name: str, replacement: str) -> dict:
def raise_for_deprecated_parameter(kwargs: dict[Any, Any], name: str, replacement: str) -> dict[Any, Any]:
"""
Raise an error if a dictionary of keyword arguments contains a key and suggest the replacement.
"""
Expand Down