Пример #1
0
 def test_get_testdata_file_external_hash_match(self):
     """Test that external source is used when hash is OK."""
     fname = "693_UNCI.dcm"
     p = self.dpath / fname
     ext_hash = calculate_file_hash(p)
     ref_hash = get_cached_filehash(p.name)
     assert ext_hash == ref_hash
     fpath = self.as_posix(get_testdata_file(fname))
     assert "data_store/data" in fpath
Пример #2
0
 def test_get_testdata_files_hash_match(self):
     """Test that the external source is not used when hash is not OK."""
     p = self.dpath / "693_UNCI.dcm"
     ext_hash = calculate_file_hash(p)
     ref_hash = get_cached_filehash(p.name)
     assert ext_hash == ref_hash
     fpaths = get_testdata_files("693_UNCI*")
     fpaths = [self.as_posix(p) for p in fpaths]
     assert 2 == len(fpaths)
     assert "data_store/data" in fpaths[0]
     assert ".pydicom/data" in fpaths[1]
Пример #3
0
    def test_get_testdata_file_external_hash_mismatch(self):
        """Test that the external source is not used when hash is not OK."""
        p = self.dpath / "693_UNCI.dcm"
        with open(p, 'wb') as f:
            f.write(b"\x00\x01")

        ext_hash = calculate_file_hash(p)
        ref_hash = get_cached_filehash(p.name)
        assert ext_hash != ref_hash
        fpath = self.as_posix(get_testdata_file(p.name))
        assert ".pydicom/data" in fpath
    def test_get_testdata_file_external_ignore_hash(self):
        """Test that non-pydicom-data external source ignores hash check."""
        EXTERNAL_DATA_SOURCES['mylib'] = EXTERNAL_DATA_SOURCES['pydicom-data']
        p = self.dpath / "693_UNCI.dcm"
        with open(p, 'wb') as f:
            f.write(b"\x00\x01")

        ext_hash = calculate_file_hash(p)
        ref_hash = get_cached_filehash(p.name)
        assert ext_hash != ref_hash
        fpath = self.as_posix(get_testdata_file(p.name))
        assert "data_store/data" in fpath
Пример #5
0
    def test_get_testdata_files_external_ignore_hash(self):
        """Test that non-pydicom-data external source ignores hash check."""
        external_data_sources()['mylib'] = external_data_sources(
        )['pydicom-data']
        p = self.dpath / "693_UNCI.dcm"
        with open(p, 'wb') as f:
            f.write(b"\x00\x01")

        ext_hash = calculate_file_hash(p)
        ref_hash = get_cached_filehash(p.name)
        assert ext_hash != ref_hash
        fpaths = get_testdata_files("693_UNCI*")
        fpaths = [self.as_posix(p) for p in fpaths]
        assert 2 == len(fpaths)
        assert "data_store/data" in fpaths[0]
        assert ".pydicom/data" in fpaths[1]
Пример #6
0
def _check_data_hash(fpath: str) -> bool:
    """Return ``True`` if the SHA256 checksum of the file at ``fpath`` is OK.

    Parameters
    ----------
    fpath : str
        The absolute path to the file to perform the checksum for.

    Returns
    -------
    bool
        ``True`` if the checksum matches those in ``hashes.json``, ``False``
        otherwise.

    Raises
    ------
    pydicom.data.download.NoHashFound
        If the file is missing from ``hashes.json``.
    """
    p = Path(fpath)
    ext_hash = calculate_file_hash(p)
    ref_hash = get_cached_filehash(p.name)

    return ext_hash == ref_hash