Update to work with latest mock

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ář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2023-01-26 13:04:21 +01:00
parent 88327d5784
commit 51628a974d
4 changed files with 36 additions and 36 deletions

View File

@ -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": {

View File

@ -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,

View File

@ -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,

View File

@ -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()