diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2010-01-02 22:28:48 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2010-01-02 22:28:48 (GMT) |
commit | 443ec6875f04c8111832307c047409792cd445d1 (patch) | |
tree | 7e2f3a41bbbb494feda2b6831ce180410d5e952d /Lib/test/test_hashlib.py | |
parent | c2fa18ca20e9ad1b8931eec61ece2a93e24766db (diff) | |
download | cpython-443ec6875f04c8111832307c047409792cd445d1.zip cpython-443ec6875f04c8111832307c047409792cd445d1.tar.gz cpython-443ec6875f04c8111832307c047409792cd445d1.tar.bz2 |
Issue #3745: Undo the requirement for new buffer API only objects to be passed
to hashlib functions in python 2.x. The module now uses the 's*' for argument
parsing which auto encodes unicode objects to the system default encoding for
us.
Diffstat (limited to 'Lib/test/test_hashlib.py')
-rw-r--r-- | Lib/test/test_hashlib.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py index 7184316..fdf2b9e 100644 --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -71,18 +71,23 @@ class HashLibTestCase(unittest.TestCase): computed = hashlib.new(name, data).hexdigest() self.assertEqual(computed, digest) - def check_no_unicode(self, algorithm_name): + def check_unicode(self, algorithm_name): # Unicode objects are not allowed as input. - self.assertRaises(TypeError, getattr(hashlib, algorithm_name), u'spam') - self.assertRaises(TypeError, hashlib.new, algorithm_name, u'spam') - - def test_no_unicode(self): - self.check_no_unicode('md5') - self.check_no_unicode('sha1') - self.check_no_unicode('sha224') - self.check_no_unicode('sha256') - self.check_no_unicode('sha384') - self.check_no_unicode('sha512') + expected = hashlib.new(algorithm_name, str(u'spam')).hexdigest() + self.assertEqual(getattr(hashlib, algorithm_name)(u'spam').hexdigest(), + expected) + self.assertEqual(hashlib.new(algorithm_name, u'spam').hexdigest(), + expected) + + def test_unicode(self): + # In python 2.x unicode is auto-encoded to the system default encoding + # when passed to hashlib functions. + self.check_unicode('md5') + self.check_unicode('sha1') + self.check_unicode('sha224') + self.check_unicode('sha256') + self.check_unicode('sha384') + self.check_unicode('sha512') def test_case_md5_0(self): self.check('md5', '', 'd41d8cd98f00b204e9800998ecf8427e') |