Skip to content

Commit 35fc247

Browse files
Merge pull request #334 from tillahoffmann/doctest
Add missing doctests.
2 parents a1aceac + 62d7562 commit 35fc247

File tree

10 files changed

+141
-65
lines changed

10 files changed

+141
-65
lines changed

compose/testcontainers/compose/__init__.py

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,20 @@ class DockerCompose:
2323
2424
.. doctest::
2525
26-
compose_filename = ["docker-compose-1.yml", "docker-compose-2.yml"]
27-
with DockerCompose("/home/project", compose_file_name=compose_file_name, pull=True) as \
28-
compose:
29-
host = compose.get_service_host("hub", 4444)
30-
port = compose.get_service_port("hub", 4444)
31-
driver = webdriver.Remote(
32-
command_executor=(f"http://{host}:{port}/wd/hub"),
33-
desired_capabilities=CHROME,
34-
)
35-
driver.get("http://automation-remarks.com")
36-
stdout, stderr = compose.get_logs()
37-
if stderr:
38-
print(f"Errors\\n:{stderr}")
26+
>>> from testcontainers.compose import DockerCompose
27+
28+
>>> compose = DockerCompose("compose/tests", compose_file_name="docker-compose-4.yml",
29+
... pull=True)
30+
>>> with compose:
31+
... stdout, stderr = compose.get_logs()
32+
>>> b"Hello from Docker!" in stdout
33+
True
3934
4035
.. code-block:: yaml
4136
42-
hub:
43-
image: selenium/hub
44-
ports:
45-
- "4444:4444"
46-
firefox:
47-
image: selenium/node-firefox
48-
links:
49-
- hub
50-
expose:
51-
- "5555"
52-
chrome:
53-
image: selenium/node-chrome
54-
links:
55-
- hub
56-
expose:
57-
- "5555"
37+
services:
38+
hello-world:
39+
image: "hello-world"
5840
"""
5941
def __init__(
6042
self,

google/testcontainers/google/pubsub.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ class PubSubContainer(DockerContainer):
3030
3131
.. doctest::
3232
33-
def test_docker_run_pubsub():
34-
config = PubSubContainer('google/cloud-sdk:emulators')
35-
with config as pubsub:
36-
publisher = pubsub.get_publisher()
37-
topic_path = publisher.topic_path(pubsub.project, "my-topic")
38-
topic = publisher.create_topic(topic_path)
33+
>>> from testcontainers.google import PubSubContainer
34+
35+
>>> config = PubSubContainer()
36+
>>> with config as pubsub:
37+
... publisher = pubsub.get_publisher_client()
38+
... topic_path = publisher.topic_path(pubsub.project, "my-topic")
39+
... topic = publisher.create_topic(name=topic_path)
3940
"""
4041
def __init__(self, image: str = "google/cloud-sdk:emulators", project: str = "test-project",
4142
port: int = 8432, **kwargs) -> None:

localstack/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
long_description_content_type="text/x-rst",
1212
url="https://github.com/testcontainers/testcontainers-python",
1313
install_requires=[
14+
"boto3",
1415
"testcontainers-core",
1516
],
1617
python_requires=">=3.7",

localstack/testcontainers/localstack/__init__.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1111
# License for the specific language governing permissions and limitations
1212
# under the License.
13+
import boto3
14+
import functools as ft
15+
import os
1316
from testcontainers.core.waiting_utils import wait_for_logs
1417
from testcontainers.core.container import DockerContainer
18+
from typing import Any, Optional
1519

1620

1721
class LocalStackContainer(DockerContainer):
@@ -24,23 +28,21 @@ class LocalStackContainer(DockerContainer):
2428
2529
>>> from testcontainers.localstack import LocalStackContainer
2630
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...>
31-
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
31+
>>> with LocalStackContainer(image="localstack/localstack:2.0.1") as localstack:
32+
... dynamo_client = localstack.get_client("dynamodb")
33+
... tables = dynamo_client.list_tables()
34+
>>> tables
35+
{'TableNames': [], ...}
3836
"""
39-
def __init__(self, image: str = 'localstack/localstack:0.11.4', edge_port: int = 4566,
40-
**kwargs) -> None:
37+
def __init__(self, image: str = 'localstack/localstack:2.0.1', edge_port: int = 4566,
38+
region_name: Optional[str] = None, **kwargs) -> None:
4139
super(LocalStackContainer, self).__init__(image, **kwargs)
4240
self.edge_port = edge_port
41+
self.region_name = region_name or os.environ.get("AWS_DEFAULT_REGION", "us-west-1")
4342
self.with_exposed_ports(self.edge_port)
43+
self.with_env("AWS_DEFAULT_REGION", self.region_name)
44+
self.with_env("AWS_ACCESS_KEY_ID", "testcontainers-localstack")
45+
self.with_env("AWS_SECRET_ACCESS_KEY", "testcontainers-localstack")
4446

4547
def with_services(self, *services) -> "LocalStackContainer":
4648
"""
@@ -64,6 +66,17 @@ def get_url(self) -> str:
6466
port = self.get_exposed_port(self.edge_port)
6567
return f'http://{host}:{port}'
6668

