Skip to content

Commit

Permalink
Take care of unused arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Mar 8, 2021
1 parent 4700452 commit 9211ecc
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 45 deletions.
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ repos:
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-builtins
- flake8-import-order-jwodder
- flake8-bugbear
- flake8-builtins
- flake8-import-order-jwodder
- flake8-unused-arguments
2 changes: 1 addition & 1 deletion src/outgoing/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class NetrcConfig(pydantic.BaseModel):
password: Optional[StandardPassword]

@pydantic.root_validator(skip_on_failure=True)
def _validate(cls, values: Dict[str, Any]) -> Dict[str, Any]: # noqa: B902
def _validate(cls, values: Dict[str, Any]) -> Dict[str, Any]: # noqa: B902, U100
if values["password"] is not None:
if values["netrc"]:
raise ValueError("netrc cannot be set when a password is present")
Expand Down
4 changes: 3 additions & 1 deletion src/outgoing/senders/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class SMTPSender(NetrcConfig, OpenClosable):
_client: Optional[smtplib.SMTP] = PrivateAttr(None)

@validator("port", always=True)
def _set_default_port(cls, v: Any, values: Dict[str, Any]) -> Any: # noqa: B902
def _set_default_port(
cls, v: Any, values: Dict[str, Any] # noqa: B902, U100
) -> Any:
if v == 0:
ssl = values.get("ssl")
if ssl is True:
Expand Down
6 changes: 3 additions & 3 deletions src/outgoing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def __enter__(self: OC) -> OC:

def __exit__(
self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
_exc_type: Optional[Type[BaseException]],
_exc_val: Optional[BaseException],
_exc_tb: Optional[TracebackType],
) -> None:
self._context_depth -= 1
if self._context_depth == 0:
Expand Down
4 changes: 1 addition & 3 deletions test/test_config/test_netrc_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ def test_netrc_config_password_netrc(
m.assert_not_called()


def test_netrc_config_username_no_password_no_netrc(
mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch
) -> None:
def test_netrc_config_username_no_password_no_netrc(mocker: MockerFixture) -> None:
m = mocker.patch(
"outgoing.core.lookup_netrc",
return_value=(sentinel.USERNAME, "hunter2"),
Expand Down
12 changes: 6 additions & 6 deletions test/test_config/test_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ def test_standard_password_invalid_username(mocker: MockerFixture) -> None:

class Password02(Password):
@classmethod
def host(cls, values: Dict[str, Any]) -> str:
def host(cls, _values: Dict[str, Any]) -> str:
return "api.example.com"

@classmethod
def username(cls, values: Dict[str, Any]) -> str:
def username(cls, _values: Dict[str, Any]) -> str:
return "mylogin"


Expand Down Expand Up @@ -189,21 +189,21 @@ def test_password_unset_fields(mocker: MockerFixture) -> None:
)


def test_password_bad_host(mocker: MockerFixture) -> None:
def test_password_bad_host() -> None:
with pytest.raises(RuntimeError) as excinfo:
type("PasswordTest", (Password,), {"host": 42})
assert str(excinfo.value) == "Password.host must be a str, callable, or None"


def test_password_bad_username(mocker: MockerFixture) -> None:
def test_password_bad_username() -> None:
with pytest.raises(RuntimeError) as excinfo:
type("PasswordTest", (Password,), {"username": 42})
assert str(excinfo.value) == "Password.username must be a str, callable, or None"


class HostErrorPassword(Password):
@classmethod
def host(cls, values: Dict[str, Any]) -> None:
def host(cls, _values: Dict[str, Any]) -> None:
raise RuntimeError("Invalid host method")


Expand All @@ -222,7 +222,7 @@ def test_host_error_password(mocker: MockerFixture) -> None:

class UsernameErrorPassword(Password):
@classmethod
def username(cls, values: Dict[str, Any]) -> None:
def username(cls, _values: Dict[str, Any]) -> None:
raise RuntimeError("Invalid username method")


Expand Down
1 change: 0 additions & 1 deletion test/test_config/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class Paths(BaseModel):


def test_path_expanduser(
monkeypatch: pytest.MonkeyPatch,
tmp_home: pathlib.Path,
) -> None:
(tmp_home / "foo").mkdir()
Expand Down
6 changes: 4 additions & 2 deletions test/test_from_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ def test_from_nonexistent_custom_config_file_no_default(tmp_home: Path) -> None:
)


@pytest.mark.usefixtures("tmp_home")
@pytest.mark.parametrize("fallback", [False, True])
def test_from_nonexistent_default_config_file(fallback: bool, tmp_home: Path) -> None:
def test_from_nonexistent_default_config_file(fallback: bool) -> None:
defconf = get_default_configpath()
with pytest.raises(MissingConfigError) as excinfo:
from_config_file(fallback=fallback)
Expand Down Expand Up @@ -188,8 +189,9 @@ def test_from_no_section_in_custom_config_file_or_default(tmp_home: Path) -> Non
)


@pytest.mark.usefixtures("tmp_home")
@pytest.mark.parametrize("fallback", [False, True])
def test_from_no_section_default_config_file(fallback: bool, tmp_home: Path) -> None:
def test_from_no_section_default_config_file(fallback: bool) -> None:
defconf = get_default_configpath()
defconf.parent.mkdir(parents=True, exist_ok=True)
defconf.write_text('[sender]\nmethod = "mbox"\npath = "inbox"\n')
Expand Down
17 changes: 4 additions & 13 deletions test/test_lookup_netrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@


