]> granicus.if.org Git - python/commitdiff
Issue 18532: Added tests and documentation to formally specify the .name attribute...
authorJason R. Coombs <jaraco@jaraco.com>
Sat, 3 Aug 2013 09:39:39 +0000 (11:39 +0200)
committerJason R. Coombs <jaraco@jaraco.com>
Sat, 3 Aug 2013 09:39:39 +0000 (11:39 +0200)
Doc/library/hashlib.rst
Lib/test/test_hashlib.py

index 6cb76c133f29a6da51508595ed9fd37598f865cf..db41db4ba50dc8773e41e9339f3e7350a1c7a617 100644 (file)
@@ -124,6 +124,18 @@ returned by the constructors:
 
    The internal block size of the hash algorithm in bytes.
 
+A hash object has the following attributes:
+
+.. attribute:: hash.name
+
+   The canonical name of this hash, always lowercase and always suitable as a
+   parameter to :func:`new` to create another hash of this type.
+
+   .. versionchanged:: 3.4
+      The name attribute has been present in CPython since its inception, but
+      until Python 3.4 was not formally specified, so may not exist on some
+      platforms.
+
 A hash object has the following methods:
 
 
index 26012097f2b58cc8dd72ce0192261d4fbf67129e..e944bde3354dd82a37b2ab110a83b1dc769e58ae 100644 (file)
@@ -154,6 +154,11 @@ class HashLibTestCase(unittest.TestCase):
             assert isinstance(h.digest(), bytes), name
             self.assertEqual(hexstr(h.digest()), h.hexdigest())
 
+    def test_name_attribute(self):
+        for cons in self.hash_constructors:
+            h = cons()
+            assert isinstance(h.name, str), "No name attribute"
+            assert h.name in self.supported_hash_names
 
     def test_large_update(self):
         aas = b'a' * 128