Skip to content

Commit

Permalink
Merge pull request #21 from icgood/warnings
Browse files Browse the repository at this point in the history
Fix pytest-asyncio warnings
  • Loading branch information
icgood authored Jan 15, 2022
2 parents 6cde908 + 8c6a0b2 commit ca3b5f7
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 35 deletions.
4 changes: 2 additions & 2 deletions pymapadmin/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from abc import abstractmethod, ABCMeta
from argparse import ArgumentParser, Namespace
from collections.abc import Mapping
from typing import Generic, Any, Final, Optional, TextIO
from typing import Generic, Any, Final, TextIO

from grpclib.client import Channel

Expand Down Expand Up @@ -85,7 +85,7 @@ def client(self) -> StubT:

def _get_metadata(self) -> Mapping[str, str]:
metadata = {'client-version': client_version}
token: Optional[str] = None
token: str | None = None
if 'PYMAP_ADMIN_TOKEN' in os.environ:
token = os.environ['PYMAP_ADMIN_TOKEN']
else:
Expand Down
6 changes: 3 additions & 3 deletions pymapadmin/commands/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import getpass
from argparse import ArgumentParser, FileType
from contextlib import closing
from typing import Any, Optional, TextIO
from typing import Any, TextIO

from .base import Command, AdminCommand
from ..config import Config
Expand Down Expand Up @@ -79,8 +79,8 @@ def method(self) -> MethodProtocol[LoginRequest, LoginResponse]:

def build_request(self) -> LoginRequest:
username: str = self.args.user
authzid: Optional[str] = self.args.authzid
expiration: Optional[float] = self.args.expiration
authzid: str | None = self.args.authzid
expiration: float | None = self.args.expiration
if self.args.ask_password:
password = getpass.getpass(f'{username} Password: ')
elif self.args.password_file is not None:
Expand Down
4 changes: 2 additions & 2 deletions pymapadmin/commands/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import getpass
from argparse import ArgumentParser, FileType
from collections.abc import Mapping, Sequence
from typing import Any, Optional
from typing import Any

from .base import AdminCommand
from ..typing import AdminRequestT, AdminResponseT, MethodProtocol
Expand Down Expand Up @@ -66,7 +66,7 @@ def add_subparser(cls, name: str, subparsers: Any) \
def method(self) -> MethodProtocol[SetUserRequest, UserResponse]:
return self.client.SetUser

def getpass(self) -> Optional[str]:
def getpass(self) -> str | None:
if self.args.no_password:
return None
elif self.args.password_file:
Expand Down
23 changes: 11 additions & 12 deletions pymapadmin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
from argparse import Namespace
from configparser import ConfigParser
from typing import Optional

from .local import config_file, token_file, socket_file

Expand Down Expand Up @@ -65,16 +64,16 @@ def build(cls, args: Namespace) -> ConfigParser:
section['no_verify_cert'] = str(args.no_verify_cert)
return parser

def _getstr(self, attr: str, envvar: str) -> Optional[str]:
val: Optional[str] = getattr(self._args, attr)
def _getstr(self, attr: str, envvar: str) -> str | None:
val: str | None = getattr(self._args, attr)
if val is not None:
return val
if envvar in os.environ:
return os.environ[envvar]
return self._section.get(attr, fallback=None)

def _getint(self, attr: str, envvar: str) -> Optional[int]:
val: Optional[int] = getattr(self._args, attr)
def _getint(self, attr: str, envvar: str) -> int | None:
val: int | None = getattr(self._args, attr)
if val is not None:
return val
if envvar in os.environ:
Expand All @@ -91,31 +90,31 @@ def _getbool(self, attr: str, envvar: str) -> bool:
return self._section.getboolean(attr, fallback=False)

@property
def host(self) -> Optional[str]:
def host(self) -> str | None:
return self._getstr('host', 'PYMAP_ADMIN_HOST')

@property
def port(self) -> Optional[int]:
def port(self) -> int | None:
return self._getint('port', 'PYMAP_ADMIN_PORT')

@property
def token(self) -> Optional[str]:
def token(self) -> str | None:
return self._getstr('token', 'PYMAP_ADMIN_TOKEN')

