mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 02:35:06 +02:00
Do not require mock in Python 3 in certbot module (#7895)
Part of #7886. This PR conditionally installs mock in `certbot/setup.py` based on setuptools version and python version, when possible. It then updates `certbot` tests to use `unittest.mock` when `mock` isn't available. * Conditionally install mock in certbot * use unittest.mock when third-party mock isn't available in certbot * Add type:ignores because of https://github.com/python/mypy/issues/1153 * error when trying to build wheels with old setuptools
This commit is contained in:
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
import configobj
|
import configobj
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock # type: ignore
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from acme import challenges
|
from acme import challenges
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"""Base test class for DNS authenticators built on Lexicon."""
|
"""Base test class for DNS authenticators built on Lexicon."""
|
||||||
|
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock # type: ignore
|
||||||
from requests.exceptions import HTTPError
|
from requests.exceptions import HTTPError
|
||||||
from requests.exceptions import RequestException
|
from requests.exceptions import RequestException
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ import unittest
|
|||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives import serialization
|
from cryptography.hazmat.primitives import serialization
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock # type: ignore
|
||||||
import OpenSSL
|
import OpenSSL
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import six
|
import six
|
||||||
|
|||||||
+10
-2
@@ -47,7 +47,6 @@ install_requires = [
|
|||||||
# 1.1.0+ is required to avoid the warnings described at
|
# 1.1.0+ is required to avoid the warnings described at
|
||||||
# https://github.com/certbot/josepy/issues/13.
|
# https://github.com/certbot/josepy/issues/13.
|
||||||
'josepy>=1.1.0',
|
'josepy>=1.1.0',
|
||||||
'mock',
|
|
||||||
'parsedatetime>=1.3', # Calendar.parseDT
|
'parsedatetime>=1.3', # Calendar.parseDT
|
||||||
'pyrfc3339',
|
'pyrfc3339',
|
||||||
'pytz',
|
'pytz',
|
||||||
@@ -62,7 +61,8 @@ install_requires = [
|
|||||||
# So this dependency is not added for old Linux distributions with old setuptools,
|
# So this dependency is not added for old Linux distributions with old setuptools,
|
||||||
# in order to allow these systems to build certbot from sources.
|
# in order to allow these systems to build certbot from sources.
|
||||||
pywin32_req = 'pywin32>=227' # do not forget to edit pywin32 dependency accordingly in windows-installer/construct.py
|
pywin32_req = 'pywin32>=227' # do not forget to edit pywin32 dependency accordingly in windows-installer/construct.py
|
||||||
if StrictVersion(setuptools_version) >= StrictVersion('36.2'):
|
setuptools_known_environment_markers = (StrictVersion(setuptools_version) >= StrictVersion('36.2'))
|
||||||
|
if setuptools_known_environment_markers:
|
||||||
install_requires.append(pywin32_req + " ; sys_platform == 'win32'")
|
install_requires.append(pywin32_req + " ; sys_platform == 'win32'")
|
||||||
elif 'bdist_wheel' in sys.argv[1:]:
|
elif 'bdist_wheel' in sys.argv[1:]:
|
||||||
raise RuntimeError('Error, you are trying to build certbot wheels using an old version '
|
raise RuntimeError('Error, you are trying to build certbot wheels using an old version '
|
||||||
@@ -73,6 +73,14 @@ elif os.name == 'nt':
|
|||||||
# setuptools, pywin32 will not be specified as a dependency.
|
# setuptools, pywin32 will not be specified as a dependency.
|
||||||
install_requires.append(pywin32_req)
|
install_requires.append(pywin32_req)
|
||||||
|
|
||||||
|
if setuptools_known_environment_markers:
|
||||||
|
install_requires.append('mock ; python_version < "3.3"')
|
||||||
|
elif 'bdist_wheel' in sys.argv[1:]:
|
||||||
|
raise RuntimeError('Error, you are trying to build certbot wheels using an old version '
|
||||||
|
'of setuptools. Version 36.2+ of setuptools is required.')
|
||||||
|
elif sys.version_info < (3,3):
|
||||||
|
install_requires.append('mock')
|
||||||
|
|
||||||
dev_extras = [
|
dev_extras = [
|
||||||
'coverage',
|
'coverage',
|
||||||
'ipdb',
|
'ipdb',
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import json
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from acme import messages
|
from acme import messages
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import functools
|
|||||||
import logging
|
import logging
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import zope.component
|
import zope.component
|
||||||
|
|
||||||
from acme import challenges
|
from acme import challenges
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ import tempfile
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import configobj
|
import configobj
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
from certbot._internal import configuration
|
from certbot._internal import configuration
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import copy
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import six
|
import six
|
||||||
from six.moves import reload_module # pylint: disable=import-error
|
from six.moves import reload_module # pylint: disable=import-error
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ import tempfile
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from josepy import interfaces
|
from josepy import interfaces
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
from certbot import util
|
from certbot import util
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import contextlib
|
|||||||
import errno
|
import errno
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from certbot import util
|
from certbot import util
|
||||||
from certbot._internal import lock
|
from certbot._internal import lock
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"""Tests for certbot._internal.configuration."""
|
"""Tests for certbot._internal.configuration."""
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
from certbot._internal import constants
|
from certbot._internal import constants
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
import logging
|
import logging
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import OpenSSL
|
import OpenSSL
|
||||||
import zope.component
|
import zope.component
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ import string
|
|||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
from six.moves import reload_module # pylint: disable=import-error
|
from six.moves import reload_module # pylint: disable=import-error
|
||||||
|
|
||||||
from certbot.compat import filesystem # pylint: disable=ungrouped-imports
|
from certbot.compat import filesystem # pylint: disable=ungrouped-imports
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import zope.component
|
import zope.component
|
||||||
|
|
||||||
from acme import messages
|
from acme import messages
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import socket
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"""Tests for certbot._internal.eff."""
|
"""Tests for certbot._internal.eff."""
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from certbot._internal import constants
|
from certbot._internal import constants
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import signal
|
|||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from certbot.compat import os
|
from certbot.compat import os
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"""Tests for certbot.errors."""
|
"""Tests for certbot.errors."""
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from acme import messages
|
from acme import messages
|
||||||
from certbot import achallenges
|
from certbot import achallenges
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"""Tests for certbot._internal.hooks."""
|
"""Tests for certbot._internal.hooks."""
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
from certbot import util
|
from certbot import util
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import functools
|
|||||||
import multiprocessing
|
import multiprocessing
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
from certbot.compat import os
|
from certbot.compat import os
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from acme import messages
|
from acme import messages
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ import traceback
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import pytz
|
import pytz
|
||||||
import six
|
import six
|
||||||
from six.moves import reload_module # pylint: disable=import-error
|
from six.moves import reload_module # pylint: disable=import-error
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ from cryptography.exceptions import InvalidSignature
|
|||||||
from cryptography.exceptions import UnsupportedAlgorithm
|
from cryptography.exceptions import UnsupportedAlgorithm
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives import hashes # type: ignore
|
from cryptography.hazmat.primitives import hashes # type: ignore
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import shutil
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from acme import challenges
|
from acme import challenges
|
||||||
from certbot import achallenges
|
from certbot import achallenges
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import functools
|
|||||||
import string
|
import string
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import six
|
import six
|
||||||
import zope.interface
|
import zope.interface
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from certbot.plugins import dns_common_lexicon
|
from certbot.plugins import dns_common_lexicon
|
||||||
from certbot.plugins import dns_test_common_lexicon
|
from certbot.plugins import dns_test_common_lexicon
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import collections
|
|||||||
import logging
|
import logging
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
from certbot import util
|
from certbot import util
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"""Tests for new style enhancements"""
|
"""Tests for new style enhancements"""
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from certbot._internal.plugins import null
|
from certbot._internal.plugins import null
|
||||||
from certbot.plugins import enhancements
|
from certbot.plugins import enhancements
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from acme import challenges
|
from acme import challenges
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"""Tests for certbot._internal.plugins.null."""
|
"""Tests for certbot._internal.plugins.null."""
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import zope.component
|
import zope.component
|
||||||
|
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ from socket import errno as socket_errors # type: ignore
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import OpenSSL.crypto # pylint: disable=unused-import
|
import OpenSSL.crypto # pylint: disable=unused-import
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
import json
|
import json
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
from certbot.compat import filesystem
|
from certbot.compat import filesystem
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"""Tests for certbot.plugins.util."""
|
"""Tests for certbot.plugins.util."""
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from certbot.compat import os
|
from certbot.compat import os
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ import tempfile
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from acme import challenges
|
from acme import challenges
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"""Tests for certbot._internal.renewal"""
|
"""Tests for certbot._internal.renewal"""
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from acme import challenges
|
from acme import challenges
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"""Tests for renewal updater interfaces"""
|
"""Tests for renewal updater interfaces"""
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
from certbot import interfaces
|
from certbot import interfaces
|
||||||
from certbot._internal import main
|
from certbot._internal import main
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ import shutil
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from certbot import errors
|
from certbot import errors
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import stat
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import configobj
|
import configobj
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import pytz
|
import pytz
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import errno
|
|||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
try:
|
||||||
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock
|
||||||
import six
|
import six
|
||||||
from six.moves import reload_module # pylint: disable=import-error
|
from six.moves import reload_module # pylint: disable=import-error
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user