def _try_url_and_hash_it(url: str, hash_type: str): logger.debug("downloading url: %s", url) try: new_hash = hash_url(url, timeout=120, hash_type=hash_type) if new_hash is None: logger.debug("url does not exist or hashing took too long: %s", url) return None logger.debug("hash: %s", new_hash) return new_hash except Exception as e: logger.debug("hashing url failed: %s", repr(e)) return None
def test_hashing_smoke(): url = "https://github.com/LSSTDESC/CLMM/archive/0.1.0.tar.gz" hsh = hash_url(url) assert hsh == "902cd1b15783a770a23b0950287f42e798f3b8aadb5bbf07b864ca37499a29e9"
def test_hashing_badtype(): url = "https://github.com/LSSTDESC/CLMM/archive/0.1.0.tar.gz" with pytest.raises(AttributeError): hash_url(url, timeout=100, hash_type='blah')
def test_hashing_timeout_notexist(): url = "http://gmsh.info/src/gmsh-4.5.3-source.t" hsh = hash_url(url, timeout=1) assert hsh is None
def test_hashing_timeout(): url = "https://github.com/LSSTDESC/CLMM/archive/0.1.0.tar.gz" hsh = hash_url(url, timeout=0) assert hsh is None
def get_sha256(url: str) -> Optional[str]: try: return hash_url(url, timeout=120, hash_type="sha256") except Exception as e: logger.debug("url hashing exception: %s", repr(e)) return None
def get_sha256(url: str) -> Optional[str]: try: return hash_url(url, timeout=120, hash_type="sha256") except Exception: return None