1
0
mirror of https://github.com/certbot/certbot.git synced 2026-01-26 07:41:33 +03:00

Do not require mock in Python 3 in acme module (#7894)

Part of #7886.

This PR conditionally installs mock in acme/setup.py based on setuptools version and python version, when possible. It then updates acme tests to use unittest.mock when mock isn't available.

* Conditionally install mock in acme

* use unittest.mock when third-party mock isn't available in acme

* error when trying to build wheels with old setuptools
This commit is contained in:
ohemorange
2020-04-13 14:32:22 -07:00
committed by GitHub
parent 8e4dc0a48c
commit cd0acf5dcc
7 changed files with 35 additions and 7 deletions

View File

@@ -1,5 +1,7 @@
from distutils.version import StrictVersion
import sys
from setuptools import __version__ as setuptools_version
from setuptools import find_packages
from setuptools import setup
from setuptools.command.test import test as TestCommand
@@ -15,7 +17,6 @@ install_requires = [
# 1.1.0+ is required to avoid the warnings described at
# https://github.com/certbot/josepy/issues/13.
'josepy>=1.1.0',
'mock',
# Connection.set_tlsext_host_name (>=0.13)
'PyOpenSSL>=0.13.1',
'pyrfc3339',
@@ -26,6 +27,15 @@ install_requires = [
'six>=1.9.0', # needed for python_2_unicode_compatible
]
setuptools_known_environment_markers = (StrictVersion(setuptools_version) >= StrictVersion('36.2'))
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 = [
'pytest',
'pytest-xdist',

View File

@@ -3,7 +3,10 @@ import unittest
import josepy as jose
import OpenSSL
import mock
try:
import mock
except ImportError: # pragma: no cover
from unittest import mock
import requests
from six.moves.urllib import parse as urllib_parse

View File

@@ -6,7 +6,10 @@ import json
import unittest
import josepy as jose
import mock
try:
import mock
except ImportError: # pragma: no cover
from unittest import mock
import OpenSSL
import requests
from six.moves import http_client # pylint: disable=import-error

View File

@@ -1,7 +1,10 @@
"""Tests for acme.errors."""
import unittest
import mock
try:
import mock
except ImportError: # pragma: no cover
from unittest import mock
class BadNonceTest(unittest.TestCase):

View File

@@ -2,7 +2,10 @@
import sys
import unittest
import mock
try:
import mock
except ImportError: # pragma: no cover
from unittest import mock
class MagicTypingTest(unittest.TestCase):

View File

@@ -2,7 +2,10 @@
import unittest
import josepy as jose
import mock
try:
import mock
except ImportError: # pragma: no cover
from unittest import mock
from acme import challenges
import test_util

View File

@@ -4,7 +4,10 @@ import threading
import unittest
import josepy as jose
import mock
try:
import mock
except ImportError: # pragma: no cover
from unittest import mock
import requests
from six.moves import http_client # pylint: disable=import-error
from six.moves import socketserver # type: ignore # pylint: disable=import-error