diff --git a/swh/model/hashutil.py b/swh/model/hashutil.py index 946edc4a0e252567d3a75614b9686de6ce36e8c2..81c88c3a97688061b3b2390094c2b01dc174ffd6 100644 --- a/swh/model/hashutil.py +++ b/swh/model/hashutil.py @@ -7,7 +7,6 @@ import binascii import functools import hashlib import os -import sys from io import BytesIO @@ -77,16 +76,11 @@ def _new_hash(algo, length=None): raise ValueError('Missing length for git hashing algorithm') base_algo = algo[:-4] h = _new_git_hash(base_algo, 'blob', length) - elif ':' in algo: # variable length hashing algorithms (only from - # python3 >= 3.6) - if sys.version_info.major == 3 and sys.version_info.minor >= 6: - _algo = algo.split(':') - base_algo = _algo[0] - variable_length = int(_algo[1]) - - h = hashlib.new('%s%s' % (base_algo, variable_length)) - else: - raise ValueError('Unsupported hashing algorithm %s' % algo) + elif ':' in algo: # variable length hashing algorithms + _algo = algo.split(':') + base_algo = _algo[0] + variable_length = int(_algo[1]) + h = hashlib.new('%s%s' % (base_algo, variable_length)) else: h = hashlib.new(algo) diff --git a/swh/model/tests/test_hashutil.py b/swh/model/tests/test_hashutil.py index 435909de8ebbc525b7dd07236c0b260664d94949..8d14524dbbdc842d20e346fb0ca16125c0cf075d 100644 --- a/swh/model/tests/test_hashutil.py +++ b/swh/model/tests/test_hashutil.py @@ -8,7 +8,7 @@ import tempfile import unittest from nose.tools import istest -from unittest.mock import MagicMock, patch +from unittest.mock import patch from swh.model import hashutil @@ -131,24 +131,11 @@ class Hashutil(unittest.TestCase): hashutil._new_hash('blake2:10') except ValueError as e: self.assertEquals(str(e), - 'Unsupported hashing algorithm blake2:10') + 'unsupported hash type blake210') - @patch('swh.model.hashutil.sys') - @istest - def new_hash_unexpected_hashing_algo(self, mock_sys): - mock_sys.version_info = MagicMock(major=3, minor=6) - - try: - hashutil._new_hash('blake3:256') - except ValueError as e: - self.assertEquals(str(e), - 'unsupported hash type blake3256') - - @patch('swh.model.hashutil.sys') @patch('swh.model.hashutil.hashlib') @istest - def new_hash_blake2b(self, mock_hashlib, mock_sys): - mock_sys.version_info = MagicMock(major=3, minor=6) + def new_hash_blake2b(self, mock_hashlib): mock_hashlib.new.return_value = 'some-hashlib-object' h = hashutil._new_hash('blake2b:512') @@ -156,17 +143,14 @@ class Hashutil(unittest.TestCase): self.assertEquals(h, 'some-hashlib-object') mock_hashlib.new.assert_called_with('blake2b512') - @patch('swh.model.hashutil.sys') @patch('swh.model.hashutil.hashlib') @istest - def new_hash_blake2s(self, mock_hashlib, mock_sys): - mock_sys.version_info = MagicMock(major=3, minor=6) + def new_hash_blake2s(self, mock_hashlib): mock_hashlib.new.return_value = 'some-hashlib-object' h = hashutil._new_hash('blake2s:256') self.assertEquals(h, 'some-hashlib-object') - mock_hashlib.blake2s.assert_called_with(digest_size=128) mock_hashlib.new.assert_called_with('blake2s256')