From eb120c5e205e4867b7dca5b357c8e4d5a7bd079a Mon Sep 17 00:00:00 2001 From: Evan Goode Date: Thu, 5 Dec 2024 18:09:24 +0000 Subject: [PATCH] Python API: add_new_download return None regression test DownloadCallbacks.add_new_download can now return either None or an int. This adds a regression test to check that add_new_download can still return None. --- .../libdnf5/repo/test_package_downloader.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/python3/libdnf5/repo/test_package_downloader.py b/test/python3/libdnf5/repo/test_package_downloader.py index 4034ab843..74d5a19de 100644 --- a/test/python3/libdnf5/repo/test_package_downloader.py +++ b/test/python3/libdnf5/repo/test_package_downloader.py @@ -108,3 +108,33 @@ def mirror_failure(self, user_cb_data, msg, url): cbs.end_status, [PackageDownloadCallbacks.TransferStatus_SUCCESSFUL, PackageDownloadCallbacks.TransferStatus_SUCCESSFUL]) self.assertEqual(cbs.end_msg, [None, None]) + + +class TestPackageDownloaderReturnNone(base_test_case.BaseTestCase): + # Previously, add_new_download could only return None. This test adds a + # check to ensure backwards-compatibility with that API. + def test_package_downloader_return_none(self): + class PackageDownloadCallbacks(libdnf5.repo.DownloadCallbacks): + def __init__(self): + super(PackageDownloadCallbacks, self).__init__() + + def add_new_download(self, user_data, description, total_to_download): + return None + + repo = self.add_repo_rpm("rpm-repo1") + + query = libdnf5.rpm.PackageQuery(self.base) + query.filter_name(["one"]) + query.filter_arch(["noarch"]) + self.assertEqual(query.size(), 2) + + downloader = libdnf5.repo.PackageDownloader(self.base) + + cbs = PackageDownloadCallbacks() + self.base.set_download_callbacks( + libdnf5.repo.DownloadCallbacksUniquePtr(cbs)) + + for package in query: + downloader.add(package) + + downloader.download()