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

Method computehash

src/_pytest/_py/path.py:618–638  ·  src/_pytest/_py/path.py::LocalPath.computehash

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=class="st">"md5", chunksize=524288):
619 class="st">""class="st">"Return hexdigest of hashvalue for this file."class="st">""
620 try:
621 try:
622 import hashlib as mod
623 except ImportError:
624 if hashtype == class="st">"sha1":
625 hashtype = class="st">"sha"
626 mod = __import__(hashtype)
627 hash = getattr(mod, hashtype)()
628 except (AttributeError, ImportError):
629 raise ValueError(fclass="st">"Don&class="cm">#x27;t know how to compute {hashtype!r} hash")
630 f = self.open(class="st">"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 class="st">"""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