MCPcopy
hub / github.com/pytest-dev/pytest / computehash

Method computehash

src/_pytest/_py/path.py:618–638  ·  view source on GitHub ↗

Return hexdigest of hashvalue for this file.

(self, hashtype="md5", chunksize=524288)

Source from the content-addressed store, hash-verified

616 error.checked_call(os.remove, self.strpath)
617
618 def computehash(self, hashtype="md5", chunksize=524288):
619 """Return hexdigest of hashvalue for this file."""
620 try:
621 try:
622 import hashlib as mod
623 except ImportError:
624 if hashtype == "sha1":
625 hashtype = "sha"
626 mod = __import__(hashtype)
627 hash = getattr(mod, hashtype)()
628 except (AttributeError, ImportError):
629 raise ValueError(f"Don't know how to compute {hashtype!r} hash")
630 f = self.open("rb")
631 try:
632 while 1:
633 buf = f.read(chunksize)
634 if not buf:
635 return hash.hexdigest()
636 hash.update(buf)
637 finally:
638 f.close()
639
640 def new(self, **kw):
641 """Create a modified version of this path.

Callers 1

test_gethashMethod · 0.80

Calls 4

openMethod · 0.95
updateMethod · 0.80
readMethod · 0.45
closeMethod · 0.45

Tested by 1

test_gethashMethod · 0.64