commit: fa2f4995680414c6f1b852a97655c7ced02f816f
Author: Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Sun Sep 18 17:32:23 2022 +0000
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Sun Sep 18 17:37:50 2022 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=fa2f4995
Add test to cover portage.checksum._apply_hash_filter
Thanks-to: Michał Górny <mgorny <AT> gentoo.org>
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
lib/portage/tests/util/test_checksum.py | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/lib/portage/tests/util/test_checksum.py
b/lib/portage/tests/util/test_checksum.py
index da864ba22..0e49f882f 100644
--- a/lib/portage/tests/util/test_checksum.py
+++ b/lib/portage/tests/util/test_checksum.py
@@ -1,9 +1,9 @@
-# Copyright 2011-2017 Gentoo Foundation
+# Copyright 2011-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
from portage.tests import TestCase
-from portage.checksum import checksum_str
+from portage.checksum import checksum_str, _apply_hash_filter
from portage.exception import DigestException
@@ -146,3 +146,26 @@ class ChecksumTestCase(TestCase):
)
except DigestException:
self.skipTest("STREEBOG512 implementation not available")
+
+
+class ApplyHashFilterTestCase(TestCase):
+ def test_apply_hash_filter(self):
+ indict = {"MD5": "", "SHA1": "", "SHA256": "", "size": ""}
+
+ self.assertEqual(
+ sorted(_apply_hash_filter(indict, lambda x: True)),
+ ["MD5", "SHA1", "SHA256", "size"],
+ )
+ self.assertEqual(
+ sorted(_apply_hash_filter(indict, lambda x: x == "MD5")), ["MD5",
"size"]
+ )
+ self.assertEqual(
+ sorted(_apply_hash_filter(indict, lambda x: x != "MD5")),
+ ["SHA1", "SHA256", "size"],
+ )
+ self.assertEqual(
+ sorted(_apply_hash_filter(indict, lambda x: x == "SHA256")),
+ ["SHA256", "size"],
+ )
+ # this should return size + one of the hashes
+ self.assertEqual(len(list(_apply_hash_filter(indict, lambda x:
False))), 2)