Mercurial > hg
annotate tests/test-hashutil.py @ 44071:34e8305f02bd
lfs: add a switch to `hg verify` to ignore the content of blobs
Trying to validate the fulltext of an external revision causes missing blobs to
be downloaded and cached. Since the downloads aren't batch prefetched[1] and
aren't compressed, this can be expensive both in terms of time and space.
I made this a tri-state instead of a simple bool because there's an existing
(undocumented) config to handle this, and it would be weird if `hg verify` were
to suddenly start ignoring that config but an `hg recover` initiated verify
honors it. Since this uses the same config setting, it too will skip
rename verification (which requires fulltext, but not for LFS).
[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2018-April/116118.html
Differential Revision: https://phab.mercurial-scm.org/D7708
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 20 Dec 2019 01:11:35 -0500 |
parents | bde1cd4c99d9 |
children | dc9b53482689 |
rev | line source |
---|---|
44058
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 # Tests to ensure that sha1dc.sha1 is exactly a drop-in for |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 # hashlib.sha1 for our needs. |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 from __future__ import absolute_import |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
4 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
5 import hashlib |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
6 import unittest |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
7 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
8 import silenttestrunner |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
10 try: |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 from mercurial.thirdparty import sha1dc |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
12 except ImportError: |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 sha1dc = None |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
15 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
16 class hashertestsbase(object): |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
17 def test_basic_hash(self): |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
18 h = self.hasher() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
19 h.update(b'foo') |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 self.assertEqual( |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
21 '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33', h.hexdigest() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 ) |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 h.update(b'bar') |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 self.assertEqual( |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 '8843d7f92416211de9ebb963ff4ce28125932878', h.hexdigest() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 ) |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 def test_copy_hasher(self): |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
29 h = self.hasher() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 h.update(b'foo') |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
31 h2 = h.copy() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 h.update(b'baz') |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 h2.update(b'bar') |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 self.assertEqual( |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 '21eb6533733a5e4763acacd1d45a60c2e0e404e1', h.hexdigest() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 ) |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 self.assertEqual( |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 '8843d7f92416211de9ebb963ff4ce28125932878', h2.hexdigest() |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 ) |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 def test_init_hasher(self): |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
42 h = self.hasher(b'initial string') |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 self.assertEqual( |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 b'\xc9y|n\x1f3S\xa4:\xbaJ\xca,\xc1\x1a\x9e\xb8\xd8\xdd\x86', |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 h.digest(), |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
46 ) |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
47 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
48 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
49 class hashlibtests(unittest.TestCase, hashertestsbase): |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
50 hasher = hashlib.sha1 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
51 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
52 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
53 if sha1dc: |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
54 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
55 class sha1dctests(unittest.TestCase, hashertestsbase): |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
56 hasher = sha1dc.sha1 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
57 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
58 |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
59 if __name__ == '__main__': |
bde1cd4c99d9
sha1dc: initial implementation of Python extension
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
60 silenttestrunner.main(__name__) |