Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create types module inside tests #2502

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
5 changes: 2 additions & 3 deletions tests/conftest.py
@@ -1,11 +1,10 @@
import functools
from typing import Any, Callable, Dict, Literal
from typing import Any, Dict, Literal

import pytest

from starlette.testclient import TestClient

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


@pytest.fixture
Expand Down
4 changes: 1 addition & 3 deletions tests/middleware/test_base.py
Expand Up @@ -3,7 +3,6 @@
from typing import (
Any,
AsyncGenerator,
Callable,
Generator,
List,
Type,
Expand All @@ -24,8 +23,7 @@
from starlette.testclient import TestClient
from starlette.types import ASGIApp, Message, Receive, Scope, Send
from starlette.websockets import WebSocket

TestClientFactory = Callable[[ASGIApp], TestClient]
from tests.types import TestClientFactory


class CustomMiddleware(BaseHTTPMiddleware):
Expand Down
7 changes: 1 addition & 6 deletions tests/middleware/test_cors.py
@@ -1,15 +1,10 @@
from typing import Callable

from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.middleware.cors import CORSMiddleware
from starlette.requests import Request
from starlette.responses import PlainTextResponse
from starlette.routing import Route
from starlette.testclient import TestClient
from starlette.types import ASGIApp

TestClientFactory = Callable[[ASGIApp], TestClient]
from tests.types import TestClientFactory


def test_cors_allow_all(
Expand Down
6 changes: 2 additions & 4 deletions tests/middleware/test_errors.py
@@ -1,4 +1,4 @@
from typing import Any, Callable
from typing import Any

import pytest

Expand All @@ -8,10 +8,8 @@
from starlette.requests import Request
from starlette.responses import JSONResponse, Response
from starlette.routing import Route
from starlette.testclient import TestClient
from starlette.types import Receive, Scope, Send

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


def test_handler(
Expand Down
7 changes: 1 addition & 6 deletions tests/middleware/test_gzip.py
@@ -1,15 +1,10 @@
from typing import Callable

from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.middleware.gzip import GZipMiddleware
from starlette.requests import Request
from starlette.responses import ContentStream, PlainTextResponse, StreamingResponse
from starlette.routing import Route
from starlette.testclient import TestClient
from starlette.types import ASGIApp

TestClientFactory = Callable[[ASGIApp], TestClient]
from tests.types import TestClientFactory


def test_gzip_responses(test_client_factory: TestClientFactory) -> None:
Expand Down
6 changes: 1 addition & 5 deletions tests/middleware/test_https_redirect.py
@@ -1,14 +1,10 @@
from typing import Callable

from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.middleware.httpsredirect import HTTPSRedirectMiddleware
from starlette.requests import Request
from starlette.responses import PlainTextResponse
from starlette.routing import Route
from starlette.testclient import TestClient

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


def test_https_redirect_middleware(test_client_factory: TestClientFactory) -> None:
Expand Down
4 changes: 1 addition & 3 deletions tests/middleware/test_session.py
@@ -1,5 +1,4 @@
import re
from typing import Callable

from starlette.applications import Starlette
from starlette.middleware import Middleware
Expand All @@ -8,8 +7,7 @@
from starlette.responses import JSONResponse
from starlette.routing import Mount, Route
from starlette.testclient import TestClient

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


def view_session(request: Request) -> JSONResponse:
Expand Down
6 changes: 1 addition & 5 deletions tests/middleware/test_trusted_host.py
@@ -1,14 +1,10 @@
from typing import Callable

from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.middleware.trustedhost import TrustedHostMiddleware
from starlette.requests import Request
from starlette.responses import PlainTextResponse
from starlette.routing import Route
from starlette.testclient import TestClient

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


def test_trusted_host_middleware(test_client_factory: TestClientFactory) -> None:
Expand Down
13 changes: 6 additions & 7 deletions tests/middleware/test_wsgi.py
@@ -1,16 +1,15 @@
import sys
from typing import Any, Callable, Dict, Iterable

import pytest

from starlette._utils import collapse_excgroups
from starlette.middleware.wsgi import WSGIMiddleware, build_environ
from starlette.testclient import TestClient

WSGIResponse = Iterable[bytes]
TestClientFactory = Callable[..., TestClient]
StartResponse = Callable[..., Any]
Environment = Dict[str, Any]
from tests.types import (
Environment,
StartResponse,
TestClientFactory,
WSGIResponse,
)


def hello_world(
Expand Down
5 changes: 2 additions & 3 deletions tests/test_applications.py
@@ -1,7 +1,7 @@
import os
from contextlib import asynccontextmanager
from pathlib import Path
from typing import AsyncGenerator, AsyncIterator, Callable, Generator
from typing import AsyncGenerator, AsyncIterator, Generator

import anyio
import pytest
Expand All @@ -20,8 +20,7 @@
from starlette.testclient import TestClient
from starlette.types import ASGIApp, Receive, Scope, Send
from starlette.websockets import WebSocket

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


async def error_500(request: Request, exc: HTTPException) -> JSONResponse:
Expand Down
6 changes: 1 addition & 5 deletions tests/test_authentication.py
Expand Up @@ -19,12 +19,8 @@
from starlette.requests import HTTPConnection, Request
from starlette.responses import JSONResponse, Response
from starlette.routing import Route, WebSocketRoute
from starlette.testclient import TestClient
from starlette.websockets import WebSocket, WebSocketDisconnect

TestClientFactory = Callable[..., TestClient]
AsyncEndpoint = Callable[..., Awaitable[Response]]
SyncEndpoint = Callable[..., Response]
from tests.types import AsyncEndpoint, SyncEndpoint, TestClientFactory


class BasicAuth(AuthenticationBackend):
Expand Down
6 changes: 1 addition & 5 deletions tests/test_background.py
@@ -1,13 +1,9 @@
from typing import Callable

import pytest

from starlette.background import BackgroundTask, BackgroundTasks
from starlette.responses import Response
from starlette.testclient import TestClient
from starlette.types import Receive, Scope, Send

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


def test_async_task(test_client_factory: TestClientFactory) -> None:
Expand Down
6 changes: 2 additions & 4 deletions tests/test_concurrency.py
@@ -1,5 +1,5 @@
from contextvars import ContextVar
from typing import Callable, Iterator
from typing import Iterator

import anyio
import pytest
Expand All @@ -9,9 +9,7 @@
from starlette.requests import Request
from starlette.responses import Response
from starlette.routing import Route
from starlette.testclient import TestClient

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


@pytest.mark.anyio
Expand Down
6 changes: 2 additions & 4 deletions tests/test_convertors.py
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Callable, Iterator
from typing import Iterator

import pytest

Expand All @@ -8,9 +8,7 @@
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette.routing import Route, Router
from starlette.testclient import TestClient

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


@pytest.fixture(scope="module", autouse=True)
Expand Down
5 changes: 2 additions & 3 deletions tests/test_endpoints.py
@@ -1,4 +1,4 @@
from typing import Callable, Iterator
from typing import Iterator

import pytest

Expand All @@ -8,8 +8,7 @@
from starlette.routing import Route, Router
from starlette.testclient import TestClient
from starlette.websockets import WebSocket

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


class Homepage(HTTPEndpoint):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_exceptions.py
@@ -1,5 +1,5 @@
import warnings
from typing import Callable, Generator
from typing import Generator

import pytest

Expand All @@ -10,8 +10,7 @@
from starlette.routing import Route, Router, WebSocketRoute
from starlette.testclient import TestClient
from starlette.types import Receive, Scope, Send

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


def raise_runtime_error(request: Request) -> None:
Expand Down
4 changes: 1 addition & 3 deletions tests/test_formparsers.py
Expand Up @@ -11,10 +11,8 @@
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette.routing import Mount
from starlette.testclient import TestClient
from starlette.types import ASGIApp, Receive, Scope, Send

TestClientFactory = typing.Callable[..., TestClient]
from tests.types import TestClientFactory


class ForceMultipartDict(typing.Dict[typing.Any, typing.Any]):
Expand Down
6 changes: 2 additions & 4 deletions tests/test_requests.py
@@ -1,16 +1,14 @@
import sys
from typing import Any, Callable, Dict, Iterator, List, Optional
from typing import Any, Dict, Iterator, List, Optional

import anyio
import pytest

from starlette.datastructures import Address, State
from starlette.requests import ClientDisconnect, Request
from starlette.responses import JSONResponse, PlainTextResponse, Response
from starlette.testclient import TestClient
from starlette.types import Message, Receive, Scope, Send

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


def test_request_url(test_client_factory: TestClientFactory) -> None:
Expand Down
5 changes: 2 additions & 3 deletions tests/test_responses.py
Expand Up @@ -3,7 +3,7 @@
import time
from http.cookies import SimpleCookie
from pathlib import Path
from typing import AsyncIterator, Callable, Iterator, Union
from typing import AsyncIterator, Iterator, Union

import anyio
import pytest
Expand All @@ -21,8 +21,7 @@
)
from starlette.testclient import TestClient
from starlette.types import Message, Receive, Scope, Send

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


def test_text_response(test_client_factory: TestClientFactory) -> None:
Expand Down
3 changes: 1 addition & 2 deletions tests/test_routing.py
Expand Up @@ -15,8 +15,7 @@
from starlette.testclient import TestClient
from starlette.types import ASGIApp, Message, Receive, Scope, Send
from starlette.websockets import WebSocket, WebSocketDisconnect

TestClientFactory = typing.Callable[..., TestClient]
from tests.types import TestClientFactory


def homepage(request: Request) -> Response:
Expand Down
6 changes: 1 addition & 5 deletions tests/test_schemas.py
@@ -1,20 +1,16 @@
from typing import Callable

from starlette.applications import Starlette
from starlette.endpoints import HTTPEndpoint
from starlette.requests import Request
from starlette.responses import Response
from starlette.routing import Host, Mount, Route, Router, WebSocketRoute
from starlette.schemas import SchemaGenerator
from starlette.testclient import TestClient
from starlette.websockets import WebSocket
from tests.types import TestClientFactory

schemas = SchemaGenerator(
{"openapi": "3.0.0", "info": {"title": "Example API", "version": "1.0"}}
)

TestClientFactory = Callable[..., TestClient]


def ws(session: WebSocket) -> None:
"""ws"""
Expand Down
4 changes: 1 addition & 3 deletions tests/test_templates.py
Expand Up @@ -14,9 +14,7 @@
from starlette.responses import Response
from starlette.routing import Route
from starlette.templating import Jinja2Templates
from starlette.testclient import TestClient

TestClientFactory = typing.Callable[..., TestClient]
from tests.types import TestClientFactory


def test_templates(tmpdir: Path, test_client_factory: TestClientFactory) -> None:
Expand Down
5 changes: 2 additions & 3 deletions tests/test_testclient.py
Expand Up @@ -4,7 +4,7 @@
import sys
from asyncio import Task, current_task as asyncio_current_task
from contextlib import asynccontextmanager
from typing import Any, AsyncGenerator, Callable
from typing import Any, AsyncGenerator

import anyio
import anyio.lowlevel
Expand All @@ -20,8 +20,7 @@
from starlette.testclient import ASGIInstance, TestClient
from starlette.types import ASGIApp, Receive, Scope, Send
from starlette.websockets import WebSocket, WebSocketDisconnect

TestClientFactory = Callable[..., TestClient]
from tests.types import TestClientFactory


def mock_service_endpoint(request: Request) -> JSONResponse:
Expand Down