-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33fb552
commit 30d3172
Showing
6 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.. autoclass:: testcontainers.testmoduleimport.NewSubModuleContainer | ||
.. title:: testcontainers.testmoduleimport.NewSubModuleContainer |
1 change: 1 addition & 0 deletions
1
modules/testmoduleimport/testcontainers/testmoduleimport/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .new_sub_module import NewSubModuleContainer # noqa: F401 |
27 changes: 27 additions & 0 deletions
27
modules/testmoduleimport/testcontainers/testmoduleimport/new_sub_module.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters