Skip to content

Commit

Permalink
Merge pull request #212 from r-transit/dev/prepare-release
Browse files Browse the repository at this point in the history
Fix tests, update contributors, prepare release
  • Loading branch information
polettif authored Dec 7, 2023
2 parents 1d6b540 + 048dd92 commit 5341a06
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 67 deletions.
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ Authors@R: c(
person("Alexandra", "Kapp", role = c("ctb")),
person("Kearey", "Smith", role = c("ctb")),
person("Dave", "Vautin", role = c("ctb")),
person("Kyle", "Walker", role = c("ctb"))
person("Kyle", "Walker", role = c("ctb")),
person("Davis", "Vaughan", role = c("ctb")),
person("Ryan", "Rymarczyk", role = c("ctb")),
person("Kirill", "Müller", role = c("ctb"))
)
Description: Read General Transit Feed Specification (GTFS) zipfiles into a list of R dataframes. Perform validation of the data structure against the specification. Analyze the headways and frequencies at routes and stops. Create maps and perform spatial analysis on the routes and stops. Please see the GTFS documentation here for more detail: <https://gtfs.org/>.
License: GPL
Expand Down
2 changes: 1 addition & 1 deletion R/spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ gtfs_as_sf <- function(gtfs_obj, skip_shapes = FALSE, crs = NULL, quiet = TRUE)
#' lon/lat coordinates
#' @return an sf dataframe for gtfs routes with a point column
#'
#' @seealso code{\link{gtfs_as_sf}}
#' @seealso \code{\link{gtfs_as_sf}}
#' @export
#' @examples
#' data(gtfs_duke)
Expand Down
2 changes: 1 addition & 1 deletion man/stops_as_sf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
data.table::setDTthreads(2)
library(testthat)
library(tidytransit)

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-as_tidygtfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test_that("as_tidygtfs w/ gtfstools", {
expect_equal(dt_gtfs.tidygtfs[[table_name]], tidygtfs[[table_name]])
}

expect_is(dt_gtfs.tidygtfs, "tidygtfs")
expect_s3_class(dt_gtfs.tidygtfs, "tidygtfs")
})

