Gentoo Archives: gentoo-commits

From: Sam James <sam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/, lib/portage/util/
Date: Sat, 31 Dec 2022 13:33:11
Message-Id: 1672493583.3a349232febc295565dee8dd1b25f9a76726b50a.sam@gentoo
1 commit: 3a349232febc295565dee8dd1b25f9a76726b50a
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Fri Dec 30 10:37:03 2022 +0000
4 Commit: Sam James <sam <AT> gentoo <DOT> org>
5 CommitDate: Sat Dec 31 13:33:03 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=3a349232
7
8 Inline Whirlpool tests in test_whirlpool
9
10 Inline the Whirlpool tests in the test case instead of spawning them
11 as a subprocess.
12
13 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
14 Signed-off-by: Sam James <sam <AT> gentoo.org>
15
16 lib/portage/tests/util/test_whirlpool.py | 34 ++++++++++++++++++--------------
17 lib/portage/util/whirlpool.py | 29 +++------------------------
18 2 files changed, 22 insertions(+), 41 deletions(-)
19
20 diff --git a/lib/portage/tests/util/test_whirlpool.py b/lib/portage/tests/util/test_whirlpool.py
21 index 554fffc6a..d93467b21 100644
22 --- a/lib/portage/tests/util/test_whirlpool.py
23 +++ b/lib/portage/tests/util/test_whirlpool.py
24 @@ -1,23 +1,27 @@
25 -# Copyright 2011-2014 Gentoo Foundation
26 +# Copyright 2011-2022 Gentoo Authors
27 # Distributed under the terms of the GNU General Public License v2
28
29 -import subprocess
30 -
31 -import portage
32 -from portage import os
33 -from portage.const import PORTAGE_PYM_PATH
34 from portage.tests import TestCase
35 +from portage.util.whirlpool import Whirlpool
36
37
38 class WhirlpoolTestCase(TestCase):
39 def testBundledWhirlpool(self):
40 - # execute the tests bundled with the whirlpool module
41 - retval = subprocess.call(
42 - [
43 - portage._python_interpreter,
44 - "-b",
45 - "-Wd",
46 - os.path.join(PORTAGE_PYM_PATH, "portage/util/whirlpool.py"),
47 - ]
48 + self.assertEqual(
49 + Whirlpool(b"The quick brown fox jumps over the lazy dog").hexdigest(),
50 + "b97de512e91e3828b40d2b0fdce9ceb3c4a71f9bea8d88e75c4fa854df36725fd2b52eb6544edcacd6f8beddfea403cb55ae31f03ad62a5ef54e42ee82c3fb35",
51 + )
52 + self.assertEqual(
53 + Whirlpool(b"The quick brown fox jumps over the lazy eog").hexdigest(),
54 + "c27ba124205f72e6847f3e19834f925cc666d0974167af915bb462420ed40cc50900d85a1f923219d832357750492d5c143011a76988344c2635e69d06f2d38c",
55 + )
56 + self.assertEqual(
57 + Whirlpool(b"").hexdigest(),
58 + "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3",
59 + )
60 + w = Whirlpool()
61 + w.update(b"")
62 + self.assertEqual(
63 + w.hexdigest(),
64 + "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3",
65 )
66 - self.assertEqual(retval, os.EX_OK)
67
68 diff --git a/lib/portage/util/whirlpool.py b/lib/portage/util/whirlpool.py
69 index b62191d91..1431c18fb 100644
70 --- a/lib/portage/util/whirlpool.py
71 +++ b/lib/portage/util/whirlpool.py
72 @@ -1,3 +1,6 @@
73 +# Copyright 2022 Gentoo Authors
74 +# Distributed under the terms of the GNU General Public License v2
75 +
76 # whirlpool.py - pure Python implementation of the Whirlpool algorithm.
77 # Bjorn Edstrom <be@××××.se> 16 december 2007.
78 ##
79 @@ -2372,29 +2375,3 @@ def processBuffer(ctx):
80 # apply the Miyaguchi-Preneel compression function
81 for i in range(8):
82 ctx.hash[i] ^= state[i] ^ block[i]
83 -
84 -
85 -#
86 -# Tests.
87 -#
88 -
89 -
90 -if __name__ == "__main__":
91 - assert (
92 - Whirlpool(b"The quick brown fox jumps over the lazy dog").hexdigest()
93 - == "b97de512e91e3828b40d2b0fdce9ceb3c4a71f9bea8d88e75c4fa854df36725fd2b52eb6544edcacd6f8beddfea403cb55ae31f03ad62a5ef54e42ee82c3fb35"
94 - )
95 - assert (
96 - Whirlpool(b"The quick brown fox jumps over the lazy eog").hexdigest()
97 - == "c27ba124205f72e6847f3e19834f925cc666d0974167af915bb462420ed40cc50900d85a1f923219d832357750492d5c143011a76988344c2635e69d06f2d38c"
98 - )
99 - assert (
100 - Whirlpool(b"").hexdigest()
101 - == "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3"
102 - )
103 - w = Whirlpool()
104 - w.update(b"")
105 - assert (
106 - w.hexdigest()
107 - == "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3"
108 - )