[Python-checkins] cpython: Issue #20162: test_hash_distribution() uses subTest() to mention the prefix in

victor.stinner python-checkins at python.org
Tue Jan 7 14:42:14 CET 2014


http://hg.python.org/cpython/rev/81f8b4744f1a
changeset:   88335:81f8b4744f1a
parent:      88333:37caaf21f827
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Jan 07 14:40:51 2014 +0100
summary:
  Issue #20162: test_hash_distribution() uses subTest() to mention the prefix in
the error message.

files:
  Lib/test/test_hash.py |  19 ++++++++++---------
  1 files changed, 10 insertions(+), 9 deletions(-)


diff --git a/Lib/test/test_hash.py b/Lib/test/test_hash.py
--- a/Lib/test/test_hash.py
+++ b/Lib/test/test_hash.py
@@ -330,15 +330,16 @@
         base = "abcdefghabcdefg"
         for i in range(1, len(base)):
             prefix = base[:i]
-            s15 = set()
-            s255 = set()
-            for c in range(256):
-                h = hash(prefix + chr(c))
-                s15.add(h & 0xf)
-                s255.add(h & 0xff)
-            # SipHash24 distribution depends on key, usually > 60%
-            self.assertGreater(len(s15), 8, prefix)
-            self.assertGreater(len(s255), 128, prefix)
+            with self.subTest(prefix=prefix):
+                s15 = set()
+                s255 = set()
+                for c in range(256):
+                    h = hash(prefix + chr(c))
+                    s15.add(h & 0xf)
+                    s255.add(h & 0xff)
+                # SipHash24 distribution depends on key, usually > 60%
+                self.assertGreater(len(s15), 8, prefix)
+                self.assertGreater(len(s255), 128, prefix)
 
 if __name__ == "__main__":
     unittest.main()

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list