equal
deleted
inserted
replaced
|
1 # Tests to ensure that sha1dc.sha1 is exactly a drop-in for |
|
2 # hashlib.sha1 for our needs. |
|
3 from __future__ import absolute_import |
|
4 |
|
5 import hashlib |
|
6 import unittest |
|
7 |
|
8 import silenttestrunner |
|
9 |
|
10 try: |
|
11 from mercurial.thirdparty import sha1dc |
|
12 except ImportError: |
|
13 sha1dc = None |
|
14 |
|
15 |
|
16 class hashertestsbase(object): |
|
17 def test_basic_hash(self): |
|
18 h = self.hasher() |
|
19 h.update(b'foo') |
|
20 self.assertEqual( |
|
21 '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33', h.hexdigest() |
|
22 ) |
|
23 h.update(b'bar') |
|
24 self.assertEqual( |
|
25 '8843d7f92416211de9ebb963ff4ce28125932878', h.hexdigest() |
|
26 ) |
|
27 |
|
28 def test_copy_hasher(self): |
|
29 h = self.hasher() |
|
30 h.update(b'foo') |
|
31 h2 = h.copy() |
|
32 h.update(b'baz') |
|
33 h2.update(b'bar') |
|
34 self.assertEqual( |
|
35 '21eb6533733a5e4763acacd1d45a60c2e0e404e1', h.hexdigest() |
|
36 ) |
|
37 self.assertEqual( |
|
38 '8843d7f92416211de9ebb963ff4ce28125932878', h2.hexdigest() |
|
39 ) |
|
40 |
|
41 def test_init_hasher(self): |
|
42 h = self.hasher(b'initial string') |
|
43 self.assertEqual( |
|
44 b'\xc9y|n\x1f3S\xa4:\xbaJ\xca,\xc1\x1a\x9e\xb8\xd8\xdd\x86', |
|
45 h.digest(), |
|
46 ) |
|
47 |
|
48 |
|
49 class hashlibtests(unittest.TestCase, hashertestsbase): |
|
50 hasher = hashlib.sha1 |
|
51 |
|
52 |
|
53 if sha1dc: |
|
54 |
|
55 class sha1dctests(unittest.TestCase, hashertestsbase): |
|
56 hasher = sha1dc.sha1 |
|
57 |
|
58 |
|
59 if __name__ == '__main__': |
|
60 silenttestrunner.main(__name__) |