@pytest.mark.parametrize("username", [None, "myname"])
def test_lookup_netrc(
monkeypatch: pytest.MonkeyPatch, tmp_home: Path, username: Optional[str]
) -> None:
def test_lookup_netrc(tmp_home: Path, username: Optional[str]) -> None:
(tmp_home / ".netrc").write_text(
"machine api.example.com\nlogin myname\npassword hunter2\n"
)
Expand All @@ -18,7 +16,6 @@ def test_lookup_netrc(


def test_lookup_netrc_username_mismatch(
monkeypatch: pytest.MonkeyPatch,
tmp_home: Path,
) -> None:
(tmp_home / ".netrc").write_text(
Expand All @@ -33,9 +30,7 @@ def test_lookup_netrc_username_mismatch(


@pytest.mark.parametrize("username", [None, "yourname"])
def test_lookup_netrc_path(
monkeypatch: pytest.MonkeyPatch, tmp_home: Path, username: Optional[str]
) -> None:
def test_lookup_netrc_path(tmp_home: Path, username: Optional[str]) -> None:
(tmp_home / ".netrc").write_text(
"machine api.example.com\nlogin myname\npassword hunter2\n"
)
Expand All @@ -49,9 +44,7 @@ def test_lookup_netrc_path(


@pytest.mark.parametrize("username", [None, "myname"])
def test_lookup_netrc_no_match(
monkeypatch: pytest.MonkeyPatch, tmp_home: Path, username: Optional[str]
) -> None:
def test_lookup_netrc_no_match(tmp_home: Path, username: Optional[str]) -> None:
(tmp_home / ".netrc").write_text(
"machine api.example.com\nlogin myname\npassword hunter2\n"
)
Expand All @@ -69,9 +62,7 @@ def test_lookup_netrc_no_match(
raises=NetrcParseError,
)
@pytest.mark.parametrize("username", [None, "myname"])
def test_lookup_netrc_no_password(
monkeypatch: pytest.MonkeyPatch, tmp_home: Path, username: Optional[str]
) -> None:
def test_lookup_netrc_no_password(tmp_home: Path, username: Optional[str]) -> None:
(tmp_home / ".netrc").write_text("machine api.example.com\nlogin myname\n")
(tmp_home / ".netrc").chmod(0o600)
with pytest.raises(NetrcLookupError) as excinfo:
Expand Down
2 changes: 0 additions & 2 deletions test/test_passwords/test_dotenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def test_dotenv_password_configpath_relative(tmp_path: Path) -> None:


def test_dotenv_password_expanduser(
monkeypatch: pytest.MonkeyPatch,
tmp_home: Path,
) -> None:
(tmp_home / "foo.txt").write_text("SECRET=hunter2\n")
Expand All @@ -49,7 +48,6 @@ def test_dotenv_password_expanduser(


def test_dotenv_password_expanduser_configpath(
monkeypatch: pytest.MonkeyPatch,
tmp_home: Path,
) -> None:
(tmp_home / "foo.txt").write_text("SECRET=hunter2\n")
Expand Down
2 changes: 0 additions & 2 deletions test/test_passwords/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ def test_file_password_configpath_relative(tmp_path: Path) -> None:


def test_file_password_expanduser(
monkeypatch: pytest.MonkeyPatch,
tmp_home: Path,
) -> None:
(tmp_home / "foo.txt").write_text(" hunter2\n")
assert resolve_password({"file": "~/foo.txt"}) == "hunter2"


def test_file_password_expanduser_configpath(
monkeypatch: pytest.MonkeyPatch,
tmp_home: Path,
) -> None:
(tmp_home / "foo.txt").write_text(" hunter2\n")
Expand Down
11 changes: 4 additions & 7 deletions test/test_senders/test_smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def test_smtp_construct_ssl(tmp_path: Path) -> None:
assert sender._client is None


def test_smtp_construct_starttls(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
def test_smtp_construct_starttls(tmp_path: Path) -> None:
(tmp_path / "net.rc").write_text(
"machine mx.example.com\nlogin me\npassword secret\n"
)
Expand Down Expand Up @@ -272,9 +270,8 @@ def test_smtp_fix_send_no_ssl_auth(
assert email2dict(test_email1) == msgdict


def test_smtp_fix_send_ssl_no_auth(
smtpd_use_ssl: None, smtpd: SMTPDFix, test_email1: EmailMessage
) -> None:
@pytest.mark.usefixtures("smtpd_use_ssl")
def test_smtp_fix_send_ssl_no_auth(smtpd: SMTPDFix, test_email1: EmailMessage) -> None:
sender = from_dict(
{"method": "smtp", "host": smtpd.hostname, "port": smtpd.port, "ssl": True}
)
Expand All @@ -291,9 +288,9 @@ def test_smtp_fix_send_ssl_no_auth(
raises=smtplib.SMTPNotSupportedError,
reason="https://github.com/bebleo/smtpdfix/issues/10",
)
@pytest.mark.usefixtures("smtpd_use_ssl")
def test_smtp_fix_send_ssl_auth(
monkeypatch: pytest.MonkeyPatch,
smtpd_use_ssl: None,
smtpd: SMTPDFix,
test_email1: EmailMessage,
) -> None:
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ deps =
flake8-bugbear
flake8-builtins~=1.4
flake8-import-order-jwodder
flake8-unused-arguments
commands =
flake8 --config=tox.ini src test

Expand Down Expand Up @@ -62,8 +63,9 @@ hang-closing = False
import-order-style = jwodder
max-doc-length = 80
max-line-length = 80
select = C,B,B902,B950,E,E242,F,I,W
select = C,B,B902,B950,E,E242,F,I,U100,W
ignore = B005,E203,E262,E501,I201,W503
unused-arguments-ignore-stub-functions = True

[testenv:docs]
basepython = python3
Expand Down

0 comments on commit 9211ecc

Please sign in to comment.