Exemple #1
0
    def test_get_dataset(self):
        """Test the different functions to get lists of data files."""

        cached_data_test_files = str(get_data_dir())

        # Test base locations
        charbase = os.path.join(DATA_ROOT, 'charset_files')
        assert os.path.exists(charbase)

        testbase = os.path.join(DATA_ROOT, 'test_files')
        assert os.path.exists(testbase)

        # Test file get
        chardata = get_charset_files()
        assert 15 < len(chardata)

        # Test that top level file is included
        bases = [basename(x) for x in chardata]

        # Test that subdirectory files included
        testdata = get_testdata_files()
        bases = [basename(x) for x in testdata]
        assert '2693' in bases
        assert 70 < len(testdata)

        # The files should be from their respective bases
        for x in testdata:
            assert testbase in x or cached_data_test_files in x
        for x in chardata:
            assert charbase in x
def test_fetch_data_files():
    """Test fetch_data_files()."""
    # Remove a single file from the cache
    cache = get_data_dir()
    path = cache / "693_J2KR.dcm"
    if path.exists():
        path.unlink()

    assert not path.exists()
    fetch_data_files()
    assert path.exists()
Exemple #3
0
def fetch_data_files():
    """Download missing test files to the local cache."""
    cache = get_data_dir()
    paths = {cache / fname: fname for fname in list(get_url_map().keys())}

    error = []
    for p in paths:
        # Download missing files or files that don't match the hash
        try:
            data_path_with_download(p.name)
        except Exception:
            error.append(p.name)

    if error:
        raise RuntimeError(
            "An error occurred downloading the following files: "
            f"{', '.join(error)}")
    def test_get_dataset(self):
        """Test the different functions to get lists of data files."""
        # The cached files downloaded from the pydicom-data repo
        cached_data_test_files = str(get_data_dir())

        # If pydicom-data is available locally
        ext_path = None
        if 'pydicom-data' in external_data_sources():
            ext_path = os.fspath(
                external_data_sources()['pydicom-data'].data_path)

        # Test base locations
        charbase = os.path.join(DATA_ROOT, 'charset_files')
        assert os.path.exists(charbase)

        testbase = os.path.join(DATA_ROOT, 'test_files')
        assert os.path.exists(testbase)

        # Test file get
        chardata = get_charset_files()
        assert 15 < len(chardata)

        # Test that top level file is included
        bases = [basename(x) for x in chardata]

        # Test that subdirectory files included
        testdata = get_testdata_files()
        bases = [basename(x) for x in testdata]
        assert '2693' in bases
        assert 70 < len(testdata)

        # The files should be from their respective bases
        for x in testdata:
            # Don't check files from external sources other than pydicom-data
            if (testbase not in x and cached_data_test_files not in x
                    and (ext_path not in x if ext_path else True)):
                continue

            assert (testbase in x or cached_data_test_files in x
                    or (ext_path in x if ext_path else False))

        for x in chardata:
            assert charbase in x