Use unittest.mock instead of mock

The mock third party library was needed for mock support in py2
runtimes. Since we now only support py36 and later, we can use the
standard lib unittest.mock module instead.

Change-Id: Idffdcf1153821c3d9514f3410e5609ea8c99fe74
This commit is contained in:
James Page 2021-12-16 09:20:28 +00:00
parent 9e5f668299
commit e2d8f32d31
14 changed files with 20 additions and 22 deletions

View File

@ -1,5 +1,4 @@
- project:
templates:
- python35-charm-jobs
- openstack-python3-ussuri-jobs
- openstack-cover-jobs

View File

@ -13,11 +13,6 @@ setuptools<50.0.0 # https://github.com/pypa/setuptools/commit/04e3df22df840c6bb
requests>=2.18.4
# Newer mock seems to have some syntax which is newer than python3.5 (e.g.
# f'{something}'
mock>=1.2,<4.0.0; python_version < '3.6'
mock>=1.2; python_version >= '3.6'
stestr>=2.2.0
# Dependency of stestr. Workaround for

View File

@ -14,7 +14,7 @@
"""Tests for reweight_osd action."""
from actions import change_osd_weight as action
from mock import mock
import unittest.mock as mock
from test_utils import CharmTestCase

View File

@ -14,7 +14,7 @@
"""Tests for the list_inconsistent_objs action."""
from actions import list_inconsistent_objs as action
from mock import mock
import unittest.mock as mock
from test_utils import CharmTestCase

View File

@ -107,9 +107,13 @@ class ListPoolsTestCase(CharmTestCase):
def test_getting_list_pools_with_details(self):
"""Test getting list of pools with details."""
self.pools = None
def _function_set(message):
self.pools = json.loads(message['message'])
self.function_set.side_effect = _function_set
list_pools.main()
self.function_get.assert_called_once_with("format")
pools = json.loads(self.function_set.call_args.args[0]["message"])
self.assertEqual(pools[0]["pool"], 1)
self.assertEqual(pools[0]["size"], 3)
self.assertEqual(pools[0]["min_size"], 2)
self.assertEqual(self.pools[0]["pool"], 1)
self.assertEqual(self.pools[0]["size"], 3)
self.assertEqual(self.pools[0]["min_size"], 2)

View File

@ -14,7 +14,7 @@
"""Tests for purge_osd action."""
from actions import purge_osd as action
from mock import mock
import unittest.mock as mock
from test_utils import CharmTestCase

View File

@ -12,7 +12,7 @@
# limitations under the License.
import json
import sys
from mock import mock
import unittest.mock as mock
from test_utils import CharmTestCase

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
import unittest.mock as mock
import subprocess
import test_utils

View File

@ -3,7 +3,7 @@ import json
import unittest
import sys
from mock import patch, MagicMock, DEFAULT, call
from unittest.mock import patch, MagicMock, DEFAULT, call
# python-apt is not installed as part of test-requirements but is imported by
# some charmhelpers modules so create a fake import.

View File

@ -12,7 +12,7 @@
# limitations under the License.
import json
import mock
import unittest.mock as mock
import test_utils
@ -250,7 +250,7 @@ class CephUtilsTestCase(test_utils.CharmTestCase):
def test_set_require_osd_release_raise_call_error(self, log, check_call):
release = 'luminous'
check_call.side_effect = utils.subprocess.CalledProcessError(
0, mock.mock.MagicMock()
0, mock.MagicMock()
)
expected_call = mock.call(
['ceph', 'osd', 'require-osd-release', release]

View File

@ -16,7 +16,7 @@ import unittest
import os
import sys
from mock import patch
from unittest.mock import patch
# import the module we want to test
os.sys.path.insert(1, os.path.join(sys.path[0], 'files/nagios'))

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
import unittest.mock as mock
import sys
import test_utils

View File

@ -1,4 +1,4 @@
from mock import patch
from unittest.mock import patch
from ceph_hooks import check_for_upgrade
from test_utils import CharmTestCase

View File

@ -17,7 +17,7 @@ import unittest
import os
import yaml
from mock import patch
from unittest.mock import patch
def load_config():