From: John Mulligan Date: Thu, 1 Jun 2023 15:16:13 +0000 (-0400) Subject: cephadm: change tests to assert using mock call not func.args X-Git-Tag: v18.2.1~326^2~75 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=4e57a530eb1b70131b6acaba02f7112af04ff1e7;p=ceph-ci.git cephadm: change tests to assert using mock call not func.args The Python docs [1] note that: Changed in version 3.8: Added args and kwargs properties. In order to run tests on python 3.6 (example: `tox -e py36`) we change the tests to do the asserts using the older call(...) comparison style, with mock.ANY used for args we don't care about. [1] - https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.call_args Signed-off-by: John Mulligan --- diff --git a/src/cephadm/tests/test_util_funcs.py b/src/cephadm/tests/test_util_funcs.py index f29c0819fb5..ea79c0877a9 100644 --- a/src/cephadm/tests/test_util_funcs.py +++ b/src/cephadm/tests/test_util_funcs.py @@ -94,7 +94,7 @@ class TestCopyTree: self._copy_tree([src1], dst, uid=0, gid=0) assert len(_chown.mock_calls) >= 2 for c in _chown.mock_calls: - assert c.args[1:] == (0, 0) + assert c == mock.call(mock.ANY, 0, 0) assert (dst / "foo.txt").exists() @@ -187,7 +187,7 @@ class TestCopyFiles: self._copy_files([file1], dst, uid=0, gid=0) assert len(_chown.mock_calls) >= 1 for c in _chown.mock_calls: - assert c.args[1:] == (0, 0) + assert c == mock.call(mock.ANY, 0, 0) assert (dst / "f1.txt").exists() @@ -270,7 +270,7 @@ class TestMoveFiles: self._move_files([file1], dst, uid=0, gid=0) assert len(_chown.mock_calls) >= 1 for c in _chown.mock_calls: - assert c.args[1:] == (0, 0) + assert c == mock.call(mock.ANY, 0, 0) assert dst.is_file() assert not file1.exists() @@ -288,9 +288,9 @@ def test_recursive_chown(tmp_path): _chown.return_value = None _cephadm.recursive_chown(str(d1), uid=500, gid=500) assert len(_chown.mock_calls) == 3 - assert _chown.mock_calls[0].args == (str(d1), 500, 500) - assert _chown.mock_calls[1].args == (str(d2), 500, 500) - assert _chown.mock_calls[2].args == (str(f1), 500, 500) + assert _chown.mock_calls[0] == mock.call(str(d1), 500, 500) + assert _chown.mock_calls[1] == mock.call(str(d2), 500, 500) + assert _chown.mock_calls[2] == mock.call(str(f1), 500, 500) class TestFindExecutable: