Skip to content

Commit

Permalink
f: more types
Browse files Browse the repository at this point in the history
  • Loading branch information
fizyk committed Sep 17, 2020
1 parent 43da1e1 commit db1a266
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/pytest_postgresql/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
from psycopg2cffi._impl.connection import Connection as connection
else:
from psycopg2._psycopg import cursor
from psycopg2._psycopg import connection
from psycopg2._psycopg import connection
26 changes: 14 additions & 12 deletions src/pytest_postgresql/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
import platform
import subprocess
from tempfile import gettempdir
from typing import List, Callable, Union, Iterable
from warnings import warn

import pytest
from _pytest.fixtures import FixtureRequest
from _pytest.tmpdir import TempdirFactory

from pytest_postgresql.compat import psycopg2, connection
from pytest_postgresql.executor_noop import NoopExecutor
Expand All @@ -32,7 +35,7 @@
from pytest_postgresql.port import get_port


def get_config(request):
def get_config(request: FixtureRequest) -> dict:
"""Return a dictionary with config options."""
config = {}
options = [
Expand Down Expand Up @@ -85,9 +88,9 @@ def drop_postgresql_database(user, host, port, db_name, version, password=None):


def postgresql_proc(
executable=None, host=None, port=-1, user=None, password=None,
options='', startparams=None, unixsocketdir=None, logs_prefix='',
):
executable: str=None, host: str=None, port: Union[str, int, Iterable]=-1, user: str=None, password: str=None,
options: str='', startparams: str=None, unixsocketdir: str=None, logs_prefix: str='',
) -> Callable[[FixtureRequest, TempdirFactory], PostgreSQLExecutor]:
"""
Postgresql process factory.
Expand All @@ -109,7 +112,7 @@ def postgresql_proc(
:returns: function which makes a postgresql process
"""
@pytest.fixture(scope='session')
def postgresql_proc_fixture(request, tmpdir_factory):
def postgresql_proc_fixture(request: FixtureRequest, tmpdir_factory: TempdirFactory) -> PostgreSQLExecutor:
"""
Process fixture for PostgreSQL.
Expand Down Expand Up @@ -162,8 +165,8 @@ def postgresql_proc_fixture(request, tmpdir_factory):


def postgresql_noproc(
host=None, port=None, user=None, password=None, options='',
):
host: str=None, port: Union[str, int]=None, user: str=None, password: str=None, options: str='',
) -> Callable[[FixtureRequest], NoopExecutor]:
"""
Postgresql noprocess factory.
Expand All @@ -175,7 +178,7 @@ def postgresql_noproc(
:returns: function which makes a postgresql process
"""
@pytest.fixture(scope='session')
def postgresql_noproc_fixture(request):
def postgresql_noproc_fixture(request: FixtureRequest) -> NoopExecutor:
"""
Noop Process fixture for PostgreSQL.
Expand Down Expand Up @@ -203,7 +206,7 @@ def postgresql_noproc_fixture(request):
return postgresql_noproc_fixture


def postgresql(process_fixture_name, db_name=None, load=None):
def postgresql(process_fixture_name: str, db_name: str=None, load: List[str]=None) -> Callable[[FixtureRequest], connection]:
"""
Return connection fixture factory for PostgreSQL.
Expand All @@ -214,7 +217,7 @@ def postgresql(process_fixture_name, db_name=None, load=None):
:returns: function which makes a connection to postgresql
"""
@pytest.fixture
def postgresql_factory(request):
def postgresql_factory(request: FixtureRequest) -> connection:
"""
Fixture factory for PostgreSQL.
Expand All @@ -229,7 +232,7 @@ def postgresql_factory(request):
'psycopg2 or psycopg2-binary package for CPython '
'or psycopg2cffi for Pypy.'
)
proc_fixture = request.getfixturevalue(process_fixture_name)
proc_fixture: Union[PostgreSQLExecutor, NoopExecutor] = request.getfixturevalue(process_fixture_name)

pg_host = proc_fixture.host
pg_port = proc_fixture.port
Expand Down Expand Up @@ -258,7 +261,6 @@ def postgresql_factory(request):
cur.execute(_fd.read())
yield db_connection
db_connection.close()
db_connection.info

return postgresql_factory

Expand Down

0 comments on commit db1a266

Please sign in to comment.