Skip to content

Commit 972cc30

Browse files
committed
chore: update poetry and tests to support arm machines
1 parent e9e40f9 commit 972cc30

File tree

9 files changed

+58
-4
lines changed

9 files changed

+58
-4
lines changed

Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,28 @@
33

44
PYTHON_VERSION ?= 3.10
55
IMAGE = testcontainers-python:${PYTHON_VERSION}
6-
PACKAGES = core $(addprefix modules/,$(notdir $(wildcard modules/*)))
6+
PACKAGES = core $(addprefix modules/,$(notdir $(filter %/, $(wildcard modules/*/))))
77

88
UPLOAD = $(addsuffix /upload,${PACKAGES})
9-
TESTS = $(addsuffix /tests,$(filter-out meta,${PACKAGES}))
9+
TESTS = $(addsuffix /tests,$(filter-out meta,$(filter-out %.md %.txt,${PACKAGES})))
1010
TESTS_DIND = $(addsuffix -dind,${TESTS})
1111
DOCTESTS = $(addsuffix /doctests,$(filter-out modules/README.md,${PACKAGES}))
1212

13+
ARCH := $(shell uname -m)
14+
ARM_ARCHS := arm64 aarch64
15+
IS_ARM := $(filter $(ARCH),$(ARM_ARCHS))
16+
17+
# List of safe extras (excluding 'db2') with original TOML keys
18+
EXTRAS_LIST := $(shell $(PYTHON) scripts/list_arm_extras.py)
1319

1420
install: ## Set up the project for development
21+
ifeq ($(IS_ARM),$(ARCH))
22+
@echo "Detected ARM architecture, skipping 'db2' extra (ibm-db is incompatible)"
23+
poetry install $(foreach extra,$(EXTRAS_LIST),--extras $(extra))
24+
else
25+
@echo "Detected non-ARM architecture, installing all extras"
1526
poetry install --all-extras
27+
endif
1628
poetry run pre-commit install
1729

1830
build: ## Build the python package

core/tests/test_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def test_is_windows(monkeypatch: MonkeyPatch) -> None:
3333

3434

3535
def test_is_arm(monkeypatch: MonkeyPatch) -> None:
36-
assert not utils.is_arm()
3736
monkeypatch.setattr("platform.machine", lambda: "arm64")
3837
assert utils.is_arm()
3938
monkeypatch.setattr("platform.machine", lambda: "aarch64")

modules/cosmosdb/tests/test_cosmosdb_emulator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import pytest
22
from testcontainers.cosmosdb._emulator import CosmosDBEmulatorContainer
33

4+
from testcontainers.core.utils import is_arm
45

6+
7+
@pytest.mark.skipif(is_arm(), reason="db2 container not available for ARM")
58
def test_runs():
69
with CosmosDBEmulatorContainer(partition_count=1, bind_ports=False) as emulator:
710
assert emulator.server_certificate_pem is not None

modules/cosmosdb/tests/test_cosmosdb_mongodb.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import pytest
22
from testcontainers.cosmosdb import CosmosDBMongoEndpointContainer
33

4+
from testcontainers.core.utils import is_arm
45

6+
7+
@pytest.mark.skipif(is_arm(), reason="db2 container not available for ARM")
58
def test_requires_a_version():
69
with pytest.raises(AssertionError, match="A MongoDB version is required"):
710
CosmosDBMongoEndpointContainer(mongodb_version=None)
@@ -10,6 +13,7 @@ def test_requires_a_version():
1013
CosmosDBMongoEndpointContainer(mongodb_version="4.0")
1114

1215

16+
@pytest.mark.skipif(is_arm(), reason="db2 container not available for ARM")
1317
def test_runs():
1418
with CosmosDBMongoEndpointContainer(mongodb_version="4.0", partition_count=1, bind_ports=False) as emulator:
1519
assert emulator.env["AZURE_COSMOS_EMULATOR_ENABLE_MONGODB_ENDPOINT"] == "4.0"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import pytest
22
from testcontainers.cosmosdb import CosmosDBNoSQLEndpointContainer
33

4+
from testcontainers.core.utils import is_arm
45

6+
7+
@pytest.mark.skipif(is_arm(), reason="db2 container not available for ARM")
58
def test_runs():
69
with CosmosDBNoSQLEndpointContainer(partition_count=1, bind_ports=False) as emulator:
710
assert emulator.get_exposed_port(8081) is not None, "The NoSQL endpoint's port should be exposed"

modules/db2/tests/test_db2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def test_docker_run_db2(version: str):
2626
# - sqlserver
2727
# - mongodb
2828
# - db2
29+
@pytest.mark.skipif(is_arm(), reason="db2 container not available for ARM")
2930
def test_quoted_password():
3031
user = "db2inst1"
3132
dbname = "testdb"

modules/elasticsearch/tests/test_elasticsearch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
import pytest
55

6+
from testcontainers.core.utils import is_arm
67
from testcontainers.elasticsearch import ElasticSearchContainer
78

89

910
# The versions below should reflect the latest stable releases
1011
@pytest.mark.parametrize("version", ["7.17.18", "8.12.2"])
12+
@pytest.mark.skipif(is_arm(), reason="db2 container not available for ARM")
1113
def test_docker_run_elasticsearch(version):
1214
with ElasticSearchContainer(f"elasticsearch:{version}", mem_limit="3G") as es:
1315
resp = urllib.request.urlopen(es.get_url())

modules/google/tests/test_google.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from queue import Queue
22
from google.cloud.datastore import Entity
33

4+
import time
45
from testcontainers.core.waiting_utils import wait_for_logs
56
from testcontainers.google import PubSubContainer, DatastoreContainer
67

@@ -25,7 +26,8 @@ def test_pubsub_container():
2526
# Receive the message
2627
queue = Queue()
2728
subscriber.subscribe(subscription_path, queue.put)
28-
message = queue.get(timeout=1)
29+
# timeout 10 is needed to account for slower arm machines
30+
message = queue.get(timeout=10)
2931
assert message.data == b"Hello world!"
3032
message.ack()
3133

scripts/list_arm_extras.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
3+
# used to generate the list of extras in the Makefile
4+
import sys
5+
from pathlib import Path
6+
7+
# Support both Python 3.10 (needs tomli) and 3.11+ (has tomllib)
8+
if sys.version_info >= (3, 11):
9+
import tomllib
10+
else:
11+
try:
12+
import tomli as tomllib
13+
except ImportError:
14+
## Python <3.11 detected but 'tomli' is not installed, poetry add --group dev tomli
15+
sys.exit(1)
16+
17+
SKIPPED_EXTRAS = {"db2"} # skip incompatible extras
18+
19+
20+
def get_filtered_extras() -> list[str]:
21+
with Path("pyproject.toml").open("rb") as f:
22+
data = tomllib.load(f)
23+
extras = data["tool"]["poetry"]["extras"]
24+
return [key for key in extras if key not in SKIPPED_EXTRAS]
25+
26+
27+
if __name__ == "__main__":
28+
sys.stdout.write(" ".join(get_filtered_extras()) + "\n")

0 commit comments

Comments
 (0)