]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: change tests to assert using mock call not func.args
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 1 Jun 2023 15:16:13 +0000 (11:16 -0400)
committerAdam King <adking@redhat.com>
Thu, 31 Aug 2023 17:35:13 +0000 (13:35 -0400)
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 <jmulligan@redhat.com>
src/cephadm/tests/test_util_funcs.py

index f29c0819fb570d0793174925a35d563feb3df3d6..ea79c0877a9adbd83ca0f0d190a9d899a7dd46b8 100644 (file)
@@ -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: