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

docs: missing compose html from old docs #776

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions compose.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Docker Compose
==============

Docker compose is described in :ref:`Testcontainers Core`.
1 change: 1 addition & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx.ext.autosectionlabel",
]

# Configure autodoc to avoid excessively long fully-qualified names.
Expand Down
19 changes: 18 additions & 1 deletion core/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@ Testcontainers Core

:code:`testcontainers-core` is the core functionality for spinning up Docker containers in test environments.

.. autoclass:: testcontainers.core.container.DockerContainer
.. automodule:: testcontainers.core.container
:members:
:undoc-members:

.. automodule:: testcontainers.core.network
:members:

.. autoclass:: testcontainers.core.image.DockerImage

.. autoclass:: testcontainers.core.generic.DbContainer

.. raw:: html

<hr>

Compose
-------

It is also possible to use Docker Compose functionality:

.. automodule:: testcontainers.compose.compose
:members:

.. raw:: html

<hr>
Expand Down
18 changes: 9 additions & 9 deletions core/testcontainers/compose/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ class DockerCompose:

>>> from testcontainers.compose import DockerCompose

>>> compose = DockerCompose("compose/tests", compose_file_name="docker-compose-4.yml",
>>> compose = DockerCompose("core/tests/compose_fixtures/basic", compose_file_name="hello.yaml",
... pull=True)
>>> with compose:
... stdout, stderr = compose.get_logs()
>>> b"Hello from Docker!" in stdout
>>> "Hello from Docker!" in stdout
True

.. code-block:: yaml
Expand Down Expand Up @@ -189,7 +189,7 @@ def docker_compose_command(self) -> list[str]:
Returns command parts used for the docker compose commands

Returns:
cmd: Docker compose command parts.
list[str]: Docker compose command parts.
"""
return self.compose_command_property

Expand Down Expand Up @@ -255,8 +255,8 @@ def get_logs(self, *services: str) -> tuple[str, str]:
:param services: which services to get the logs for (or omit, for all)

Returns:
stdout: Standard output stream.
stderr: Standard error stream.
str: stdout: Standard output stream.
str: stderr: Standard error stream.
"""
logs_cmd = [*self.compose_command_property, "logs", *services]

Expand Down Expand Up @@ -356,15 +356,15 @@ def exec_in_container(

Args:
service_name: Name of the docker compose service to run the command in.
command: Command to execute.
command: Command to execute.

:param service_name: specify the service name
:param command: the command to run in the container

Returns:
stdout: Standard output stream.
stderr: Standard error stream.
exit_code: The command's exit code.
str: stdout: Standard output stream.
str: stderr: Standard error stream.
int: exit_code: The command's exit code.
"""
if not service_name:
service_name = self.get_container().Service
Expand Down
7 changes: 7 additions & 0 deletions core/testcontainers/core/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ def get_wrapped_container(self) -> "Container":
return self._container

def get_docker_client(self) -> DockerClient:
"""
:meta private:
"""
return self._docker

def get_logs(self) -> tuple[bytes, bytes]:
Expand All @@ -190,6 +193,10 @@ def _configure(self) -> None:


class Reaper:
"""
:meta private:
"""

_instance: "Optional[Reaper]" = None
_container: Optional[DockerContainer] = None
_socket: Optional[socket] = None
Expand Down
8 changes: 8 additions & 0 deletions core/tests/compose_fixtures/basic/hello.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
hello:
image: alpine:latest
init: true
command:
- sh
- -c
- 'while true; do echo "Hello from Docker!"; sleep 1; done'
1 change: 1 addition & 0 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ testcontainers-python facilitates the use of Docker containers for functional an
:maxdepth: 1

core/README
compose
modules/index

Getting Started
Expand Down