From 41048f60b7e1542fd3d7c7c3efc2f8f657d05863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 26 Jan 2023 13:04:21 +0100 Subject: [PATCH] Update to work with latest mock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `called_once` attribute now raises an exception. Switch to `assert_called_once` method. Also replace `assertTrue(x.called)` with `x.assert_called()`. Signed-off-by: Lubomír Sedlář (cherry picked from commit 51628a974dfa4995e6ab44f9997b42d6c761de53) --- tests/test_imagebuildphase.py | 42 +++++++++++++++++------------------ tests/test_liveimagesphase.py | 16 ++++++------- tests/test_livemediaphase.py | 10 ++++----- tests/test_notifier.py | 4 ++-- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/test_imagebuildphase.py b/tests/test_imagebuildphase.py index a618a377..05a65db7 100644 --- a/tests/test_imagebuildphase.py +++ b/tests/test_imagebuildphase.py @@ -45,7 +45,7 @@ class TestImageBuildPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() client_args = { "original_image_conf": original_image_conf, "image_conf": { @@ -137,7 +137,7 @@ class TestImageBuildPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() server_args = { "original_image_conf": original_image_conf, "image_conf": { @@ -196,7 +196,7 @@ class TestImageBuildPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() server_args = { "original_image_conf": original_image_conf, "image_conf": { @@ -261,8 +261,8 @@ class TestImageBuildPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertFalse(phase.pool.add.called) - self.assertFalse(phase.pool.queue_put.called) + phase.pool.add.assert_not_called() + phase.pool.queue_put.assert_not_called() @mock.patch("pungi.phases.image_build.ThreadPool") def test_image_build_set_install_tree(self, ThreadPool): @@ -297,9 +297,9 @@ class TestImageBuildPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() - self.assertTrue(phase.pool.queue_put.called_once) + phase.pool.queue_put.assert_called_once() args, kwargs = phase.pool.queue_put.call_args self.assertEqual(args[0][0], compose) self.assertDictEqual( @@ -364,9 +364,9 @@ class TestImageBuildPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() - self.assertTrue(phase.pool.queue_put.called_once) + phase.pool.queue_put.assert_called_once() args, kwargs = phase.pool.queue_put.call_args self.assertEqual(args[0][0], compose) self.assertDictEqual( @@ -430,9 +430,9 @@ class TestImageBuildPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() - self.assertTrue(phase.pool.queue_put.called_once) + phase.pool.queue_put.assert_called_once() args, kwargs = phase.pool.queue_put.call_args self.assertEqual(args[0][0], compose) self.assertDictEqual( @@ -501,9 +501,9 @@ class TestImageBuildPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() - self.assertTrue(phase.pool.queue_put.called_once) + phase.pool.queue_put.assert_called_once() args, kwargs = phase.pool.queue_put.call_args self.assertEqual(args[0][0], compose) self.assertDictEqual( @@ -569,9 +569,9 @@ class TestImageBuildPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() - self.assertTrue(phase.pool.queue_put.called_once) + phase.pool.queue_put.assert_called_once() args, kwargs = phase.pool.queue_put.call_args self.assertEqual( args[0][1].get("image_conf", {}).get("image-build", {}).get("release"), @@ -612,9 +612,9 @@ class TestImageBuildPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() - self.assertTrue(phase.pool.queue_put.called_once) + phase.pool.queue_put.assert_called_once() args, kwargs = phase.pool.queue_put.call_args self.assertEqual( args[0][1].get("image_conf", {}).get("image-build", {}).get("release"), @@ -655,9 +655,9 @@ class TestImageBuildPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() - self.assertTrue(phase.pool.queue_put.called_once) + phase.pool.queue_put.assert_called_once() args, kwargs = phase.pool.queue_put.call_args self.assertTrue(args[0][1].get("scratch")) @@ -692,7 +692,7 @@ class TestImageBuildPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() server_args = { "original_image_conf": original_image_conf, "image_conf": { @@ -755,7 +755,7 @@ class TestImageBuildPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() server_args = { "original_image_conf": original_image_conf, "image_conf": { diff --git a/tests/test_liveimagesphase.py b/tests/test_liveimagesphase.py index 8321a53e..7ef9e398 100644 --- a/tests/test_liveimagesphase.py +++ b/tests/test_liveimagesphase.py @@ -43,7 +43,7 @@ class TestLiveImagesPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() self.maxDiff = None six.assertCountEqual( self, @@ -124,7 +124,7 @@ class TestLiveImagesPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() self.maxDiff = None six.assertCountEqual( self, @@ -192,7 +192,7 @@ class TestLiveImagesPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() self.maxDiff = None six.assertCountEqual( self, @@ -265,7 +265,7 @@ class TestLiveImagesPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() self.maxDiff = None six.assertCountEqual( self, @@ -363,7 +363,7 @@ class TestLiveImagesPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() self.maxDiff = None six.assertCountEqual( self, @@ -433,7 +433,7 @@ class TestLiveImagesPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() self.maxDiff = None six.assertCountEqual( self, @@ -503,7 +503,7 @@ class TestLiveImagesPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() self.maxDiff = None six.assertCountEqual( self, @@ -571,7 +571,7 @@ class TestLiveImagesPhase(PungiTestCase): phase.run() # assert at least one thread was started - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() self.maxDiff = None six.assertCountEqual( self, diff --git a/tests/test_livemediaphase.py b/tests/test_livemediaphase.py index 9dfe76b4..c286fad1 100644 --- a/tests/test_livemediaphase.py +++ b/tests/test_livemediaphase.py @@ -36,7 +36,7 @@ class TestLiveMediaPhase(PungiTestCase): phase = LiveMediaPhase(compose) phase.run() - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() self.assertEqual( phase.pool.queue_put.call_args_list, [ @@ -93,7 +93,7 @@ class TestLiveMediaPhase(PungiTestCase): phase = LiveMediaPhase(compose) phase.run() - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() self.assertEqual( phase.pool.queue_put.call_args_list, [ @@ -156,7 +156,7 @@ class TestLiveMediaPhase(PungiTestCase): phase = LiveMediaPhase(compose) phase.run() - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() self.assertEqual( phase.pool.queue_put.call_args_list, [ @@ -267,7 +267,7 @@ class TestLiveMediaPhase(PungiTestCase): phase = LiveMediaPhase(compose) phase.run() - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() self.assertEqual( phase.pool.queue_put.call_args_list, [ @@ -444,7 +444,7 @@ class TestLiveMediaPhase(PungiTestCase): phase = LiveMediaPhase(compose) phase.run() - self.assertTrue(phase.pool.add.called) + phase.pool.add.assert_called() self.assertEqual( phase.pool.queue_put.call_args_list, diff --git a/tests/test_notifier.py b/tests/test_notifier.py index 8e7d598e..750953d1 100644 --- a/tests/test_notifier.py +++ b/tests/test_notifier.py @@ -133,7 +133,7 @@ class TestNotifier(unittest.TestCase): def test_does_not_run_without_config(self, run, makedirs): n = PungiNotifier(None) n.send("cmd", foo="bar", baz="quux") - self.assertFalse(run.called) + run.assert_not_called() @mock.patch("pungi.util.translate_path") @mock.patch("kobo.shortcuts.run") @@ -146,4 +146,4 @@ class TestNotifier(unittest.TestCase): n.send("cmd", **self.data) self.assertEqual(run.call_args_list, [self._call("run-notify", "cmd")]) - self.assertTrue(self.compose.log_warning.called) + self.compose.log_warning.assert_called()