The silencing of DeprecationWarning was not taking -3 into consideration. Since
[python.git] / Lib / test / test_sha.py
blob6b38435548c1ddbceee328fce485d973817f91fc
1 # Testing sha module (NIST's Secure Hash Algorithm)
3 # use the three examples from Federal Information Processing Standards
4 # Publication 180-1, Secure Hash Standard, 1995 April 17
5 # http://www.itl.nist.gov/div897/pubs/fip180-1.htm
7 import warnings
8 warnings.filterwarnings("ignore", "the sha module is deprecated.*",
9 DeprecationWarning)
11 import sha
12 import unittest
13 from test import test_support
16 class SHATestCase(unittest.TestCase):
17 def check(self, data, digest):
18 # Check digest matches the expected value
19 obj = sha.new(data)
20 computed = obj.hexdigest()
21 self.assertTrue(computed == digest)
23 # Verify that the value doesn't change between two consecutive
24 # digest operations.
25 computed_again = obj.hexdigest()
26 self.assertTrue(computed == computed_again)
28 # Check hexdigest() output matches digest()'s output
29 digest = obj.digest()
30 hexd = ""
31 for c in digest:
32 hexd += '%02x' % ord(c)
33 self.assertTrue(computed == hexd)
35 def test_case_1(self):
36 self.check("abc",
37 "a9993e364706816aba3e25717850c26c9cd0d89d")
39 def test_case_2(self):
40 self.check("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
41 "84983e441c3bd26ebaae4aa1f95129e5e54670f1")
43 def test_case_3(self):
44 self.check("a" * 1000000,
45 "34aa973cd4c4daa4f61eeb2bdbad27316534016f")
47 def test_case_4(self):
48 self.check(chr(0xAA) * 80,
49 '4ca0ef38f1794b28a8f8ee110ee79d48ce13be25')
51 def test_main():
52 test_support.run_unittest(SHATestCase)
55 if __name__ == "__main__":
56 test_main()