mirror of
https://github.com/certbot/certbot.git
synced 2026-08-04 12:13:34 +02:00
Do not require mock in Python 3 in acme module (#7910)
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. Now with `type: ignore` as appropriate. Once the "future steps" of #7886 are finished, and mypy is on Python 3, the `pragma no cover`s and `type ignore`s will be gone. * Conditionally install mock in acme * error out on newer python and older setuptools * error when trying to build wheels with old setuptools * use unittest.mock when third-party mock isn't available in acme, with no cover and type ignore
This commit is contained in:
+11
-1
@@ -1,5 +1,7 @@
|
|||||||
|
from distutils.version import StrictVersion
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from setuptools import __version__ as setuptools_version
|
||||||
from setuptools import find_packages
|
from setuptools import find_packages
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
from setuptools.command.test import test as TestCommand
|
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
|
# 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',
|
|
||||||
# Connection.set_tlsext_host_name (>=0.13)
|
# Connection.set_tlsext_host_name (>=0.13)
|
||||||
'PyOpenSSL>=0.13.1',
|
'PyOpenSSL>=0.13.1',
|
||||||
'pyrfc3339',
|
'pyrfc3339',
|
||||||
@@ -26,6 +27,15 @@ install_requires = [
|
|||||||
'six>=1.9.0', # needed for python_2_unicode_compatible
|
'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 = [
|
dev_extras = [
|
||||||
'pytest',
|
'pytest',
|
||||||
'pytest-xdist',
|
'pytest-xdist',
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import unittest
|
|||||||
|
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
import OpenSSL
|
import OpenSSL
|
||||||
|
try:
|
||||||
import mock
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock # type: ignore
|
||||||
import requests
|
import requests
|
||||||
from six.moves.urllib import parse as urllib_parse
|
from six.moves.urllib import parse as urllib_parse
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import json
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
|
try:
|
||||||
import mock
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock # type: ignore
|
||||||
import OpenSSL
|
import OpenSSL
|
||||||
import requests
|
import requests
|
||||||
from six.moves import http_client # pylint: disable=import-error
|
from six.moves import http_client # pylint: disable=import-error
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"""Tests for acme.errors."""
|
"""Tests for acme.errors."""
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
try:
|
||||||
import mock
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock # type: ignore
|
||||||
|
|
||||||
|
|
||||||
class BadNonceTest(unittest.TestCase):
|
class BadNonceTest(unittest.TestCase):
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
try:
|
||||||
import mock
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock # type: ignore
|
||||||
|
|
||||||
|
|
||||||
class MagicTypingTest(unittest.TestCase):
|
class MagicTypingTest(unittest.TestCase):
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
|
try:
|
||||||
import mock
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock # type: ignore
|
||||||
|
|
||||||
from acme import challenges
|
from acme import challenges
|
||||||
import test_util
|
import test_util
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import threading
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import josepy as jose
|
import josepy as jose
|
||||||
|
try:
|
||||||
import mock
|
import mock
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
from unittest import mock # type: ignore
|
||||||
import requests
|
import requests
|
||||||
from six.moves import http_client # pylint: disable=import-error
|
from six.moves import http_client # pylint: disable=import-error
|
||||||
from six.moves import socketserver # type: ignore # pylint: disable=import-error
|
from six.moves import socketserver # type: ignore # pylint: disable=import-error
|
||||||
|
|||||||
Reference in New Issue
Block a user