aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2022-12-30 11:37:03 +0100
committerSam James <sam@gentoo.org>2022-12-31 13:33:03 +0000
commit3a349232febc295565dee8dd1b25f9a76726b50a (patch)
tree89d14a2127d70b160a8c6fcc9cf1cc4f6b4c87a9
parentRework signal handling in entry scripts (diff)
downloadportage-3a349232.tar.gz
portage-3a349232.tar.bz2
portage-3a349232.zip
Inline Whirlpool tests in test_whirlpool
Inline the Whirlpool tests in the test case instead of spawning them as a subprocess. Signed-off-by: Michał Górny <mgorny@gentoo.org> Signed-off-by: Sam James <sam@gentoo.org>
-rw-r--r--lib/portage/tests/util/test_whirlpool.py34
-rw-r--r--lib/portage/util/whirlpool.py29
2 files changed, 22 insertions, 41 deletions
diff --git a/lib/portage/tests/util/test_whirlpool.py b/lib/portage/tests/util/test_whirlpool.py
index 554fffc6a..d93467b21 100644
--- a/lib/portage/tests/util/test_whirlpool.py
+++ b/lib/portage/tests/util/test_whirlpool.py
@@ -1,23 +1,27 @@
-# Copyright 2011-2014 Gentoo Foundation
+# Copyright 2011-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
-import subprocess
-
-import portage
-from portage import os
-from portage.const import PORTAGE_PYM_PATH
from portage.tests import TestCase
+from portage.util.whirlpool import Whirlpool
class WhirlpoolTestCase(TestCase):
def testBundledWhirlpool(self):
- # execute the tests bundled with the whirlpool module
- retval = subprocess.call(
- [
- portage._python_interpreter,
- "-b",
- "-Wd",
- os.path.join(PORTAGE_PYM_PATH, "portage/util/whirlpool.py"),
- ]
+ self.assertEqual(
+ Whirlpool(b"The quick brown fox jumps over the lazy dog").hexdigest(),
+ "b97de512e91e3828b40d2b0fdce9ceb3c4a71f9bea8d88e75c4fa854df36725fd2b52eb6544edcacd6f8beddfea403cb55ae31f03ad62a5ef54e42ee82c3fb35",
+ )
+ self.assertEqual(
+ Whirlpool(b"The quick brown fox jumps over the lazy eog").hexdigest(),
+ "c27ba124205f72e6847f3e19834f925cc666d0974167af915bb462420ed40cc50900d85a1f923219d832357750492d5c143011a76988344c2635e69d06f2d38c",
+ )
+ self.assertEqual(
+ Whirlpool(b"").hexdigest(),
+ "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3",
+ )
+ w = Whirlpool()
+ w.update(b"")
+ self.assertEqual(
+ w.hexdigest(),
+ "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3",
)
- self.assertEqual(retval, os.EX_OK)
diff --git a/lib/portage/util/whirlpool.py b/lib/portage/util/whirlpool.py
index b62191d91..1431c18fb 100644
--- a/lib/portage/util/whirlpool.py
+++ b/lib/portage/util/whirlpool.py
@@ -1,3 +1,6 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
# whirlpool.py - pure Python implementation of the Whirlpool algorithm.
# Bjorn Edstrom <be@bjrn.se> 16 december 2007.
##
@@ -2372,29 +2375,3 @@ def processBuffer(ctx):
# apply the Miyaguchi-Preneel compression function
for i in range(8):
ctx.hash[i] ^= state[i] ^ block[i]
-
-
-#
-# Tests.
-#
-
-
-if __name__ == "__main__":
- assert (
- Whirlpool(b"The quick brown fox jumps over the lazy dog").hexdigest()
- == "b97de512e91e3828b40d2b0fdce9ceb3c4a71f9bea8d88e75c4fa854df36725fd2b52eb6544edcacd6f8beddfea403cb55ae31f03ad62a5ef54e42ee82c3fb35"
- )
- assert (
- Whirlpool(b"The quick brown fox jumps over the lazy eog").hexdigest()
- == "c27ba124205f72e6847f3e19834f925cc666d0974167af915bb462420ed40cc50900d85a1f923219d832357750492d5c143011a76988344c2635e69d06f2d38c"
- )
- assert (
- Whirlpool(b"").hexdigest()
- == "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3"
- )
- w = Whirlpool()
- w.update(b"")
- assert (
- w.hexdigest()
- == "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3"
- )