1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2025-02-24 01:38:15 +00:00

tests: fixture type hints and style standardization

This commit is contained in:
Nicolas Duchon 2024-12-27 21:36:07 +01:00
parent ea99c1a6f9
commit ae0c9a8e96
3 changed files with 12 additions and 12 deletions

View File

@ -6,7 +6,7 @@ import shlex
import socket import socket
import subprocess import subprocess
import time import time
from typing import List, Optional from typing import Iterator, List, Optional
import backoff import backoff
import docker.errors import docker.errors
@ -330,7 +330,7 @@ def wait_for_nginxproxy_to_be_ready():
@pytest.fixture @pytest.fixture
def docker_compose_file(request: FixtureRequest) -> Optional[str]: def docker_compose_file(request: FixtureRequest) -> Iterator[Optional[str]]:
"""Fixture naming the docker compose file to consider. """Fixture naming the docker compose file to consider.
If a YAML file exists with the same name as the test module (with the `.py` extension replaced If a YAML file exists with the same name as the test module (with the `.py` extension replaced
@ -462,13 +462,13 @@ class DockerComposer(contextlib.AbstractContextManager):
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def docker_composer() -> DockerComposer: def docker_composer() -> Iterator[DockerComposer]:
with DockerComposer() as d: with DockerComposer() as d:
yield d yield d
@pytest.fixture @pytest.fixture
def ca_root_certificate() -> str: def ca_root_certificate() -> Iterator[str]:
yield CA_ROOT_CERTIFICATE yield CA_ROOT_CERTIFICATE
@ -480,7 +480,7 @@ def monkey_patched_dns():
@pytest.fixture @pytest.fixture
def docker_compose(monkey_patched_dns, docker_composer, docker_compose_file) -> DockerClient: def docker_compose(monkey_patched_dns, docker_composer, docker_compose_file) -> Iterator[DockerClient]:
"""Ensures containers described in a docker compose file are started. """Ensures containers described in a docker compose file are started.
A custom docker compose file name can be specified by overriding the `docker_compose_file` A custom docker compose file name can be specified by overriding the `docker_compose_file`
@ -493,8 +493,8 @@ def docker_compose(monkey_patched_dns, docker_composer, docker_compose_file) ->
yield docker_client yield docker_client
@pytest.fixture() @pytest.fixture
def nginxproxy() -> RequestsForDocker: def nginxproxy() -> Iterator[RequestsForDocker]:
""" """
Provides the `nginxproxy` object that can be used in the same way the requests module is: Provides the `nginxproxy` object that can be used in the same way the requests module is:
@ -510,8 +510,8 @@ def nginxproxy() -> RequestsForDocker:
yield RequestsForDocker() yield RequestsForDocker()
@pytest.fixture() @pytest.fixture
def acme_challenge_path() -> str: def acme_challenge_path() -> Iterator[str]:
""" """
Provides fake Let's Encrypt ACME challenge path used in certain tests Provides fake Let's Encrypt ACME challenge path used in certain tests
""" """

View File

@ -7,7 +7,7 @@ import pytest
from docker.errors import NotFound from docker.errors import NotFound
@pytest.fixture() @pytest.fixture
def web1(docker_compose): def web1(docker_compose):
""" """
pytest fixture creating a web container with `VIRTUAL_HOST=web1.nginx-proxy` listening on port 81. pytest fixture creating a web container with `VIRTUAL_HOST=web1.nginx-proxy` listening on port 81.
@ -30,7 +30,7 @@ def web1(docker_compose):
except NotFound: except NotFound:
pass pass
@pytest.fixture() @pytest.fixture
def web2(docker_compose): def web2(docker_compose):
""" """
pytest fixture creating a web container with `VIRTUAL_HOST=nginx-proxy`, `VIRTUAL_PATH=/web2/` and `VIRTUAL_DEST=/` listening on port 82. pytest fixture creating a web container with `VIRTUAL_HOST=nginx-proxy`, `VIRTUAL_PATH=/web2/` and `VIRTUAL_DEST=/` listening on port 82.

View File

@ -23,7 +23,7 @@ def test_invalid_path(docker_compose, nginxproxy, stub):
r = nginxproxy.get(f"http://{stub}/port") r = nginxproxy.get(f"http://{stub}/port")
assert r.status_code in [404, 503] assert r.status_code in [404, 503]
@pytest.fixture() @pytest.fixture
def web4(docker_compose): def web4(docker_compose):
""" """
pytest fixture creating a web container with `VIRTUAL_HOST=nginx-proxy.test`, `VIRTUAL_PATH=/web4/` and `VIRTUAL_DEST=/` listening on port 84. pytest fixture creating a web container with `VIRTUAL_HOST=nginx-proxy.test`, `VIRTUAL_PATH=/web4/` and `VIRTUAL_DEST=/` listening on port 84.