Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/certbot/certbot.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Ferrand <adferrand@users.noreply.github.com>2021-12-13 06:01:31 +0300
committerGitHub <noreply@github.com>2021-12-13 06:01:31 +0300
commit97d9e2c97dbb2a57cc9a5d0374376e98b359d11c (patch)
tree7fcc36b0ffe1dd7ff9c5e0078d010329e0a7bd4c
parent89cefc177aed479f9f68bbb7bdbba14fc4a17857 (diff)
Fully type lock_test.py (#9126)
* Type lock_test.py * Reconfigure tox * Fix imports
-rw-r--r--tests/lock_test.py28
-rw-r--r--tox.ini4
2 files changed, 18 insertions, 14 deletions
diff --git a/tests/lock_test.py b/tests/lock_test.py
index 4ddbd3aef..97da5f77a 100644
--- a/tests/lock_test.py
+++ b/tests/lock_test.py
@@ -9,6 +9,10 @@ import shutil
import subprocess
import sys
import tempfile
+from typing import Iterable
+from typing import List
+from typing import Sequence
+from typing import Tuple
from cryptography import x509
from cryptography.hazmat.backends import default_backend
@@ -24,7 +28,7 @@ from certbot.tests import util as test_util
logger = logging.getLogger(__name__)
-def main():
+def main() -> None:
"""Run the lock tests."""
dirs, base_cmd = set_up()
for subcommand in ('certonly', 'install', 'renew', 'run',):
@@ -33,7 +37,7 @@ def main():
logger.info('Lock test ran successfully.')
-def set_up():
+def set_up() -> Tuple[List[str], List[str]]:
"""Prepare tests to be run.
Logging is set up and temporary directories are set up to contain a
@@ -65,7 +69,7 @@ def set_up():
return dirs, command
-def set_up_dirs():
+def set_up_dirs() -> Tuple[str, str, str, str]:
"""Set up directories for tests.
A temporary directory is created to contain the config, log, work,
@@ -96,7 +100,7 @@ def set_up_dirs():
return config_dir, logs_dir, work_dir, nginx_dir
-def set_up_nginx_dir(root_path):
+def set_up_nginx_dir(root_path: str) -> None:
"""Create a basic Nginx configuration in nginx_dir.
:param str root_path: where the Nginx server root should be placed
@@ -113,7 +117,7 @@ def set_up_nginx_dir(root_path):
f.write(check_call(['/bin/sh', conf_script, root_path, key_path, cert_path]))
-def set_up_command(config_dir, logs_dir, work_dir, nginx_dir):
+def set_up_command(config_dir: str, logs_dir: str, work_dir: str, nginx_dir: str) -> List[str]:
"""Build the Certbot command to run for testing.
You can test different subcommands by appending the desired command
@@ -137,7 +141,7 @@ def set_up_command(config_dir, logs_dir, work_dir, nginx_dir):
config_dir, logs_dir, work_dir, nginx_dir).split())
-def setup_certificate(workspace):
+def setup_certificate(workspace: str) -> Tuple[str, str]:
"""Generate a self-signed certificate for nginx.
:param workspace: path of folder where to put the certificate
:return: tuple containing the key path and certificate path
@@ -181,7 +185,7 @@ def setup_certificate(workspace):
return key_path, cert_path
-def test_command(command, directories):
+def test_command(command: Sequence[str], directories: Iterable[str]) -> None:
"""Assert Certbot acquires locks in a specific order.
command is run repeatedly testing that Certbot acquires locks on
@@ -198,7 +202,7 @@ def test_command(command, directories):
dir_lock.release()
-def check_error(command, dir_path):
+def check_error(command: Sequence[str], dir_path: str) -> None:
"""Run command and verify it fails to acquire the lock for dir_path.
:param str command: certbot command to run
@@ -223,7 +227,7 @@ def check_error(command, dir_path):
report_failure(err_msg, out, err)
-def check_call(args):
+def check_call(args: Sequence[str]) -> str:
"""Simple imitation of subprocess.check_call.
This function is only available in subprocess in Python 2.7+.
@@ -240,7 +244,7 @@ def check_call(args):
return out
-def report_failure(err_msg, out, err):
+def report_failure(err_msg: str, out: str, err: str) -> None:
"""Report a subprocess failure and exit.
:param str err_msg: error message to report
@@ -253,7 +257,7 @@ def report_failure(err_msg, out, err):
sys.exit(err_msg)
-def subprocess_call(args):
+def subprocess_call(args: Sequence[str]) -> Tuple[int, str, str]:
"""Run a command with subprocess and return the result.
:param list args: program and it's arguments to be run
@@ -270,7 +274,7 @@ def subprocess_call(args):
return process.returncode, out, err
-def log_output(level, out, err):
+def log_output(level: int, out: str, err: str) -> None:
"""Logs stdout and stderr output at the requested level.
:param int level: logging level to use
diff --git a/tox.ini b/tox.ini
index 23e373bd7..8ffd360b2 100644
--- a/tox.ini
+++ b/tox.ini
@@ -20,8 +20,8 @@ install_and_test = python {toxinidir}/tools/install_and_test.py
dns_packages = certbot-dns-cloudflare certbot-dns-cloudxns certbot-dns-digitalocean certbot-dns-dnsimple certbot-dns-dnsmadeeasy certbot-dns-gehirn certbot-dns-google certbot-dns-linode certbot-dns-luadns certbot-dns-nsone certbot-dns-ovh certbot-dns-rfc2136 certbot-dns-route53 certbot-dns-sakuracloud
win_all_packages = acme[test] certbot[test] {[base]dns_packages} certbot-nginx
all_packages = {[base]win_all_packages} certbot-apache
-fully_typed_source_paths = acme/acme certbot/certbot certbot-ci/certbot_integration_tests certbot-ci/snap_integration_tests certbot-ci/windows_installer_integration_tests
-partially_typed_source_paths = certbot-apache/certbot_apache certbot-compatibility-test/certbot_compatibility_test certbot-dns-cloudflare/certbot_dns_cloudflare certbot-dns-cloudxns/certbot_dns_cloudxns certbot-dns-digitalocean/certbot_dns_digitalocean certbot-dns-dnsimple/certbot_dns_dnsimple certbot-dns-dnsmadeeasy/certbot_dns_dnsmadeeasy certbot-dns-gehirn/certbot_dns_gehirn certbot-dns-google/certbot_dns_google certbot-dns-linode/certbot_dns_linode certbot-dns-luadns/certbot_dns_luadns certbot-dns-nsone/certbot_dns_nsone certbot-dns-ovh/certbot_dns_ovh certbot-dns-rfc2136/certbot_dns_rfc2136 certbot-dns-route53/certbot_dns_route53 certbot-dns-sakuracloud/certbot_dns_sakuracloud certbot-nginx/certbot_nginx tests/lock_test.py
+fully_typed_source_paths = acme/acme certbot/certbot certbot-ci/certbot_integration_tests certbot-ci/snap_integration_tests certbot-ci/windows_installer_integration_tests tests/lock_test.py
+partially_typed_source_paths = certbot-apache/certbot_apache certbot-compatibility-test/certbot_compatibility_test certbot-dns-cloudflare/certbot_dns_cloudflare certbot-dns-cloudxns/certbot_dns_cloudxns certbot-dns-digitalocean/certbot_dns_digitalocean certbot-dns-dnsimple/certbot_dns_dnsimple certbot-dns-dnsmadeeasy/certbot_dns_dnsmadeeasy certbot-dns-gehirn/certbot_dns_gehirn certbot-dns-google/certbot_dns_google certbot-dns-linode/certbot_dns_linode certbot-dns-luadns/certbot_dns_luadns certbot-dns-nsone/certbot_dns_nsone certbot-dns-ovh/certbot_dns_ovh certbot-dns-rfc2136/certbot_dns_rfc2136 certbot-dns-route53/certbot_dns_route53 certbot-dns-sakuracloud/certbot_dns_sakuracloud certbot-nginx/certbot_nginx
[testenv]
passenv =