diff --git a/certbot/certbot/tests/util.py b/certbot/certbot/tests/util.py index 532220f4d..dbff31a14 100644 --- a/certbot/certbot/tests/util.py +++ b/certbot/certbot/tests/util.py @@ -198,56 +198,18 @@ def make_lineage(config_dir: str, testfile: str, ec: bool = False) -> str: return conf_path -def patch_get_utility(target: str = 'zope.component.getUtility') -> mock.MagicMock: - """Deprecated, patch certbot.display.util directly or use patch_display_util instead. - - :param str target: path to patch - - :returns: mock zope.component.getUtility - :rtype: mock.MagicMock - - """ - warnings.warn('Decorator certbot.tests.util.patch_get_utility is deprecated. You should now ' - 'patch certbot.display.util yourself directly or use ' - 'certbot.tests.util.patch_display_util as a temporary workaround.') - return cast(mock.MagicMock, mock.patch(target, new_callable=_create_display_util_mock)) - - -def patch_get_utility_with_stdout(target: str = 'zope.component.getUtility', - stdout: Optional[IO] = None) -> mock.MagicMock: - """Deprecated, patch certbot.display.util directly - or use patch_display_util_with_stdout instead. - - :param str target: path to patch - :param object stdout: object to write standard output to; it is - expected to have a `write` method - - :returns: mock zope.component.getUtility - :rtype: mock.MagicMock - - """ - warnings.warn('Decorator certbot.tests.util.patch_get_utility_with_stdout is deprecated. You ' - 'should now patch certbot.display.util yourself directly or use ' - 'use certbot.tests.util.patch_display_util_with_stdout as a temporary ' - 'workaround.') - stdout = stdout if stdout else io.StringIO() - freezable_mock = _create_display_util_mock_with_stdout(stdout) - return cast(mock.MagicMock, mock.patch(target, new=freezable_mock)) - - def patch_display_util() -> mock.MagicMock: """Patch certbot.display.util to use a special mock display utility. The mock display utility works like a regular mock object, except it also also asserts that methods are called with valid arguments. - The mock created by this patch mocks out Certbot internals so this can be - used like the old patch_get_utility function. That is, the mock object will - be called by the certbot.display.util functions and the mock returned by - that call will be used as the display utility. This was done to simplify - the transition from zope.component and mocking certbot.display.util - functions directly in test code should be preferred over using this - function in the future. + The mock created by this patch mocks out Certbot internals. That is, the + mock object will be called by the certbot.display.util functions and the + mock returned by that call will be used as the display utility. This was + done to simplify the transition from zope.component and mocking + certbot.display.util functions directly in test code should be preferred + over using this function in the future. See https://github.com/certbot/certbot/issues/8948 @@ -267,13 +229,12 @@ def patch_display_util_with_stdout( The mock display utility works like a regular mock object, except it also asserts that methods are called with valid arguments. - The mock created by this patch mocks out Certbot internals so this can be - used like the old patch_get_utility function. That is, the mock object will - be called by the certbot.display.util functions and the mock returned by - that call will be used as the display utility. This was done to simplify - the transition from zope.component and mocking certbot.display.util - functions directly in test code should be preferred over using this - function in the future. + The mock created by this patch mocks out Certbot internals. That is, the + mock object will be called by the certbot.display.util functions and the + mock returned by that call will be used as the display utility. This was + done to simplify the transition from zope.component and mocking + certbot.display.util functions directly in test code should be preferred + over using this function in the future. See https://github.com/certbot/certbot/issues/8948 diff --git a/certbot/certbot/util.py b/certbot/certbot/util.py index 242dfef5a..12507ef36 100644 --- a/certbot/certbot/util.py +++ b/certbot/certbot/util.py @@ -17,7 +17,6 @@ from typing import List from typing import Optional from typing import Set from typing import Tuple -from typing import TYPE_CHECKING from typing import Union import warnings @@ -33,9 +32,6 @@ _USE_DISTRO = sys.platform.startswith('linux') if _USE_DISTRO: import distro -if TYPE_CHECKING: - import distutils.version - logger = logging.getLogger(__name__) @@ -611,24 +607,6 @@ def is_wildcard_domain(domain: Union[str, bytes]) -> bool: return domain.startswith(b"*.") -def get_strict_version(normalized: str) -> "distutils.version.StrictVersion": - """Converts a normalized version to a strict version. - - :param str normalized: normalized version string - - :returns: An equivalent strict version - :rtype: distutils.version.StrictVersion - - """ - warnings.warn("certbot.util.get_strict_version is deprecated and will be " - "removed in a future release.", DeprecationWarning) - with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) - import distutils.version - # strict version ending with "a" and a number designates a pre-release - return distutils.version.StrictVersion(normalized.replace(".dev", "a")) - - def is_staging(srv: str) -> bool: """ Determine whether a given ACME server is a known test / staging server. diff --git a/certbot/tests/util_test.py b/certbot/tests/util_test.py index 3af87f85a..0da0976b8 100644 --- a/certbot/tests/util_test.py +++ b/certbot/tests/util_test.py @@ -592,19 +592,6 @@ class OsInfoTest(unittest.TestCase): self.assertEqual(cbutil.get_python_os_info(), ("testdist", "42")) -class GetStrictVersionTest(unittest.TestCase): - """Test for certbot.util.get_strict_version.""" - - @classmethod - def _call(cls, *args, **kwargs): - from certbot.util import get_strict_version - return get_strict_version(*args, **kwargs) - - def test_it(self): - with self.assertWarnsRegex(DeprecationWarning, "get_strict_version"): - self._call("1.2.3") - - class AtexitRegisterTest(unittest.TestCase): """Tests for certbot.util.atexit_register.""" def setUp(self):