69+
@ft.wraps(boto3.client)
70+
def get_client(self, name, **kwargs) -> Any:
71+
kwargs_ = {
72+
"endpoint_url": self.get_url(),
73+
"region_name": self.region_name,
74+
"aws_access_key_id": "testcontainers-localstack",
75+
"aws_secret_access_key": "testcontainers-localstack",
76+
}
77+
kwargs_.update(kwargs)
78+
return boto3.client(name, **kwargs_)
79+
6780
def start(self, timeout: float = 60) -> "LocalStackContainer":
6881
super().start()
6982
wait_for_logs(self, r'Ready\.\n', timeout=timeout)

localstack/tests/test_localstack.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ def test_docker_run_localstack():
1010
services = json.loads(resp.read().decode())['services']
1111

1212
# Check that all services are running
13-
assert all(value == 'running' for value in services.values())
13+
assert all(value == 'available' for value in services.values())
1414
# Check that some of the services keys
15-
assert all(test_service in services.keys() for test_service in ['dynamodb', 'sns', 'sqs'])
15+
assert all(test_service in services for test_service in ['dynamodb', 'sns', 'sqs'])
16+
17+
18+
def test_localstack_boto3():
19+
from testcontainers.localstack import LocalStackContainer
20+
21+
with LocalStackContainer(image="localstack/localstack:2.0.1") as localstack:
22+
dynamo_client = localstack.get_client("dynamodb")
23+
tables = dynamo_client.list_tables()
24+
assert tables["TableNames"] == []

requirements/3.10.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,20 @@ attrs==22.2.0
8888
# trio
8989
azure-core==1.26.4
9090
# via azure-storage-blob
91-
azure-storage-blob==12.15.0
91+
azure-storage-blob==12.16.0
9292
# via testcontainers-azurite
9393
babel==2.12.1
9494
# via sphinx
9595
bcrypt==4.0.1
9696
# via paramiko
9797
bleach==6.0.0
9898
# via readme-renderer
99+
boto3==1.26.112
100+
# via testcontainers-localstack
101+
botocore==1.29.112
102+
# via
103+
# boto3
104+
# s3transfer
99105
cachetools==5.3.0
100106
# via google-auth
101107
certifi==2022.12.7
@@ -155,7 +161,7 @@ flake8==3.7.9
155161
# via -r requirements.in
156162
google-api-core[grpc]==2.11.0
157163
# via google-cloud-pubsub
158-
google-auth==2.17.2
164+
google-auth==2.17.3
159165
# via google-api-core
160166
google-cloud-pubsub==2.16.0
161167
# via testcontainers-gcp
@@ -203,6 +209,10 @@ jeepney==0.8.0
203209
# secretstorage
204210
jinja2==3.1.2
205211
# via sphinx
212+
jmespath==1.0.1
213+
# via
214+
# boto3
215+
# botocore
206216
jsonschema==3.2.0
207217
# via docker-compose
208218
kafka-python==2.0.2
@@ -245,7 +255,7 @@ pluggy==1.0.0
245255
# via pytest
246256
proto-plus==1.22.2
247257
# via google-cloud-pubsub
248-
protobuf==4.22.1
258+
protobuf==4.22.3
249259
# via
250260
# google-api-core
251261
# google-cloud-pubsub
@@ -297,6 +307,7 @@ python-arango==7.5.7
297307
# via testcontainers-arangodb
298308
python-dateutil==2.8.2
299309
# via
310+
# botocore
300311
# opensearch-py
301312
# pg8000
302313
python-dotenv==0.21.1
@@ -342,6 +353,8 @@ rsa==4.9
342353
# via
343354
# google-auth
344355
# python-jose
356+
s3transfer==0.6.0
357+
# via boto3
345358
scramp==1.4.4
346359
# via pg8000
347360
secretstorage==3.3.3
@@ -411,6 +424,7 @@ tzlocal==4.3
411424
# via clickhouse-driver
412425
urllib3[socks]==1.26.15
413426
# via
427+
# botocore
414428
# docker
415429
# minio
416430
# opensearch-py

