diff options
author | Michał Górny <mgorny@gentoo.org> | 2017-10-25 09:49:52 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2017-10-25 09:49:52 +0200 |
commit | d0151cbf800a916ec61bce8f3473f6ebea171b90 (patch) | |
tree | 6248a7aef23aecef7b8cedef95f81006cceb309c | |
parent | 5ab985a8d4a9bb8bc3b7ec4dd5c519aa44cbe3a6 (diff) | |
download | gemato-d0151cbf800a916ec61bce8f3473f6ebea171b90.tar.gz |
Commit the utility to generate hash tests
-rwxr-xr-x | utils/gen-hash-tests.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/utils/gen-hash-tests.py b/utils/gen-hash-tests.py new file mode 100755 index 0000000..9999af0 --- /dev/null +++ b/utils/gen-hash-tests.py @@ -0,0 +1,30 @@ +#!/bin/bash +test_string='The quick brown fox jumps over the lazy dog' + +if [[ ${#} -lt 1 ]]; then + echo "Usage: ${0} <hashlib-name> [<program-to-use>]" + exit 1 +fi + +algo=${1} +algo_sum=${2:-${algo}sum} + +empty=$(printf '' | ${algo_sum} | cut -d' ' -f1) +str=$(printf '%s' "${test_string}" | ${algo_sum} | cut -d' ' -f1) + +cat <<_EOF_ + + def test_${algo}(self): + try: + self.assertEqual(hash_bytes(TEST_STRING, '${algo}'), + '${str}') + except UnsupportedHash: + raise unittest.SkipTest('hash not supported') + + def test_${algo}_empty(self): + try: + self.assertEqual(hash_bytes(b'', '${algo}'), + '${empty}') + except UnsupportedHash: + raise unittest.SkipTest('hash not supported') +_EOF_ |