Skip to content

Commit

Permalink
skip read_package remote tests if offline
Browse files Browse the repository at this point in the history
See #115
  • Loading branch information
damianooldoni committed Nov 9, 2022
1 parent b6d3308 commit ca8af06
Showing 1 changed file with 56 additions and 42 deletions.
98 changes: 56 additions & 42 deletions tests/testthat/test-read_package.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
test_that("read_package() returns a valid Data Package, whether reading path or
url", {
# Load example package (locally and remotely) and a valid minimal one
p_path <- system.file("extdata", "datapackage.json", package = "frictionless")
p_url <- file.path("https://raw.githubusercontent.com/frictionlessdata/",
"frictionless-r/main/inst/extdata/datapackage.json")
minimal_path <- test_path("data/valid_minimal.json")
p_local <- suppressMessages(read_package(p_path))
p_remote <- suppressMessages(read_package(p_url))
p_minimal <- suppressMessages(read_package(minimal_path))

# Returns a list with required properties
expect_true(check_package(p_local))
expect_true(check_package(p_remote))
expect_true(check_package(p_minimal))

# Package has correct resources
resource_names <- c("deployments", "observations", "media")
expect_identical(resources(p_local), resource_names)
expect_identical(resources(p_remote), resource_names)
expect_identical(resources(p_minimal), resource_names)

# Package has correct "directory", containing root dir of datapackage.json
expect_identical(p_local$directory, gsub("/datapackage.json", "", p_path))
expect_identical(p_remote$directory, gsub("/datapackage.json", "", p_url))
expect_identical(p_minimal$directory, "data")
})
test_that("read_package() returns a valid Data Package reading path", {
# Load example package locally and a valid minimal one
p_path <- system.file("extdata", "datapackage.json", package = "frictionless")
minimal_path <- test_path("data/valid_minimal.json")
p_local <- suppressMessages(read_package(p_path))
p_minimal <- suppressMessages(read_package(minimal_path))

# Returns a list with required properties
expect_true(check_package(p_local))
expect_true(check_package(p_minimal))

# Package has correct resources
resource_names <- c("deployments", "observations", "media")
expect_identical(resources(p_local), resource_names)
expect_identical(resources(p_minimal), resource_names)

# Package has correct "directory", containing root dir of datapackage.json
expect_identical(p_local$directory, gsub("/datapackage.json", "", p_path))
expect_identical(p_minimal$directory, "data")
})

test_that("read_package() returns a valid Data Package reading url", {
testthat::skip_if_offline()
# Load example package remotely
p_url <- file.path("https://raw.githubusercontent.com/frictionlessdata/",
"frictionless-r/main/inst/extdata/datapackage.json")
p_remote <- suppressMessages(read_package(p_url))

# Returns a list with required properties
expect_true(check_package(p_remote))

# Package has correct resources
resource_names <- c("deployments", "observations", "media")
expect_identical(resources(p_remote), resource_names)

# Package has correct "directory", containing root dir of datapackage.json
expect_identical(p_remote$directory, gsub("/datapackage.json", "", p_url))
})

test_that("read_package() shows message about usage norms", {
# Load example package and a minimal valid one a URL in "id"
Expand Down Expand Up @@ -62,17 +73,12 @@ test_that("read_package() returns error on missing file and properties", {
fixed = TRUE
)

# No file
# No file locally
expect_error(
read_package("nofile.json"),
"Can't find file at `nofile.json`",
fixed = TRUE
)
expect_error(
read_package("http://example.com/nofile.json"),
"Can't find file at `http://example.com/nofile.json`.",
fixed = TRUE
)

# Not a json file
expect_error(
Expand Down Expand Up @@ -111,19 +117,27 @@ test_that("read_package() returns error on missing file and properties", {
),
fixed = TRUE
)

# No file remotely
testthat::skip_if_offline()
expect_error(
read_package("http://example.com/nofile.json"),
"Can't find file at `http://example.com/nofile.json`.",
fixed = TRUE
)
})

test_that("read_package() allows descriptor at absolute or relative parent
path", {
relative_path <- "../testthat/data/valid_minimal.json"
expect_true(
check_package(suppressMessages(read_package(relative_path)))
)
absolute_path <- normalizePath("data/valid_minimal.json")
expect_true(
check_package(suppressMessages(read_package(absolute_path)))
)
})
relative_path <- "../testthat/data/valid_minimal.json"
expect_true(
check_package(suppressMessages(read_package(relative_path)))
)
absolute_path <- normalizePath("data/valid_minimal.json")
expect_true(
check_package(suppressMessages(read_package(absolute_path)))
)
})

test_that("read_package() allows YAML descriptor", {
expect_true(
Expand Down

0 comments on commit ca8af06

Please sign in to comment.