Skip to content

Commit

Permalink
remove httr dependency, don't check working internet in tests
Browse files Browse the repository at this point in the history
downloads are still skipped on CRAN, cleaned up read_gtfs tests
  • Loading branch information
polettif committed Feb 1, 2023
1 parent 08a5191 commit 13d102c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 39 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Imports:
gtfsio (>= 0.1.0),
dplyr,
data.table (>= 1.12.8),
httr,
rlang,
sf,
hms,
Expand Down
48 changes: 10 additions & 38 deletions tests/testthat/test-read-gtfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ local_gtfs_path <- system.file("extdata",
"google_transit_nyc_subway.zip",
package = "tidytransit")


working <- function() {
connecting <- function(gtfs_url) {
r <- tryCatch(httr::GET(gtfs_url, httr::timeout(5)),
error = function(e) NA)
if(!is.na(r[1])) r$status_code == 200 else FALSE
}
connecting(gtfs_example_url)
}

test_that("read_gtfs() imports a local file to a
list of dataframes and doesnt
delete the source file", {
Expand All @@ -31,41 +21,23 @@ test_that("loud read_gtfs", {
"gtfs")
})

test_that("import-bad paths throw good errors", {
test_that("the read_gtfs function works with urls", {
skip_on_cran()
not_a_url <- "#!:D"
expect_error(read_gtfs(path)) # invalid path
})

test_that("the read_gtfs function works", {
skip_on_cran()
if(!working()){
skip("no internet, skipping")
} else {
# non-specified path
x <- read_gtfs(gtfs_example_url, quiet=TRUE)
expect_is(x, "gtfs") # should return 'list' object
}

x <- read_gtfs(gtfs_example_url, quiet=TRUE)
expect_is(x, "gtfs") # should return 'list' object
})

test_that("the read_gtfs function fails gracefully on bad urls", {
skip_on_cran()
if(!working()){
skip("no internet, skipping")
} else {
not_zip <- "https://developers.google.com/transit/gtfs/examples/sample-feed.zippy"
bad_url <- "https://developers.google.com/transit/gtfs/examples/sample-feed-bad.zip"

# non-specified path
expect_error(read_gtfs(not_zip, quiet=TRUE))
}
not_zip <- "https://developers.google.com/transit/gtfs/examples/sample-feed.zippy"
bad_file <- "/Users/wrong.zip"
bad_url <- "https://developers.google.com/transit/gtfs/examples/sample-feed-bad.zip"

})

test_that("unknown local file throws meaningful error", {
read_gtfs(local_gtfs_path)
expect_error(read_gtfs("/Users/wrong.zip"))
expect_error(read_gtfs(not_zip, quiet=TRUE), "'path' must have '.zip' extension")
expect_error(read_gtfs(bad_file), "'path' points to non-existent file: '/Users/wrong.zip'")
expect_error(suppressWarnings(read_gtfs(bad_url)),
"cannot open URL 'https://developers.google.com/transit/gtfs/examples/sample-feed-bad.zip'")
})

test_that("Files with BOM can be read", {
Expand Down

0 comments on commit 13d102c

Please sign in to comment.