Skip to content

Commit

Permalink
adding zip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonGreenhill committed Mar 24, 2024
1 parent bc9b714 commit fbd899e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 61 deletions.
Binary file added tests/testthat/examples/wals_1A_cldf.zip
Binary file not shown.
63 changes: 2 additions & 61 deletions tests/testthat/test_resolve_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
})

0 comments on commit fbd899e

Please sign in to comment.