Beispiel #1
0
def test_download_url_without_baseurl_raises_exception(tmp_path):
    # arrange
    dst_mets = join(tmp_path, 'mets.xml')
    copyfile(SRC_METS, dst_mets)
    ws1 = Resolver().workspace_from_url(dst_mets)
    the_file = _url_to_file(SAMPLE_FILE_URL)

    # act
    with pytest.raises(Exception) as exc:
        ws1.download_file(the_file)

    # assert exception message contents
    assert "Already tried prepending baseurl '%s'" % str(tmp_path) in str(
        exc.value)
def test_workspace_from_url0():

    # act
    workspace = Resolver().workspace_from_url(METS_HEROLD)
    input_files = workspace.mets.find_all_files(fileGrp='OCR-D-IMG')
    image_file = input_files[0]
    f = workspace.download_file(image_file)

    # assert
    assert '%s.tif' % f.ID == 'FILE_0001_IMAGE.tif'
    assert f.local_filename == 'OCR-D-IMG/FILE_0001_IMAGE.tif'
Beispiel #3
0
def test_download_url_with_baseurl(tmp_path):
    # arrange
    dst_mets = join(tmp_path, 'mets.xml')
    copyfile(SRC_METS, dst_mets)
    tif_dir = tmp_path / 'OCR-D-IMG'
    tif_dir.mkdir()
    dst_tif = join(tmp_path, SAMPLE_FILE_URL)
    copyfile(join(dirname(SRC_METS), SAMPLE_FILE_URL), dst_tif)
    ws1 = Resolver().workspace_from_url(dst_mets,
                                        src_baseurl=dirname(SRC_METS))
    the_file = _url_to_file(dst_tif)

    # act
    # TODO
    # semantics changed from .download_url to .download_file
    # and from context path 'DEPRECATED' to 'OCR-D-IMG'
    f = Path(ws1.download_file(the_file).local_filename)

    # assert
    assert str(f).endswith(join('OCR-D-IMG', '%s.tif' % SAMPLE_FILE_ID))
    assert Path(ws1.directory, f).exists()