Skip to content

Commit

Permalink
Make mypy pass on our tests (#9648)
Browse files Browse the repository at this point in the history
* make mypy pass on our tests

* fix grammar
  • Loading branch information
bmw committed Mar 30, 2023
1 parent 63fb97d commit 608d731
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
SCRIPT_DIRNAME = os.path.dirname(__file__)


def main(args=None):
if not args:
args = sys.argv[1:]
def main() -> int:
args = sys.argv[1:]
with acme_server.ACMEServer('pebble', [], False) as acme_xdist:
environ = os.environ.copy()
environ['SERVER'] = acme_xdist['directory_url']
Expand Down
3 changes: 2 additions & 1 deletion certbot-nginx/certbot_nginx/_internal/parser_obj.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# type: ignore
# This module is not used for now, so we just skip type check for the sake of simplicity.
# This module is not used for now, so we just skip type checking for the sake
# of simplicity.
""" This file contains parsing routines and object classes to help derive meaning from
raw lists of tokens from pyparsing. """

Expand Down
13 changes: 7 additions & 6 deletions certbot-nginx/certbot_nginx/_internal/tests/http_01_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

from acme import challenges
from acme import messages
from certbot import achallenges
from certbot.tests import acme_util
from certbot.tests import util as test_util
Expand All @@ -23,29 +24,29 @@ class HttpPerformTest(util.NginxTest):
achalls = [
achallenges.KeyAuthorizationAnnotatedChallenge(
challb=acme_util.chall_to_challb(
challenges.HTTP01(token=b"kNdwjwOeX0I_A8DXt9Msmg"), "pending"),
challenges.HTTP01(token=b"kNdwjwOeX0I_A8DXt9Msmg"), messages.STATUS_PENDING),
domain="www.example.com", account_key=account_key),
achallenges.KeyAuthorizationAnnotatedChallenge(
challb=acme_util.chall_to_challb(
challenges.HTTP01(
token=b"\xba\xa9\xda?<m\xaewmx\xea\xad\xadv\xf4\x02\xc9y"
b"\x80\xe2_X\t\xe7\xc7\xa4\t\xca\xf7&\x945"
), "pending"),
), messages.STATUS_PENDING),
domain="ipv6.com", account_key=account_key),
achallenges.KeyAuthorizationAnnotatedChallenge(
challb=acme_util.chall_to_challb(
challenges.HTTP01(
token=b"\x8c\x8a\xbf_-f\\cw\xee\xd6\xf8/\xa5\xe3\xfd"
b"\xeb9\xf1\xf5\xb9\xefVM\xc9w\xa4u\x9c\xe1\x87\xb4"
), "pending"),
), messages.STATUS_PENDING),
domain="www.example.org", account_key=account_key),
achallenges.KeyAuthorizationAnnotatedChallenge(
challb=acme_util.chall_to_challb(
challenges.HTTP01(token=b"kNdwjxOeX0I_A8DXt9Msmg"), "pending"),
challenges.HTTP01(token=b"kNdwjxOeX0I_A8DXt9Msmg"), messages.STATUS_PENDING),
domain="migration.com", account_key=account_key),
achallenges.KeyAuthorizationAnnotatedChallenge(
challb=acme_util.chall_to_challb(
challenges.HTTP01(token=b"kNdwjxOeX0I_A8DXt9Msmg"), "pending"),
challenges.HTTP01(token=b"kNdwjxOeX0I_A8DXt9Msmg"), messages.STATUS_PENDING),
domain="ipv6ssl.com", account_key=account_key),
]

Expand Down Expand Up @@ -137,7 +138,7 @@ def test_mod_config_deduplicate(self, mock_add_server_directives):
"""A vhost that appears in both HTTP and HTTPS vhosts only gets modded once"""
achall = achallenges.KeyAuthorizationAnnotatedChallenge(
challb=acme_util.chall_to_challb(
challenges.HTTP01(token=b"kNdwjxOeX0I_A8DXt9Msmg"), "pending"),
challenges.HTTP01(token=b"kNdwjxOeX0I_A8DXt9Msmg"), messages.STATUS_PENDING),
domain="ssl.both.com", account_key=AUTH_KEY)
self.http01.add_chall(achall)
self.http01._mod_config() # pylint: disable=protected-access
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# type: ignore
# As done in parser_obj.py, this module is not used for now, so we just skip
# type checking for the sake of simplicity.
""" Tests for functions and classes in parser_obj.py """

import sys
Expand Down
5 changes: 3 additions & 2 deletions certbot/certbot/_internal/tests/plugins/common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest

from acme import challenges
from acme import messages
from certbot import achallenges
from certbot import crypto_util
from certbot import errors
Expand All @@ -20,7 +21,7 @@
AUTH_KEY = jose.JWKRSA.load(test_util.load_vector("rsa512_key.pem"))
ACHALL = achallenges.KeyAuthorizationAnnotatedChallenge(
challb=acme_util.chall_to_challb(challenges.HTTP01(token=b'token1'),
"pending"),
messages.STATUS_PENDING),
domain="encryption-example.demo", account_key=AUTH_KEY)


Expand Down Expand Up @@ -51,7 +52,7 @@ def prepare(self) -> None:
pass

def more_info(self) -> str:
pass
return "info"

@classmethod
def add_parser_arguments(cls, add):
Expand Down
11 changes: 2 additions & 9 deletions certbot/certbot/_internal/tests/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,6 @@ def test_default_exists(self):
fd3.close()


try:
file_type = file
except NameError:
import io
file_type = io.TextIOWrapper # type: ignore


class UniqueLineageNameTest(test_util.TempDirTestCase):
"""Tests for certbot.util.unique_lineage_name."""

Expand All @@ -263,7 +256,7 @@ def _call(self, filename, mode=0o777):

def test_basic(self):
f, path = self._call("wow")
assert isinstance(f, file_type)
assert isinstance(f, io.TextIOWrapper)
assert os.path.join(self.tempdir, "wow.conf") == path
f.close()

Expand All @@ -272,7 +265,7 @@ def test_multiple(self):
for _ in range(10):
items.append(self._call("wow"))
f, name = items[-1]
assert isinstance(f, file_type)
assert isinstance(f, io.TextIOWrapper)
assert isinstance(name, str)
assert "wow-0009.conf" in name
for f, _ in items:
Expand Down
12 changes: 9 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
[mypy]
# Removing this exclude setting is being tracked by
# https://github.com/certbot/certbot/issues/7909.
exclude = .*/_internal/tests/
ignore_missing_imports = True
warn_unused_ignores = True
show_error_codes = True
disallow_untyped_defs = True

# Using stricter settings here is being tracked by
# https://github.com/certbot/certbot/issues/9647.
[mypy-*._internal.tests.*]
# By default, mypy prints notes without erroring about any type annotations it
# finds in untyped function bodies when check_untyped_defs is false. Disabling
# this "error" code removes this visual noise.
disable_error_code = annotation-unchecked
disallow_untyped_defs = False

0 comments on commit 608d731

Please sign in to comment.