Skip to content
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

Added timezone argument to run and create #579

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions python_on_whales/components/container/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ def create(
systemd: Optional[Union[bool, Literal["always"]]] = None,
tmpfs: List[ValidPath] = [],
tty: bool = False,
tz: Optional[str] = None,
tjd78 marked this conversation as resolved.
Show resolved Hide resolved
ulimit: List[str] = [],
user: Optional[str] = None,
userns: Optional[str] = None,
Expand Down Expand Up @@ -791,6 +792,7 @@ def create(
full_cmd.add_simple_arg("--systemd", systemd)
full_cmd.add_args_list("--tmpfs", tmpfs)
full_cmd.add_flag("--tty", tty)
full_cmd.add_simple_arg("--tz", tz)
full_cmd.add_args_list("--ulimit", ulimit)

full_cmd.add_simple_arg("--user", user)
Expand Down Expand Up @@ -1387,6 +1389,7 @@ def run(
systemd: Optional[Union[bool, Literal["always"]]] = None,
tmpfs: List[ValidPath] = [],
tty: bool = False,
tz: Optional[str] = None,
ulimit: List[str] = [],
user: Optional[str] = None,
userns: Optional[str] = None,
Expand Down Expand Up @@ -1718,6 +1721,7 @@ def run(
full_cmd.add_simple_arg("--systemd", systemd)
full_cmd.add_args_list("--tmpfs", tmpfs)
full_cmd.add_flag("--tty", tty)
full_cmd.add_simple_arg("--tz", tz)
full_cmd.add_args_list("--ulimit", ulimit)

full_cmd.add_simple_arg("--user", user)
Expand Down
16 changes: 16 additions & 0 deletions tests/python_on_whales/components/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ def test_run_with_preserve_fds(podman_client: DockerClient):
):
assert os.read(read_fd, 7) == b"foobar\n"

def test_run_with_timezone(podman_client: DockerClient):
output = podman_client.container.run(
"ubuntu", ["date", "+'%Z'"], tz="local", remove=True
)
# Check the timezone in the container matches that in the host.
assert output == datetime.now().astimezone().strftime("'%Z'")

def test_create_start_with_timezone(podman_client: DockerClient):
LewisGaul marked this conversation as resolved.
Show resolved Hide resolved
with podman_client.container.create(
"ubuntu", ["sleep", "infinity"], tz="GMT", stop_timeout=1
LewisGaul marked this conversation as resolved.
Show resolved Hide resolved
) as container:
container.start()
output = podman_client.execute(container, ["date", "+'%Z'"])
LewisGaul marked this conversation as resolved.
Show resolved Hide resolved
# Check the timezone in the container matches what was specified
assert output == "'GMT'"
LewisGaul marked this conversation as resolved.
Show resolved Hide resolved


@pytest.mark.parametrize(
"ctr_client",
Expand Down
Loading