@property
def cert(self) -> Optional[str]:
def cert(self) -> str | None:
return self._getstr('cert', 'PYMAP_ADMIN_CERT')

@property
def key(self) -> Optional[str]:
def key(self) -> str | None:
return self._getstr('key', 'PYMAP_ADMIN_KEY')

@property
def cafile(self) -> Optional[str]:
def cafile(self) -> str | None:
return self._getstr('cafile', 'PYMAP_ADMIN_CAFILE')

@property
def capath(self) -> Optional[str]:
def capath(self) -> str | None:
return self._getstr('capath', 'PYMAP_ADMIN_CAPATH')

@property
Expand Down
6 changes: 3 additions & 3 deletions pymapadmin/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections.abc import Sequence
from functools import partial
from pathlib import Path
from typing import Any, Union, Final, Optional
from typing import Any, Final

from tempfile import gettempdir

Expand Down Expand Up @@ -80,7 +80,7 @@ def _temp_path(self) -> Path:
def _home_path(self) -> Path:
return Path(self._config_home, 'pymap', self.filename)

def add(self, *custom: Union[None, str, Path]) -> None:
def add(self, *custom: None | str | Path) -> None:
"""Append the *custom* paths to :attr:`.custom`.
Args:
Expand Down Expand Up @@ -129,7 +129,7 @@ def get_all(self) -> Sequence[Path]:
"""Return all the paths that may contain the file."""
return list(self.custom) + [self._home_path, self._temp_path]

def find(self) -> Optional[Path]:
def find(self) -> Path | None:
"""Return the :class:`~pathlib.Path` of an existing file, if one
exists.
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ ignore_missing_imports = True
[flake8]
exclude = pymapadmin/grpc

[tool:pytest]
asyncio_mode = auto

[coverage:report]
omit = */main.py, */config.py, */local.py, */grpc/*
exclude_lines =
Expand Down
4 changes: 2 additions & 2 deletions test/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from abc import ABCMeta
from collections.abc import Sequence
from typing import TypeVar, Generic, Optional
from typing import TypeVar, Generic

from grpclib.server import Stream

Expand All @@ -18,7 +18,7 @@ def __init__(self, req_type: type[RequestT],
super().__init__()
self.req_type = req_type
self.responses = responses
self._request: Optional[RequestT] = None
self._request: RequestT | None = None

@property
def request(self) -> RequestT:
Expand Down
3 changes: 0 additions & 3 deletions test/test_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from io import StringIO
from argparse import Namespace

import pytest
from grpclib.testing import ChannelFor
from pymapadmin.commands.health import CheckCommand
from grpclib.health.v1.health_grpc import HealthBase
Expand All @@ -11,8 +10,6 @@

from handler import RequestT, ResponseT, MockHandler

pytestmark = pytest.mark.asyncio


class Handler(HealthBase, MockHandler[RequestT, ResponseT]):

Expand Down
3 changes: 0 additions & 3 deletions test/test_mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from io import BytesIO, StringIO
from argparse import Namespace

import pytest
from grpclib.testing import ChannelFor
from pymapadmin.commands.mailbox import AppendCommand
from pymapadmin.grpc.admin_grpc import MailboxBase
Expand All @@ -11,8 +10,6 @@

from handler import RequestT, ResponseT, MockHandler

pytestmark = pytest.mark.asyncio


class Handler(MailboxBase, MockHandler[RequestT, ResponseT]):

Expand Down
3 changes: 0 additions & 3 deletions test/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from io import StringIO
from argparse import Namespace

import pytest
from grpclib.testing import ChannelFor
from pymapadmin.commands.system import LoginCommand, PingCommand
from pymapadmin.grpc.admin_grpc import SystemBase
Expand All @@ -11,8 +10,6 @@

from handler import RequestT, ResponseT, MockHandler

pytestmark = pytest.mark.asyncio


class Handler(SystemBase, MockHandler[RequestT, ResponseT]):

Expand Down
2 changes: 0 additions & 2 deletions test/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

from handler import RequestT, ResponseT, MockHandler

pytestmark = pytest.mark.asyncio


class Handler(UserBase, MockHandler[RequestT, ResponseT]):

Expand Down

0 comments on commit ca3b5f7

Please sign in to comment.