Skip to content

Commit

Permalink
Always call progress.quit in mocked installing packages in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pkratoch committed Sep 19, 2024
1 parent 8f82c0b commit 0365101
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,26 +512,28 @@ def _get_transaction_item(self, name, action=libdnf5.transaction.TransactionItem

def _install_packages(self, base, transaction, progress):
"""Simulate the installation of packages."""
transaction_items = list(map(self._get_transaction_item, ["p1", "p2", "p3"]))
ts_total = len(transaction_items)
for ts_done, item in enumerate(transaction_items):
progress.install_start(item, ts_total)
progress.install_progress(item, ts_done, ts_total)
progress.script_start(
item,
item.nevra,
libdnf5.rpm.TransactionCallbacks.ScriptType_PRE_INSTALL
)
progress.install_progress(item, ts_done + 1, ts_total)

for ts_done, item in enumerate(transaction_items):
progress.script_start(
item,
item.nevra,
libdnf5.rpm.TransactionCallbacks.ScriptType_POST_TRANSACTION
)

progress.quit("DNF quit")
try:
transaction_items = list(map(self._get_transaction_item, ["p1", "p2", "p3"]))
ts_total = len(transaction_items)
for ts_done, item in enumerate(transaction_items):
progress.install_start(item, ts_total)
progress.install_progress(item, ts_done, ts_total)
progress.script_start(
item,
item.nevra,
libdnf5.rpm.TransactionCallbacks.ScriptType_PRE_INSTALL
)
progress.install_progress(item, ts_done + 1, ts_total)

for ts_done, item in enumerate(transaction_items):
progress.script_start(
item,
item.nevra,
libdnf5.rpm.TransactionCallbacks.ScriptType_POST_TRANSACTION
)
finally:
# The quit must be called even if there is an error, otherwise the process never quits.
progress.quit("DNF quit")

@patch.object(DNFManager, '_run_transaction')
def test_install_packages_failed(self, run_transaction):
Expand Down

0 comments on commit 0365101

Please sign in to comment.