Skip to content

Commit 69900da

Browse files
committed
1 parent dee53c6 commit 69900da

File tree

20 files changed

+260
-261
lines changed

20 files changed

+260
-261
lines changed

arangodb/testcontainers/arangodb/__init__.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ class ArangoDbContainer(DbContainer):
1212
"""
1313
ArangoDB container.
1414
15-
Example
16-
-------
17-
The example will spin up a ArangoDB container.
18-
You may use the :code:`get_connection_url()` method which returns a arangoclient-compatible url
19-
in format :code:`scheme://host:port`. As of now, only a single host is supported (over HTTP).
15+
Example:
2016
21-
.. doctest::
17+
This example spins up an ArangoDB container. You may use the :code:`get_connection_url()`
18+
method which returns a arangoclient-compatible url in format :code:`scheme://host:port`. As
19+
of now, only a single host is supported (over HTTP).
2220
23-
>>> from testcontainers.arangodb import ArangoDbContainer
24-
>>> from arango import ArangoClient
21+
.. doctest::
2522
26-
>>> with ArangoDbContainer("arangodb:3.9.1") as arango:
27-
... client = ArangoClient(hosts=arango.get_connection_url())
28-
...
29-
... # Connect
30-
... sys_db = client.db(username="root", password="passwd")
31-
...
32-
... # Create a new database named "test".
33-
... sys_db.create_database("test")
34-
True
23+
>>> from testcontainers.arangodb import ArangoDbContainer
24+
>>> from arango import ArangoClient
25+
26+
>>> with ArangoDbContainer("arangodb:3.9.1") as arango:
27+
... client = ArangoClient(hosts=arango.get_connection_url())
28+
...
29+
... # Connect
30+
... sys_db = client.db(username="root", password="passwd")
31+
...
32+
... # Create a new database named "test".
33+
... sys_db.create_database("test")
34+
True
3535
"""
3636

