mirror of
https://github.com/certbot/certbot.git
synced 2026-01-26 07:41:33 +03:00
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
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
"""Tests for acme.errors."""
|
|
import unittest
|
|
|
|
try:
|
|
import mock
|
|
except ImportError: # pragma: no cover
|
|
from unittest import mock # type: ignore
|
|
|
|
|
|
class BadNonceTest(unittest.TestCase):
|
|
"""Tests for acme.errors.BadNonce."""
|
|
|
|
def setUp(self):
|
|
from acme.errors import BadNonce
|
|
self.error = BadNonce(nonce="xxx", error="error")
|
|
|
|
def test_str(self):
|
|
self.assertEqual("Invalid nonce ('xxx'): error", str(self.error))
|
|
|
|
|
|
class MissingNonceTest(unittest.TestCase):
|
|
"""Tests for acme.errors.MissingNonce."""
|
|
|
|
def setUp(self):
|
|
from acme.errors import MissingNonce
|
|
self.response = mock.MagicMock(headers={})
|
|
self.response.request.method = 'FOO'
|
|
self.error = MissingNonce(self.response)
|
|
|
|
def test_str(self):
|
|
self.assertTrue("FOO" in str(self.error))
|
|
self.assertTrue("{}" in str(self.error))
|
|
|
|
|
|
class PollErrorTest(unittest.TestCase):
|
|
"""Tests for acme.errors.PollError."""
|
|
|
|
def setUp(self):
|
|
from acme.errors import PollError
|
|
self.timeout = PollError(
|
|
exhausted={mock.sentinel.AR},
|
|
updated={})
|
|
self.invalid = PollError(exhausted=set(), updated={
|
|
mock.sentinel.AR: mock.sentinel.AR2})
|
|
|
|
def test_timeout(self):
|
|
self.assertTrue(self.timeout.timeout)
|
|
self.assertFalse(self.invalid.timeout)
|
|
|
|
def test_repr(self):
|
|
self.assertEqual('PollError(exhausted=%s, updated={sentinel.AR: '
|
|
'sentinel.AR2})' % repr(set()), repr(self.invalid))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main() # pragma: no cover
|