Skip to content

Commit

Permalink
Merge pull request #194 from r-transit/dev/fix-cran
Browse files Browse the repository at this point in the history
Use expect_no_warning, remove httr dependency
  • Loading branch information
polettif authored Feb 1, 2023
2 parents 3203e95 + 13d102c commit 82a5065
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 42 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,22 @@ Imports:
gtfsio (>= 0.1.0),
dplyr,
data.table (>= 1.12.8),
httr,
rlang,
sf,
hms,
digest,
checkmate,
geodist
Suggests:
testthat,
testthat (>= 3.1.5),
knitr,
markdown,
rmarkdown,
ggplot2,
scales,
lubridate,
leaflet
RoxygenNote: 7.1.2
RoxygenNote: 7.2.2
URL: https://github.com/r-transit/tidytransit
BugReports: https://github.com/r-transit/tidytransit
Roxygen: list(markdown = TRUE)
Expand Down
50 changes: 11 additions & 39 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 Expand Up @@ -110,6 +82,6 @@ test_that("files parameter", {
fns = names(g1)[names(g1) != "." & names(g1) != "calendar_dates"]

for(f in fns) {
expect_warning(read_gtfs(path, files = f), regexp = NA) # no warning expected
expect_no_warning(read_gtfs(path, files = f)) # no warning expected
}
})

0 comments on commit 82a5065

Please sign in to comment.