test_that("as_tidygtfs w/ list", {
Expand All @@ -28,7 +28,7 @@ test_that("as_tidygtfs w/ list", {
gtfs_list.tidygtfs = as_tidygtfs(gtfs_list)

expect_equal(gtfs_list.tidygtfs, tidygtfs)
expect_is(gtfs_list.tidygtfs, "tidygtfs")
expect_s3_class(gtfs_list.tidygtfs, "tidygtfs")
})

test_that("as_tidygtfs w/ gtfs", {
Expand All @@ -38,7 +38,7 @@ test_that("as_tidygtfs w/ gtfs", {
gtfs.tidygtfs = as_tidygtfs(gtfs)

expect_equal(gtfs.tidygtfs, tidygtfs)
expect_is(gtfs.tidygtfs, "tidygtfs")
expect_s3_class(gtfs.tidygtfs, "tidygtfs")
})

test_that("as_tidygtfs w/ tidygtfs", {
Expand All @@ -49,5 +49,5 @@ test_that("as_tidygtfs w/ tidygtfs", {
x2 = as_tidygtfs(x1)

expect_true(all(x2$.$dates_services$service_id == "WEEK"))
expect_is(x2, "tidygtfs")
expect_s3_class(x2, "tidygtfs")
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("Frequencies are calculated correctly")

# TODO rewrite with synthesized sample data
test_that("Stop frequencies (headways) for included data are as expected", {
expect_equal(nrow(get_stop_frequency(gtfs_duke, by_route = FALSE)), 47)
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-raptor.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("raptor travel time routing")

local_gtfs_path <- system.file("extdata", "routing.zip", package = "tidytransit")
gtfs_routing <- read_gtfs(local_gtfs_path)
test_from_stop_ids <- c("stop1a", "stop1b")
Expand Down
56 changes: 34 additions & 22 deletions tests/testthat/test-read-gtfs.R
Original file line number Diff line number Diff line change
@@ -1,46 +1,58 @@
context("Import and Validation")
g_routing_path <- system.file("extdata", "routing.zip",
package = "tidytransit")

gtfs_example_url <-
"https://github.com/r-transit/tidytransit/raw/master/inst/extdata/sample-feed-fixed.zip"
local_gtfs_path <- system.file("extdata",
"google_transit_nyc_subway.zip",
package = "tidytransit")
test_that("read_gtfs() imports a local file to a list of
dataframes and doesnt delete the source file", {

test_that("read_gtfs() imports a local file to a
list of dataframes and doesnt
delete the source file", {
gtfs_obj <- read_gtfs(local_gtfs_path)
gtfs_obj = read_gtfs(g_routing_path)

expect_is(gtfs_obj, "gtfs")
file.exists(local_gtfs_path)
expect_type(gtfs_obj, "list")
expect_s3_class(gtfs_obj, "tidygtfs")
expect_s3_class(gtfs_obj, "gtfs")
expect_true(file.exists(g_routing_path))
})

test_that("reading a real feed", {
skip_on_cran()
g_nyc_path = system.file("extdata", "google_transit_nyc_subway.zip",
package = "tidytransit")
gtfs_obj = read_gtfs(g_nyc_path)

expect_type(gtfs_obj, "list")
expect_s3_class(gtfs_obj, "tidygtfs")
expect_s3_class(gtfs_obj, "gtfs")
})

test_that("loud read_gtfs", {
expect_is(
read_gtfs(local_gtfs_path, quiet = FALSE),
expect_s3_class(
read_gtfs(g_routing_path, quiet = FALSE),
"tidygtfs")
})

test_that("gtfsio arguments", {
expect_is(
read_gtfs(local_gtfs_path, encoding = "UTF-8"),
skip_on_cran()
expect_s3_class(
read_gtfs(g_routing_path, encoding = "UTF-8"),
"tidygtfs"
)
})


test_that("tidygtfs class inheritance list", {
expect_equal(
class(read_gtfs(local_gtfs_path)),
class(read_gtfs(g_routing_path)),
c("tidygtfs", "gtfs", "list")
)
})

test_that("the read_gtfs function works with urls", {
skip_on_cran()
gtfs_example_url <-
"https://github.com/r-transit/tidytransit/raw/master/inst/extdata/sample-feed-fixed.zip"

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

test_that("the read_gtfs function fails gracefully on bad urls", {
Expand All @@ -60,7 +72,7 @@ test_that("Files with BOM can be read", {
"sample-feed-bom.zip",
package = "tidytransit")
g <- read_gtfs(bom_path)
expect_is(g, "tidygtfs")
expect_s3_class(g, "tidygtfs")
})

test_that("Feed with additional data can be read", {
Expand Down Expand Up @@ -121,6 +133,6 @@ test_that("non-unique stop_ids", {

g2 = suppressWarnings(read_gtfs(tmppath))

expect_is(g2, "gtfs")
expect_s3_class(g2, "gtfs")
expect_false(inherits(g2, "tidygtfs"))
})
2 changes: 0 additions & 2 deletions tests/testthat/test-service.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("Servicepattern")

gpath <- system.file("extdata", "routing.zip", package = "tidytransit")

test_that("set_servicepattern", {
Expand Down
23 changes: 13 additions & 10 deletions tests/testthat/test-spatial.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
context("Converting to sf objects")
library(sf)

test_that("convert gtfs stops and shapes to sf data frames", {
expect_is(stops_as_sf(gtfs_duke$stops), "sf")
expect_s3_class(stops_as_sf(gtfs_duke$stops), "sf")
shapes_sf = shapes_as_sf(gtfs_duke$shapes)
expect_is(shapes_sf, "sf")
expect_s3_class(shapes_sf, "sf")
expect_equal(nrow(shapes_sf), length(unique(gtfs_duke$shapes$shape_id)))
duke_sf <- gtfs_as_sf(gtfs_duke)
expect_is(duke_sf$shapes, "sf")
expect_is(duke_sf$stops, "sf")
expect_s3_class(duke_sf$shapes, "sf")
expect_s3_class(duke_sf$stops, "sf")
duke_sf2 = gtfs_as_sf(duke_sf)
expect_equal(duke_sf2, duke_sf)
})
Expand Down Expand Up @@ -126,7 +125,7 @@ test_that("geodist", {
xlon = c(8.4590, 8.4714)
xlat = c(47.1812, 47.1824)
dist1 = geodist_list(xlon, xlat)
expect_is(dist1, "list")
expect_type(dist1, "list")
expect_equal(length(dist1), 1)

x_sf = sf::st_as_sf(data.frame(lon = xlon, lat = xlat), coords = c("lon", "lat"), crs = 4326)
Expand All @@ -139,13 +138,14 @@ test_that("geodist", {
test_that("stop_group_distances", {
x = stop_group_distances(stopdist_df)
expect_equal(colnames(x), c("stop_name", "distances", "n_stop_ids", "dist_mean", "dist_median", "dist_max"))
expect_is(x$distances[1][[1]], "matrix")
expect_true(is.matrix(x$distances[1][[1]]))
expect_equal(x$n_stop_ids, c(3,2))
})

g_nyc = read_gtfs(system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit"))

test_that("stop_group_distances real feed", {
skip_on_cran()
g_nyc = read_gtfs(system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit"))

x1 = stop_group_distances(g_nyc$stops)

g_nyc_sf = gtfs_as_sf(g_nyc)
Expand All @@ -163,6 +163,9 @@ test_that("stop_group_distances real feed", {
})

test_that("stops cluster", {
skip_on_cran()

g_nyc = read_gtfs(system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit"))
g_nyc2 <- filter_feed_by_area(g_nyc, c(-74.0144, 40.7402, -73.9581, 40.7696))

x1 = cluster_stops(g_nyc2$stops)
Expand All @@ -179,5 +182,5 @@ test_that("stops cluster", {

# piping gtfs_obj
g_nyc2 = cluster_stops(g_nyc2)
expect_is(g_nyc2, "tidygtfs")
expect_s3_class(g_nyc2, "tidygtfs")
})
12 changes: 5 additions & 7 deletions tests/testthat/test-time.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("Time manipulation")

create_empty_gtfs_obj <- function() {
g <- list(agency = data.frame())
gtfsio::new_gtfs(g)
Expand All @@ -17,14 +15,14 @@ test_that("convert_times_to_hms() works with valid data", {

gtest <- convert_times_to_hms(gtest)

expect_is(gtest$stop_times$arrival_time, "hms")
expect_is(gtest$stop_times$departure_time, "hms")
expect_s3_class(gtest$stop_times$arrival_time, "hms")
expect_s3_class(gtest$stop_times$departure_time, "hms")
expect_false(is.na(gtest$stop_times$arrival_time[3]))
expect_equal(gtest$stop_times$departure_time[3],
hms::hms(26 * 3600 + 10 * 60 + 30))

expect_is(gtest$frequencies$start_time, "hms")
expect_is(gtest$frequencies$end_time, "hms")
expect_s3_class(gtest$frequencies$start_time, "hms")
expect_s3_class(gtest$frequencies$end_time, "hms")
})

test_that("set_dates_services() uses the right dates", {
Expand Down Expand Up @@ -110,7 +108,7 @@ test_that("set_dates_services() works with additions and exceptions", {
test_that("parse dates", {
x = "20180429"
y = parse_gtfsio_date(x)
expect_is(y, "Date")
expect_s3_class(y, "Date")
z = date_as_gtfsio_char(y)
expect_equal(x, z)
})
Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/test-travel_times.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("travel_times routing")

local_gtfs_path <- system.file("extdata", "routing.zip", package = "tidytransit")
gtfs_routing <- read_gtfs(local_gtfs_path)
test_from_stop_ids <- c("stop1a", "stop1b")
Expand Down Expand Up @@ -159,6 +157,7 @@ test_that("feed without transfers", {
})

test_that("nyc feed", {
skip_on_cran()
nyc_path <- system.file("extdata", "google_transit_nyc_subway.zip", package = "tidytransit")
nyc <- read_gtfs(nyc_path)

Expand All @@ -175,5 +174,5 @@ test_that("nyc feed", {

tts <- travel_times(nyc_st, "34 St - Herald Sq (D17)", return_coords = TRUE, stop_dist_check = FALSE)

expect_is(tts, "data.frame")
expect_s3_class(tts, "data.frame")
})
13 changes: 5 additions & 8 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("Utils")

test_that("summary.tidygtfs", {
gpath <- system.file("extdata", "routing.zip", package = "tidytransit")
g1 = read_gtfs(gpath)
Expand Down Expand Up @@ -81,8 +79,8 @@ test_that("filter_feed with shapes", {
})

test_that("filter_feed_by_date", {
g0 = read_gtfs(system.file("extdata",
"google_transit_nyc_subway.zip",
skip_on_cran()
g0 = read_gtfs(system.file("extdata", "google_transit_nyc_subway.zip",
package = "tidytransit"))
g1 = filter_feed_by_date(g0, "2018-06-28")
g2 = filter_feed_by_date(g0, "2018-10-30")
Expand All @@ -91,12 +89,11 @@ test_that("filter_feed_by_date", {
expect_lt(nrow(g1$stops), nrow(g0$stops))
expect_lt(nrow(g2$stops), nrow(g0$stops))

expect_is(g1$stop_times, "tbl_df")
expect_is(g2$stop_times, "tbl_df")
expect_s3_class(g1$stop_times, "tbl_df")
expect_s3_class(g2$stop_times, "tbl_df")
})


test_that("gtfs_meta", { # empty test
test_that("gtfs_meta", {
expect_equal(gtfs_meta, get_gtfs_meta())
})

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ test_that("warning for duplicated primary key", {

# within as_tidygtfs
g2 = expect_warning(as_tidygtfs(g1), "Duplicated ids found in: routes, stops")
expect_is(g2, "list")
expect_type(g2, "list")

g3 = g2
g3$stops$stop_id[1] <- "stop1"
g3$routes$route_id[1] <- "lineA"

g4 = as_tidygtfs(g3)
expect_is(g4, "tidygtfs")
expect_s3_class(g4, "tidygtfs")
})

test_that("validate non gtfs object", {
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-write-gtfs.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("Export")

test_that("write_gtfs creates the same feed as read by read_gtfs", {
skip_on_cran()
path1 <- system.file("extdata", "sample-feed-fixed.zip", package = "tidytransit")
Expand Down

0 comments on commit 5341a06

Please sign in to comment.