diff --git a/tests/testthat/examples/wals_1A_cldf.zip b/tests/testthat/examples/wals_1A_cldf.zip new file mode 100644 index 0000000..93be788 Binary files /dev/null and b/tests/testthat/examples/wals_1A_cldf.zip differ diff --git a/tests/testthat/test_resolve_path.R b/tests/testthat/test_resolve_path.R index 47791c5..239577c 100644 --- a/tests/testthat/test_resolve_path.R +++ b/tests/testthat/test_resolve_path.R @@ -56,71 +56,12 @@ test_that("resolve_path", { test_that("resolve_path handles archives (.zip)", { expected <- csvwr::read_metadata('examples/wals_1A_cldf/StructureDataset-metadata.json') - # create a new zipfile - cachedir <- tempdir(check=TRUE) - zipfile <- file.path(cachedir, 'wals_1A_cldf.zip') - archive::archive_write_dir(zipfile, 'examples/wals_1A_cldf') - - obtained <- resolve_path(zipfile, cachedir) - expect_equal(obtained$metadata, expected) - - # check a table at random - expect_equal( - cldf(zipfile)$tables$ValueTable, - cldf('examples/wals_1A_cldf/StructureDataset-metadata.json')$tables$ValueTable - ) -}) - - -test_that("resolve_path is remote file", { - expected <- csvwr::read_metadata('examples/wals_1A_cldf/StructureDataset-metadata.json') - - # create a new zipfile - cachedir <- tempdir(check=TRUE) - zipfile <- file.path(cachedir, 'wals_1A_cldf.zip') - archive::archive_write_dir(zipfile, 'examples/wals_1A_cldf') - - mockthat::with_mock( - # mock out download to copy file and patch is_url to return TRUE - `download` = function(url, cache_dir) zipfile, - `is_url` = function(...) TRUE, - p <- resolve_path(zipfile, cachedir) - ) - - obtained <- resolve_path(zipfile, cachedir) - expect_equal(obtained$metadata, expected) - - # check a table at random - expect_equal( - cldf(zipfile)$tables$ValueTable, - cldf('examples/wals_1A_cldf/StructureDataset-metadata.json')$tables$ValueTable - ) -}) - - -test_that("resolve_path is github", { - # we mock remotes::remote_download to just return a path to a tar.gz file, - # so we don't test the downloading (which uses the `remotes` library anyway). - expected <- csvwr::read_metadata('examples/wals_1A_cldf/StructureDataset-metadata.json') - - # create a new zipfile - cachedir <- tempdir(check=TRUE) - - zipfile <- file.path(cachedir, 'wals_1A_cldf.tar.gz') - archive::archive_write_dir(zipfile, 'examples/wals_1A_cldf') - mockthat::with_mock( - # mock out download to copy file and patch is_github to return TRUE - `remotes::remote_download` = function(x) zipfile, - `is_github` = function(...) TRUE, - p <- resolve_path(zipfile, cachedir) - ) - - obtained <- resolve_path(zipfile, cachedir) + obtained <- resolve_path("examples/wals_1A_cldf.zip") expect_equal(obtained$metadata, expected) # check a table at random expect_equal( - cldf(zipfile)$tables$ValueTable, + cldf("examples/wals_1A_cldf.zip")$tables$ValueTable, cldf('examples/wals_1A_cldf/StructureDataset-metadata.json')$tables$ValueTable ) })