mirror of
https://github.com/certbot/certbot.git
synced 2026-07-31 18:34:41 +02:00
Remove external mock dependency (#9331)
* Remove external mock dependency This also removes the "external-mock" test environment * remove superfluous ignores * remove mock warning ignore from pytest.ini * drop deps on mock in oldest, drop dep on types-mock Co-authored-by: Alex Zorin <alex@zorin.id.au>
This commit is contained in:
co-authored by
Alex Zorin
parent
c9eba6ccd3
commit
26d479d6e3
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING
|
||||
|
||||
import configobj
|
||||
import josepy as jose
|
||||
from unittest import mock
|
||||
|
||||
from acme import challenges
|
||||
from certbot import achallenges
|
||||
@@ -19,12 +20,6 @@ else:
|
||||
Protocol = object
|
||||
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock # type: ignore
|
||||
|
||||
|
||||
DOMAIN = 'example.com'
|
||||
KEY = jose.JWKRSA.load(test_util.load_vector("rsa512_key.pem"))
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Base test class for DNS authenticators built on Lexicon."""
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING
|
||||
from unittest import mock
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import josepy as jose
|
||||
@@ -14,10 +15,6 @@ from certbot.plugins.dns_common_lexicon import LexiconClient
|
||||
from certbot.plugins.dns_test_common import _AuthenticatorCallableTestCase
|
||||
from certbot.tests import util as test_util
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock # type: ignore
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Protocol
|
||||
else:
|
||||
|
||||
@@ -16,7 +16,7 @@ from typing import Iterable
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
import unittest
|
||||
import warnings
|
||||
from unittest import mock
|
||||
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
@@ -35,20 +35,6 @@ from certbot.compat import os
|
||||
from certbot.display import util as display_util
|
||||
from certbot.plugins import common
|
||||
|
||||
try:
|
||||
# When we remove this deprecated import, we should also remove the
|
||||
# "external-mock" test environment and the mock dependency listed in
|
||||
# tools/pinning/pyproject.toml.
|
||||
import mock
|
||||
warnings.warn(
|
||||
"The external mock module is being used for backwards compatibility "
|
||||
"since it is available, however, future versions of Certbot's tests will "
|
||||
"use unittest.mock. Be sure to update your code accordingly.",
|
||||
PendingDeprecationWarning
|
||||
)
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock # type: ignore
|
||||
|
||||
|
||||
class DummyInstaller(common.Installer):
|
||||
"""Dummy installer plugin for test purpose."""
|
||||
|
||||
@@ -90,7 +90,6 @@ test_extras = [
|
||||
'pytest-xdist',
|
||||
'setuptools',
|
||||
'tox',
|
||||
'types-mock',
|
||||
'types-pyOpenSSL',
|
||||
'types-pyRFC3339',
|
||||
'types-pytz',
|
||||
|
||||
@@ -4,10 +4,7 @@ import json
|
||||
import unittest
|
||||
|
||||
import josepy as jose
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
import pytz
|
||||
|
||||
from acme import messages
|
||||
|
||||
@@ -4,10 +4,7 @@ import logging
|
||||
import unittest
|
||||
|
||||
from josepy import b64encode
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from acme import challenges
|
||||
from acme import client as acme_client
|
||||
|
||||
@@ -7,10 +7,7 @@ import tempfile
|
||||
import unittest
|
||||
|
||||
import configobj
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from certbot import errors, configuration
|
||||
from certbot._internal.storage import ALL_FOUR
|
||||
|
||||
@@ -5,6 +5,7 @@ from importlib import reload as reload_module
|
||||
import io
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from acme import challenges
|
||||
from certbot import errors
|
||||
@@ -16,11 +17,6 @@ from certbot.compat import os
|
||||
import certbot.tests.util as test_util
|
||||
from certbot.tests.util import TempDirTestCase
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
PLUGINS = disco.PluginsRegistry.find_all()
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import platform
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from josepy import interfaces
|
||||
@@ -17,11 +18,6 @@ from certbot._internal import constants
|
||||
from certbot.compat import os
|
||||
import certbot.tests.util as test_util
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
KEY = test_util.load_vector("rsa512_key.pem")
|
||||
CSR_SAN = test_util.load_vector("csr-san_512.pem")
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
import contextlib
|
||||
import errno
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from certbot import util
|
||||
from certbot._internal import lock
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
"""Tests for certbot.compat.misc"""
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock # type: ignore
|
||||
import unittest
|
||||
import warnings
|
||||
from unittest import mock
|
||||
|
||||
from certbot.compat import os
|
||||
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
"""Tests for certbot.configuration."""
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from certbot import errors
|
||||
from certbot._internal import constants
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
"""Tests for certbot.crypto_util."""
|
||||
import logging
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
import OpenSSL
|
||||
|
||||
from certbot import errors
|
||||
|
||||
@@ -9,17 +9,12 @@ from importlib import reload as reload_module
|
||||
import string
|
||||
import sys
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from certbot.compat import filesystem
|
||||
from certbot.compat import os
|
||||
import certbot.tests.util as test_util
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
|
||||
class CompleterTest(test_util.TempDirTestCase):
|
||||
"""Test certbot._internal.display.completer.Completer."""
|
||||
|
||||
@@ -3,15 +3,11 @@ import io
|
||||
import socket
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from acme import messages as acme_messages
|
||||
from certbot import errors
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
class WrapLinesTest(unittest.TestCase):
|
||||
def test_wrap_lines(self):
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"""Test certbot.display.ops."""
|
||||
import sys
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import josepy as jose
|
||||
|
||||
@@ -15,11 +16,6 @@ from certbot.display import ops
|
||||
from certbot.display import util as display_util
|
||||
import certbot.tests.util as test_util
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
KEY = jose.JWKRSA.load(test_util.load_vector("rsa512_key.pem"))
|
||||
|
||||
|
||||
@@ -3,15 +3,11 @@ import io
|
||||
import socket
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from certbot import errors
|
||||
import certbot.tests.util as test_util
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
class NotifyTest(unittest.TestCase):
|
||||
"""Tests for certbot.display.util.notify"""
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
"""Tests for certbot._internal.eff."""
|
||||
import datetime
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
import josepy
|
||||
import pytz
|
||||
import requests
|
||||
|
||||
@@ -6,15 +6,10 @@ from typing import Callable
|
||||
from typing import Dict
|
||||
from typing import Union
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from certbot.compat import os
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
|
||||
def get_signals(signums):
|
||||
"""Get the handlers for an iterable of signums."""
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
"""Tests for certbot.errors."""
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from acme import messages
|
||||
from certbot import achallenges
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
"""Tests for certbot.helpful_parser"""
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from certbot import errors
|
||||
from certbot._internal.cli import HelpfulArgumentParser
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
"""Tests for certbot._internal.hooks."""
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from certbot import errors
|
||||
from certbot import util
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
import functools
|
||||
import multiprocessing
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from certbot import errors
|
||||
from certbot.compat import os
|
||||
|
||||
@@ -6,6 +6,7 @@ import sys
|
||||
import time
|
||||
from typing import Optional
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from acme import messages
|
||||
from certbot import errors
|
||||
@@ -15,11 +16,6 @@ from certbot.compat import filesystem
|
||||
from certbot.compat import os
|
||||
from certbot.tests import util as test_util
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
|
||||
class PreArgParseSetupTest(unittest.TestCase):
|
||||
|
||||
@@ -12,6 +12,7 @@ import tempfile
|
||||
import traceback
|
||||
from typing import List
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import josepy as jose
|
||||
import pytz
|
||||
@@ -34,11 +35,6 @@ from certbot.compat import os
|
||||
from certbot.plugins import enhancements
|
||||
import certbot.tests.util as test_util
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
|
||||
CERT_PATH = test_util.vector_path('cert_512.pem')
|
||||
|
||||
@@ -4,6 +4,7 @@ import contextlib
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from cryptography import x509
|
||||
from cryptography.exceptions import InvalidSignature
|
||||
@@ -16,11 +17,6 @@ import pytz
|
||||
from certbot import errors
|
||||
from certbot.tests import util as test_util
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
out = """Missing = in header key=value
|
||||
ocsp: Use -help for summary.
|
||||
|
||||
@@ -2,12 +2,9 @@
|
||||
import functools
|
||||
import shutil
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import josepy as jose
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
from acme import challenges
|
||||
from certbot import achallenges
|
||||
|
||||
@@ -3,6 +3,7 @@ import functools
|
||||
import string
|
||||
from typing import List
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import pkg_resources
|
||||
|
||||
@@ -12,11 +13,6 @@ from certbot._internal.plugins import null
|
||||
from certbot._internal.plugins import standalone
|
||||
from certbot._internal.plugins import webroot
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
EP_SA = pkg_resources.EntryPoint(
|
||||
"sa", "certbot._internal.plugins.standalone",
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
"""Tests for certbot.plugins.dns_common_lexicon."""
|
||||
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from certbot.plugins import dns_common_lexicon
|
||||
from certbot.plugins import dns_test_common_lexicon
|
||||
|
||||
@@ -3,11 +3,7 @@
|
||||
import collections
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from certbot import errors
|
||||
from certbot import util
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
"""Tests for new style enhancements"""
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from certbot._internal.plugins import null
|
||||
from certbot.plugins import enhancements
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
import sys
|
||||
import textwrap
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from acme import challenges
|
||||
from certbot import errors
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
"""Tests for certbot._internal.plugins.null."""
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
|
||||
class InstallerTest(unittest.TestCase):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import sys
|
||||
from typing import List
|
||||
import unittest
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from certbot import errors
|
||||
from certbot import interfaces
|
||||
@@ -11,11 +11,6 @@ from certbot._internal.plugins.disco import PluginsRegistry
|
||||
from certbot.display import util as display_util
|
||||
from certbot.tests import util as test_util
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
class ConveniencePickPluginTest(unittest.TestCase):
|
||||
"""Tests for certbot._internal.plugins.selection.pick_*."""
|
||||
|
||||
@@ -5,6 +5,7 @@ from typing import Dict
|
||||
from typing import Set
|
||||
from typing import Tuple
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import josepy as jose
|
||||
import OpenSSL.crypto
|
||||
@@ -16,11 +17,6 @@ from certbot import errors
|
||||
from certbot.tests import acme_util
|
||||
from certbot.tests import util as test_util
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
class ServerManagerTest(unittest.TestCase):
|
||||
"""Tests for certbot._internal.plugins.standalone.ServerManager."""
|
||||
|
||||
@@ -4,17 +4,13 @@ from typing import Iterable
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from certbot import errors
|
||||
from certbot.compat import filesystem
|
||||
from certbot.compat import os
|
||||
from certbot.tests import util as test_util
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
|
||||
class PluginStorageTest(test_util.ConfigTestCase):
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
"""Tests for certbot.plugins.util."""
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from certbot.compat import os
|
||||
|
||||
|
||||
@@ -8,12 +8,9 @@ import json
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import josepy as jose
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
from acme import challenges
|
||||
from certbot import achallenges
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
"""Tests for certbot._internal.renewal"""
|
||||
import copy
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from acme import challenges
|
||||
from certbot import errors, configuration
|
||||
from certbot._internal import storage
|
||||
import certbot.tests.util as test_util
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
|
||||
class RenewalTest(test_util.ConfigTestCase):
|
||||
@mock.patch('certbot._internal.cli.set_by_cli')
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
"""Tests for renewal updater interfaces"""
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from certbot import interfaces
|
||||
from certbot._internal import main
|
||||
|
||||
@@ -4,11 +4,7 @@ import logging
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
from unittest import mock
|
||||
|
||||
from certbot import errors
|
||||
from certbot.compat import os
|
||||
|
||||
@@ -4,12 +4,9 @@ import datetime
|
||||
import shutil
|
||||
import stat
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import configobj
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
import pytz
|
||||
|
||||
import certbot
|
||||
|
||||
@@ -5,18 +5,13 @@ from importlib import reload as reload_module
|
||||
import io
|
||||
import sys
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from certbot import errors
|
||||
from certbot.compat import filesystem
|
||||
from certbot.compat import os
|
||||
import certbot.tests.util as test_util
|
||||
|
||||
try:
|
||||
import mock
|
||||
except ImportError: # pragma: no cover
|
||||
from unittest import mock
|
||||
|
||||
|
||||
|
||||
class EnvNoSnapForExternalCallsTest(unittest.TestCase):
|
||||
"""Tests for certbot.util.env_no_snap_for_external_calls."""
|
||||
|
||||
Reference in New Issue
Block a user