3737
def __init__(self,

azurite/testcontainers/azurite/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ class AzuriteContainer(DockerContainer):
2525
:code:`get_connection_string` can be used to create a client for Blob service, Queue service
2626
and Table service.
2727
28-
Example
29-
-------
30-
.. doctest::
31-
32-
>>> from testcontainers.azurite import AzuriteContainer
33-
>>> from azure.storage.blob import BlobServiceClient
34-
35-
>>> with AzuriteContainer() as azurite_container:
36-
... connection_string = azurite_container.get_connection_string()
37-
... client = BlobServiceClient.from_connection_string(
38-
... connection_string,
39-
... api_version="2019-12-12"
40-
... )
28+
Example:
29+
30+
.. doctest::
31+
32+
>>> from testcontainers.azurite import AzuriteContainer
33+
>>> from azure.storage.blob import BlobServiceClient
34+
35+
>>> with AzuriteContainer() as azurite_container:
36+
... connection_string = azurite_container.get_connection_string()
37+
... client = BlobServiceClient.from_connection_string(
38+
... connection_string,
39+
... api_version="2019-12-12"
40+
... )
4141
"""
4242

4343
_AZURITE_ACCOUNT_NAME = os.environ.get("AZURITE_ACCOUNT_NAME", "devstoreaccount1")

clickhouse/testcontainers/clickhouse/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ class ClickHouseContainer(DbContainer):
2424
"""
2525
ClickHouse database container.
2626
27-
Example
28-
-------
29-
The example spins up a ClickHouse database and connects to it
30-
using the :code:`clickhouse-driver`.
27+
Example:
3128
32-
.. doctest::
29+
The example spins up a ClickHouse database and connects to it using the
30+
:code:`clickhouse-driver`.
3331
34-
>>> import clickhouse_driver
35-
>>> from testcontainers.clickhouse import ClickHouseContainer
32+
.. doctest::
3633
37-
>>> with ClickHouseContainer("clickhouse/clickhouse-server:21.8") as clickhouse:
38-
... client = clickhouse_driver.Client.from_url(clickhouse.get_connection_url())
39-
... client.execute("select 'working'")
40-
[('working',)]
34+
>>> import clickhouse_driver
35+
>>> from testcontainers.clickhouse import ClickHouseContainer
36+
37+
>>> with ClickHouseContainer("clickhouse/clickhouse-server:21.8") as clickhouse:
38+
... client = clickhouse_driver.Client.from_url(clickhouse.get_connection_url())
39+
... client.execute("select 'working'")
40+
[('working',)]
4141
"""
4242

4343
CLICKHOUSE_USER = os.environ.get("CLICKHOUSE_USER", "test")

compose/testcontainers/compose/__init__.py

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,44 @@ class DockerCompose:
2424
build: Build images referenced in the configuration file.
2525
env_file: Path to an env file containing environment variables to pass to docker compose.
2626
27-
Example
28-
-------
29-
.. doctest::
30-
31-
with DockerCompose("/home/project",
32-
compose_file_name=["docker-compose-1.yml", "docker-compose-2.yml"],
33-
pull=True) as compose:
34-
host = compose.get_service_host("hub", 4444)
35-
port = compose.get_service_port("hub", 4444)
36-
driver = webdriver.Remote(
37-
command_executor=("http://{}:{}/wd/hub".format(host,port)),
38-
desired_capabilities=CHROME,
39-
)
40-
driver.get("http://automation-remarks.com")
41-
stdout, stderr = compose.get_logs()
42-
if stderr:
43-
print("Errors\\n:{}".format(stderr))
44-
45-
46-
.. code-block:: yaml
47-
48-
hub:
49-
image: selenium/hub
50-
ports:
51-
- "4444:4444"
52-
firefox:
53-
image: selenium/node-firefox
54-
links:
55-
- hub
56-
expose:
57-
- "5555"
58-
chrome:
59-
image: selenium/node-chrome
60-
links:
61-
- hub
62-
expose:
63-
- "5555"
27+
Example:
28+
29+
This example spins up chrome and firefox containers using docker compose.
30+
31+
.. doctest::
32+
33+
compose_filename = ["docker-compose-1.yml", "docker-compose-2.yml"]
34+
with DockerCompose("/home/project", compose_file_name=compose_file_name, pull=True) as \
35+
compose:
36+
host = compose.get_service_host("hub", 4444)
37+
port = compose.get_service_port("hub", 4444)
38+
driver = webdriver.Remote(
39+
command_executor=("http://{}:{}/wd/hub".format(host,port)),
40+
desired_capabilities=CHROME,
41+
)
42+
driver.get("http://automation-remarks.com")
43+
stdout, stderr = compose.get_logs()
44+
if stderr:
45+
print("Errors\\n:{}".format(stderr))
46+
47+
.. code-block:: yaml
48+
49+
hub:
50+
image: selenium/hub
51+
ports:
52+
- "4444:4444"
53+
firefox:
54+
image: selenium/node-firefox
55+
links:
56+
- hub
57+
expose:
58+
- "5555"
59+
chrome:
60+
image: selenium/node-chrome
61+
links:
62+
- hub
63+
expose:
64+
- "5555"
6465
"""
6566
def __init__(
6667
self,

elasticsearch/testcontainers/elasticsearch/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ class ElasticSearchContainer(DockerContainer):
5858
"""
5959
ElasticSearch container.
6060
61-
Example
62-
-------
63-
.. doctest::
64-
65-
>>> import json
66-
>>> import urllib
67-
>>> from testcontainers.elasticsearch import ElasticSearchContainer
68-
69-
>>> with ElasticSearchContainer(f'elasticsearch:8.3.3') as es:
70-
... resp = urllib.request.urlopen(es.get_url())
71-
... json.loads(resp.read().decode())['version']['number']
72-
'8.3.3'
61+
Example:
62+
63+
.. doctest::
64+
65+
>>> import json
66+
>>> import urllib
67+
>>> from testcontainers.elasticsearch import ElasticSearchContainer
68+
69+
>>> with ElasticSearchContainer(f'elasticsearch:8.3.3') as es:
70+
... resp = urllib.request.urlopen(es.get_url())
71+
... json.loads(resp.read().decode())['version']['number']
72+
'8.3.3'
7373
"""
7474

7575
def __init__(self, image="elasticsearch", port_to_expose=9200, **kwargs) -> None:

google/testcontainers/google/pubsub.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ class PubSubContainer(DockerContainer):
2020
"""
2121
PubSub container for testing managed message queues.
2222
23-
Example
24-
-------
25-
The example will spin up a Google Cloud PubSub emulator that you can use for integration tests.
26-
The :code:`pubsub` instance provides convenience methods :code:`get_publisher` and
27-
:code:`get_subscriber` to connect to the emulator without having to set the environment variable
28-
:code:`PUBSUB_EMULATOR_HOST`.
23+
Example:
2924
30-
.. doctest::
25+
The example will spin up a Google Cloud PubSub emulator that you can use for integration
26+
tests. The :code:`pubsub` instance provides convenience methods :code:`get_publisher` and
27+
:code:`get_subscriber` to connect to the emulator without having to set the environment
28+
variable :code:`PUBSUB_EMULATOR_HOST`.
3129
32-
def test_docker_run_pubsub():
33-
config = PubSubContainer('google/cloud-sdk:emulators')
34-
with config as pubsub:
35-
publisher = pubsub.get_publisher()
36-
topic_path = publisher.topic_path(pubsub.project, "my-topic")
37-
topic = publisher.create_topic(topic_path)
30+
.. doctest::
31+
32+
def test_docker_run_pubsub():
33+
config = PubSubContainer('google/cloud-sdk:emulators')
34+
with config as pubsub:
35+
publisher = pubsub.get_publisher()
36+
topic_path = publisher.topic_path(pubsub.project, "my-topic")
37+
topic = publisher.create_topic(topic_path)
3838
"""
3939
def __init__(self, image: str = "google/cloud-sdk:emulators", project: str = "test-project",
4040
port: int = 8432, **kwargs) -> None:

kafka/testcontainers/kafka/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ class KafkaContainer(DockerContainer):
1414
"""
1515
Kafka container.
1616
17-
Example
18-
-------
19-
.. doctest::
17+
Example:
2018
21-
>>> from testcontainers.kafka import KafkaContainer
19+
.. doctest::
2220
23-
>>> with KafkaContainer() as kafka:
24-
... connection = kafka.get_bootstrap_server()
21+
>>> from testcontainers.kafka import KafkaContainer
22+
23+
>>> with KafkaContainer() as kafka:
24+
... connection = kafka.get_bootstrap_server()
2525
"""
2626
KAFKA_PORT = 9093
2727
TC_START_SCRIPT = '/tc-start.sh'

keycloak/testcontainers/keycloak/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class KeycloakContainer(DockerContainer):
2323
"""
2424
Keycloak container.
2525
26-
Example
27-
-------
28-
.. doctest::
26+
Example:
2927
30-
>>> from testcontainers.keycloak import KeycloakContainer
28+
.. doctest::
3129
32-
>>> with KeycloakContainer() as kc:
33-
... keycloak = kc.get_client()
30+
>>> from testcontainers.keycloak import KeycloakContainer
31+
32+
>>> with KeycloakContainer() as kc:
33+
... keycloak = kc.get_client()
3434
"""
3535
KEYCLOAK_USER = os.environ.get("KEYCLOAK_USER", "test")
3636
KEYCLOAK_PASSWORD = os.environ.get("KEYCLOAK_PASSWORD", "test")

localstack/testcontainers/localstack/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ class LocalStackContainer(DockerContainer):
1818
"""
1919
Localstack container.
2020
21-
Example
22-
-------
23-
.. doctest::
21+
Example:
2422
25-
>>> from testcontainers.localstack import LocalStackContainer
23+
.. doctest::
2624
27-
>>> with LocalStackContainer(image="localstack/localstack:0.11.4") as localstack:
28-
... localstack.with_services("dynamodb", "lambda")
29-
... dynamo_endpoint = localstack.get_url()
30-
<testcontainers.localstack.LocalStackContainer object at 0x...>
25+
>>> from testcontainers.localstack import LocalStackContainer
3126
32-
The endpoint can be used to create a client with the boto3 library:
33-
.. doctest::
27+
>>> with LocalStackContainer(image="localstack/localstack:0.11.4") as localstack:
28+
... localstack.with_services("dynamodb", "lambda")
29+
... dynamo_endpoint = localstack.get_url()
30+
<testcontainers.localstack.LocalStackContainer object at 0x...>
3431
35-
dynamo_client = boto3.client("dynamodb", endpoint_url=dynamo_endpoint)
36-
scan_result = dynamo_client.scan(TableName='foo')
37-
# Do something with the scan result
32+
The endpoint can be used to create a client with the boto3 library:
33+
.. doctest::
34+
35+
dynamo_client = boto3.client("dynamodb", endpoint_url=dynamo_endpoint)
36+
scan_result = dynamo_client.scan(TableName='foo')
37+
# Do something with the scan result
3838
"""
3939
def __init__(self, image: str = 'localstack/localstack:0.11.4', edge_port: int = 4566,
4040
**kwargs) -> None:

minio/testcontainers/minio/__init__.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ class MinioContainer(DockerContainer):
1414
The method :code:`get_config` can be used to retrieve the endpoint, access key
1515
and secret key of the container.
1616
17-
Example
18-
-------
19-
.. doctest::
17+
Example:
2018
21-
>>> import io
22-
>>> from testcontainers.minio import MinioContainer
19+
.. doctest::
2320
24-
>>> with MinioContainer() as minio:
25-
... client = minio.get_client()
26-
... client.make_bucket("test")
27-
... test_content = b"Hello World"
28-
... write_result = client.put_object(
29-
... "test",
30-
... "testfile.txt",
31-
... io.BytesIO(test_content),
32-
... length=len(test_content),
33-
... )
34-
... retrieved_content = client.get_object("test", "testfile.txt").data
21+
>>> import io
22+
>>> from testcontainers.minio import MinioContainer
23+
24+
>>> with MinioContainer() as minio:
25+
... client = minio.get_client()
26+
... client.make_bucket("test")
27+
... test_content = b"Hello World"
28+
... write_result = client.put_object(
29+
... "test",
30+
... "testfile.txt",
31+
... io.BytesIO(test_content),
32+
... length=len(test_content),
33+
... )
34+
... retrieved_content = client.get_object("test", "testfile.txt").data
3535
"""
3636

3737
def __init__(self, image: str = "minio/minio:RELEASE.2022-12-02T19-19-22Z",

0 commit comments

Comments
 (0)