Skip to content

Commit

Permalink
[TEMP] Test module import
Browse files Browse the repository at this point in the history
  • Loading branch information
Tranquility2 committed Jun 21, 2024
1 parent 33fb552 commit 30d3172
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions modules/testmoduleimport/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.. autoclass:: testcontainers.testmoduleimport.NewSubModuleContainer
.. title:: testcontainers.testmoduleimport.NewSubModuleContainer
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .new_sub_module import NewSubModuleContainer # noqa: F401
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from testcontainers.generic.server import ServerContainer


class NewSubModuleContainer(ServerContainer):
"""
This class is a mock container for testing purposes. It is used to test importing from other modules.
.. doctest::
>>> import httpx
>>> from testcontainers.core.image import DockerImage
>>> from testcontainers.testmoduleimport import NewSubModuleContainer
>>> with DockerImage(path="./modules/generic/tests/samples/python_server", tag="test-mod:latest") as image:
... with NewSubModuleContainer(port=9000, image=image) as srv:
... url = srv._create_connection_url()
... response = httpx.get(f"{url}", timeout=5)
... assert response.status_code == 200, "Response status code is not 200"
... assert srv.print_mock() == "NewSubModuleContainer"
"""

def __init__(self, port: int, image: str) -> None:
super().__init__(port, image)

def print_mock(self) -> str:
return "NewSubModuleContainer"
15 changes: 15 additions & 0 deletions modules/testmoduleimport/tests/test_mock_one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import httpx

from testcontainers.core.waiting_utils import wait_for_logs
from testcontainers.core.image import DockerImage
from testcontainers.testmoduleimport import NewSubModuleContainer


def test_like_doctest():
with DockerImage(path="./modules/generic/tests/samples/python_server", tag="test-srv:latest") as image:
with NewSubModuleContainer(port=9000, image=image) as srv:
assert srv.print_mock() == "NewSubModuleContainer"
url = srv._create_connection_url()
response = httpx.get(f"{url}", timeout=5)
assert response.status_code == 200, "Response status code is not 200"
_ = wait_for_logs(srv, "GET / HTTP/1.1")
3 changes: 2 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ packages = [
{ include = "testcontainers", from = "modules/cockroachdb" },
{ include = "testcontainers", from = "modules/elasticsearch" },
{ include = "testcontainers", from = "modules/generic" },
{ include = "testcontainers", from = "modules/testmoduleimport"},
{ include = "testcontainers", from = "modules/google" },
{ include = "testcontainers", from = "modules/influxdb" },
{ include = "testcontainers", from = "modules/k3s" },
Expand Down Expand Up @@ -114,6 +115,7 @@ clickhouse = ["clickhouse-driver"]
cockroachdb = []
elasticsearch = []
generic = ["httpx"]
testmoduleimport = ["httpx"]
google = ["google-cloud-pubsub", "google-cloud-datastore"]
influxdb = ["influxdb", "influxdb-client"]
k3s = ["kubernetes", "pyyaml"]
Expand Down

0 comments on commit 30d3172

Please sign in to comment.