requirements/3.11.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,20 @@ attrs==22.2.0
8888
# trio
8989
azure-core==1.26.4
9090
# via azure-storage-blob
91-
azure-storage-blob==12.15.0
91+
azure-storage-blob==12.16.0
9292
# via testcontainers-azurite
9393
babel==2.12.1
9494
# via sphinx
9595
bcrypt==4.0.1
9696
# via paramiko
9797
bleach==6.0.0
9898
# via readme-renderer
99+
boto3==1.26.112
100+
# via testcontainers-localstack
101+
botocore==1.29.112
102+
# via
103+
# boto3
104+
# s3transfer
99105
cachetools==5.3.0
100106
# via google-auth
101107
certifi==2022.12.7
@@ -152,7 +158,7 @@ flake8==3.7.9
152158
# via -r requirements.in
153159
google-api-core[grpc]==2.11.0
154160
# via google-cloud-pubsub
155-
google-auth==2.17.2
161+
google-auth==2.17.3
156162
# via google-api-core
157163
google-cloud-pubsub==2.16.0
158164
# via testcontainers-gcp
@@ -200,6 +206,10 @@ jeepney==0.8.0
200206
# secretstorage
201207
jinja2==3.1.2
202208
# via sphinx
209+
jmespath==1.0.1
210+
# via
211+
# boto3
212+
# botocore
203213
jsonschema==3.2.0
204214
# via docker-compose
205215
kafka-python==2.0.2
@@ -242,7 +252,7 @@ pluggy==1.0.0
242252
# via pytest
243253
proto-plus==1.22.2
244254
# via google-cloud-pubsub
245-
protobuf==4.22.1
255+
protobuf==4.22.3
246256
# via
247257
# google-api-core
248258
# google-cloud-pubsub
@@ -294,6 +304,7 @@ python-arango==7.5.7
294304
# via testcontainers-arangodb
295305
python-dateutil==2.8.2
296306
# via
307+
# botocore
297308
# opensearch-py
298309
# pg8000
299310
python-dotenv==0.21.1
@@ -339,6 +350,8 @@ rsa==4.9
339350
# via
340351
# google-auth
341352
# python-jose
353+
s3transfer==0.6.0
354+
# via boto3
342355
scramp==1.4.4
343356
# via pg8000
344357
secretstorage==3.3.3
@@ -404,6 +417,7 @@ tzlocal==4.3
404417
# via clickhouse-driver
405418
urllib3[socks]==1.26.15
406419
# via
420+
# botocore
407421
# docker
408422
# minio
409423
# opensearch-py

requirements/3.7.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ attrs==22.2.0
8888
# trio
8989
azure-core==1.26.4
9090
# via azure-storage-blob
91-
azure-storage-blob==12.15.0
91+
azure-storage-blob==12.16.0
9292
# via testcontainers-azurite
9393
babel==2.12.1
9494
# via sphinx
@@ -100,6 +100,12 @@ bcrypt==4.0.1
100100
# via paramiko
101101
bleach==6.0.0
102102
# via readme-renderer
103+
boto3==1.26.112
104+
# via testcontainers-localstack
105+
botocore==1.29.112
106+
# via
107+
# boto3
108+
# s3transfer
103109
cached-property==1.5.2
104110
# via docker-compose
105111
cachetools==5.3.0
@@ -161,7 +167,7 @@ flake8==3.7.9
161167
# via -r requirements.in
162168
google-api-core[grpc]==2.11.0
163169
# via google-cloud-pubsub
164-
google-auth==2.17.2
170+
google-auth==2.17.3
165171
# via google-api-core
166172
google-cloud-pubsub==2.16.0
167173
# via testcontainers-gcp
@@ -219,6 +225,10 @@ jeepney==0.8.0
219225
# secretstorage
220226
jinja2==3.1.2
221227
# via sphinx
228+
jmespath==1.0.1
229+
# via
230+
# boto3
231+
# botocore
222232
jsonschema==3.2.0
223233
# via docker-compose
224234
kafka-python==2.0.2
@@ -261,7 +271,7 @@ pluggy==1.0.0
261271
# via pytest
262272
proto-plus==1.22.2
263273
# via google-cloud-pubsub
264-
protobuf==4.22.1
274+
protobuf==4.22.3
265275
# via
266276
# google-api-core
267277
# google-cloud-pubsub
@@ -313,6 +323,7 @@ python-arango==7.5.6
313323
# via testcontainers-arangodb
314324
python-dateutil==2.8.2
315325
# via
326+
# botocore
316327
# opensearch-py
317328
# pg8000
318329
python-dotenv==0.21.1
@@ -359,6 +370,8 @@ rsa==4.9
359370
# via
360371
# google-auth
361372
# python-jose
373+
s3transfer==0.6.0
374+
# via boto3
362375
scramp==1.4.4
363376
# via pg8000
364377
secretstorage==3.3.3
@@ -434,6 +447,7 @@ tzlocal==4.3
434447
# via clickhouse-driver
435448
urllib3[socks]==1.26.15
436449
# via
450+
# botocore
437451
# docker
438452
# minio
439453
# opensearch-py

0 commit comments

Comments
 (0)