Skip to content

Commit 30d3172

Browse files
committed
[TEMP] Test module import
1 parent 33fb552 commit 30d3172

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed

modules/testmoduleimport/README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.. autoclass:: testcontainers.testmoduleimport.NewSubModuleContainer
2+
.. title:: testcontainers.testmoduleimport.NewSubModuleContainer
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .new_sub_module import NewSubModuleContainer # noqa: F401
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from testcontainers.generic.server import ServerContainer
2+
3+
4+
class NewSubModuleContainer(ServerContainer):
5+
"""
6+
This class is a mock container for testing purposes. It is used to test importing from other modules.
7+
8+
.. doctest::
9+
10+
>>> import httpx
11+
>>> from testcontainers.core.image import DockerImage
12+
>>> from testcontainers.testmoduleimport import NewSubModuleContainer
13+
14+
>>> with DockerImage(path="./modules/generic/tests/samples/python_server", tag="test-mod:latest") as image:
15+
... with NewSubModuleContainer(port=9000, image=image) as srv:
16+
... url = srv._create_connection_url()
17+
... response = httpx.get(f"{url}", timeout=5)
18+
... assert response.status_code == 200, "Response status code is not 200"
19+
... assert srv.print_mock() == "NewSubModuleContainer"
20+
21+
"""
22+
23+
def __init__(self, port: int, image: str) -> None:
24+
super().__init__(port, image)
25+
26+
def print_mock(self) -> str:
27+
return "NewSubModuleContainer"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import httpx
2+
3+
from testcontainers.core.waiting_utils import wait_for_logs
4+
from testcontainers.core.image import DockerImage
5+
from testcontainers.testmoduleimport import NewSubModuleContainer
6+
7+
8+
def test_like_doctest():
9+
with DockerImage(path="./modules/generic/tests/samples/python_server", tag="test-srv:latest") as image:
10+
with NewSubModuleContainer(port=9000, image=image) as srv:
11+
assert srv.print_mock() == "NewSubModuleContainer"
12+
url = srv._create_connection_url()
13+
response = httpx.get(f"{url}", timeout=5)
14+
assert response.status_code == 200, "Response status code is not 200"
15+
_ = wait_for_logs(srv, "GET / HTTP/1.1")

poetry.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ packages = [
3636
{ include = "testcontainers", from = "modules/cockroachdb" },
3737
{ include = "testcontainers", from = "modules/elasticsearch" },
3838
{ include = "testcontainers", from = "modules/generic" },
39+
{ include = "testcontainers", from = "modules/testmoduleimport"},
3940
{ include = "testcontainers", from = "modules/google" },
4041
{ include = "testcontainers", from = "modules/influxdb" },
4142
{ include = "testcontainers", from = "modules/k3s" },
@@ -114,6 +115,7 @@ clickhouse = ["clickhouse-driver"]
114115
cockroachdb = []
115116
elasticsearch = []
116117
generic = ["httpx"]
118+
testmoduleimport = ["httpx"]
117119
google = ["google-cloud-pubsub", "google-cloud-datastore"]
118120
influxdb = ["influxdb", "influxdb-client"]
119121
k3s = ["kubernetes", "pyyaml"]

0 commit comments

Comments
 (0)