Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_md5.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 0e29bb80e227 |
| children |
| rev | line source |
|---|---|
|
1422
8a90c9bbbdf0
* wdbframewin.py (re_eval): set __privileged__ in globals so private
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 # Testing md5 module |
|
41917
0e29bb80e227
Have md5 raise a DeprecationWarning as per PEP 4.
Brett Cannon <bcannon@gmail.com>
parents:
31389
diff
changeset
|
2 import warnings |
|
0e29bb80e227
Have md5 raise a DeprecationWarning as per PEP 4.
Brett Cannon <bcannon@gmail.com>
parents:
31389
diff
changeset
|
3 warnings.filterwarnings("ignore", "the md5 module is deprecated.*", |
|
0e29bb80e227
Have md5 raise a DeprecationWarning as per PEP 4.
Brett Cannon <bcannon@gmail.com>
parents:
31389
diff
changeset
|
4 DeprecationWarning) |
|
1422
8a90c9bbbdf0
* wdbframewin.py (re_eval): set __privileged__ in globals so private
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 |
|
31168
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
6 import unittest |
|
1422
8a90c9bbbdf0
* wdbframewin.py (re_eval): set __privileged__ in globals so private
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 from md5 import md5 |
|
31168
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
8 from test import test_support |
|
1422
8a90c9bbbdf0
* wdbframewin.py (re_eval): set __privileged__ in globals so private
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 |
|
8a90c9bbbdf0
* wdbframewin.py (re_eval): set __privileged__ in globals so private
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 def hexstr(s): |
|
31168
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
11 import string |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13981
diff
changeset
|
12 h = string.hexdigits |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13981
diff
changeset
|
13 r = '' |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13981
diff
changeset
|
14 for c in s: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13981
diff
changeset
|
15 i = ord(c) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13981
diff
changeset
|
16 r = r + h[(i >> 4) & 0xF] + h[i & 0xF] |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13981
diff
changeset
|
17 return r |
|
1422
8a90c9bbbdf0
* wdbframewin.py (re_eval): set __privileged__ in globals so private
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 |
|
31168
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
19 class MD5_Test(unittest.TestCase): |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
20 |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
21 def md5test(self, s, expected): |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
22 self.assertEqual(hexstr(md5(s).digest()), expected) |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
23 self.assertEqual(md5(s).hexdigest(), expected) |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
24 |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
25 def test_basics(self): |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
26 eq = self.md5test |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
27 eq('', 'd41d8cd98f00b204e9800998ecf8427e') |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
28 eq('a', '0cc175b9c0f1b6a831c399e269772661') |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
29 eq('abc', '900150983cd24fb0d6963f7d28e17f72') |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
30 eq('message digest', 'f96b697d7cb7938d525a2f31aaf161d0') |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
31 eq('abcdefghijklmnopqrstuvwxyz', 'c3fcd3d76192e4007dfb496cca67e13b') |
|
31389
aca1ce1b4b61
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
31168
diff
changeset
|
32 eq('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', |
|
31168
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
33 'd174ab98d277d9f5a5611c2c9f419d9f') |
|
31389
aca1ce1b4b61
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
31168
diff
changeset
|
34 eq('12345678901234567890123456789012345678901234567890123456789012345678901234567890', |
|
31168
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
35 '57edf4a22be3c955ac49da2e2107b67a') |
|
1422
8a90c9bbbdf0
* wdbframewin.py (re_eval): set __privileged__ in globals so private
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 |
|
31168
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
37 def test_hexdigest(self): |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
38 # hexdigest is new with Python 2.0 |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
39 m = md5('testing the hexdigest method') |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
40 h = m.hexdigest() |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
41 self.assertEqual(hexstr(m.digest()), h) |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
42 |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
43 def test_large_update(self): |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
44 aas = 'a' * 64 |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
45 bees = 'b' * 64 |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
46 cees = 'c' * 64 |
|
13981
72f682eb9adb
Added a test of the md5.hexdigest() method. Funny enough, this test
Barry Warsaw <barry@python.org>
parents:
1422
diff
changeset
|
47 |
|
31168
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
48 m1 = md5() |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
49 m1.update(aas) |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
50 m1.update(bees) |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
51 m1.update(cees) |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
52 |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
53 m2 = md5() |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
54 m2.update(aas + bees + cees) |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
55 self.assertEqual(m1.digest(), m2.digest()) |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
56 |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
57 def test_main(): |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
58 test_support.run_unittest(MD5_Test) |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
59 |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
60 if __name__ == '__main__': |
|
48702f19ccfb
Add tests to test_weakref.py to bring code coverage in _weakref.c up to 100%.
Walter Dörwald <walter@livinglogic.de>
parents:
15540
diff
changeset
|
61 test_main() |
