From 0faab2234cddc6afad5b85fd54e486f0edce661a Mon Sep 17 00:00:00 2001 From: Miro Hrončok Date: Jan 11 2022 00:59:57 +0000 Subject: Use unittest.mock on Python 3 See https://bugzilla.redhat.com/show_bug.cgi?id=2029012#c5 And https://fedoraproject.org/wiki/Changes/DeprecatePythonMock#How_to_migrate_to_unittest.mock Signed-off-by: Miro Hrončok --- diff --git a/requirements/fedora-py3.txt b/requirements/fedora-py3.txt index fc799c3..7c366ea 100644 --- a/requirements/fedora-py3.txt +++ b/requirements/fedora-py3.txt @@ -14,6 +14,5 @@ python3-yaml # For running tests python3-coverage python3-flake8 -python3-mock python3-rpmfluff python3-openidc-client # used in MBS tests diff --git a/requirements/test-pypi.txt b/requirements/test-pypi.txt index b732dcb..830d8c3 100644 --- a/requirements/test-pypi.txt +++ b/requirements/test-pypi.txt @@ -1,5 +1,5 @@ coverage -mock == 1.0.1 +mock == 1.0.1;python_version<"3.3" flake8 pytest pytest-cov diff --git a/tests/commands/test_check_repo.py b/tests/commands/test_check_repo.py index fa9fb1c..8952481 100644 --- a/tests/commands/test_check_repo.py +++ b/tests/commands/test_check_repo.py @@ -5,10 +5,14 @@ import subprocess import sys import tempfile -from mock import patch from pyrpkg.errors import rpkgError from six.moves import StringIO +try: + from unittest.mock import patch +except ImportError: + from mock import patch + from . import CommandTestCase diff --git a/tests/test_cli.py b/tests/test_cli.py index 90c2067..133380b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -16,10 +16,14 @@ import git import koji_cli.lib import six import utils -from mock import ANY, Mock, PropertyMock, call, mock_open, patch from six.moves import StringIO, configparser, http_client from utils import CommandTestCase, FakeThreadPool +try: + from unittest.mock import ANY, Mock, PropertyMock, call, mock_open, patch +except ImportError: + from mock import ANY, Mock, PropertyMock, call, mock_open, patch + import pyrpkg.cli from pyrpkg import Commands, Modulemd, layout, rpkgError from pyrpkg.errors import AlreadyUploadedError diff --git a/tests/test_commands.py b/tests/test_commands.py index 079f53a..e3ab001 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -11,9 +11,13 @@ from datetime import datetime import git import rpm import six -from mock import Mock, PropertyMock, call, mock_open, patch from pyrpkg import rpkgError +try: + from unittest.mock import Mock, PropertyMock, call, mock_open, patch +except ImportError: + from mock import Mock, PropertyMock, call, mock_open, patch + from utils import CommandTestCase diff --git a/tests/test_flatpak_build.py b/tests/test_flatpak_build.py index 5098ab7..669b477 100644 --- a/tests/test_flatpak_build.py +++ b/tests/test_flatpak_build.py @@ -3,7 +3,6 @@ import subprocess from textwrap import dedent import requests -from mock import Mock, patch from pyrpkg import Modulemd from utils import CommandTestCase @@ -13,6 +12,10 @@ try: except ImportError: import unittest +try: + from unittest.mock import Mock, patch +except ImportError: + from mock import Mock, patch EOG_MODULEMD = """ document: modulemd diff --git a/tests/test_lookaside.py b/tests/test_lookaside.py index f36a222..35d3499 100644 --- a/tests/test_lookaside.py +++ b/tests/test_lookaside.py @@ -13,10 +13,14 @@ import shutil import tempfile import unittest -import mock import pycurl import six +try: + from unittest import mock +except ImportError: + import mock + from pyrpkg.errors import (AlreadyUploadedError, DownloadError, InvalidHashType, UploadError) from pyrpkg.lookaside import CGILookasideCache diff --git a/tests/test_module_build.py b/tests/test_module_build.py index 266ba81..a1a27fb 100644 --- a/tests/test_module_build.py +++ b/tests/test_module_build.py @@ -4,7 +4,11 @@ import copy import sys import six -from mock import PropertyMock, patch + +try: + from unittest.mock import PropertyMock, patch +except ImportError: + from mock import PropertyMock, patch from utils import CommandTestCase diff --git a/tests/test_retire.py b/tests/test_retire.py index c41327c..0fef69b 100644 --- a/tests/test_retire.py +++ b/tests/test_retire.py @@ -5,12 +5,16 @@ import shutil import subprocess import tempfile -import mock import pyrpkg.cli import six from pyrpkg.errors import rpkgError from six.moves import configparser +try: + from unittest import mock +except ImportError: + import mock + # For running tests with Python 2 try: import unittest2 as unittest diff --git a/tests/test_side_tag.py b/tests/test_side_tag.py index 766d9e9..7a7f859 100644 --- a/tests/test_side_tag.py +++ b/tests/test_side_tag.py @@ -4,11 +4,15 @@ import logging import os import koji -import mock import pyrpkg.cli import six from six.moves import StringIO, configparser +try: + from unittest import mock +except ImportError: + import mock + from utils import CommandTestCase if six.PY2: diff --git a/tests/test_utils.py b/tests/test_utils.py index 557cf66..34188c5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,7 +3,11 @@ import tempfile import unittest import warnings -import mock +try: + from unittest import mock +except ImportError: + import mock + from pyrpkg.utils import (cached_property, is_file_in_directory, is_file_tracked, log_result, warn_deprecated)