Skip to content

Commit

Permalink
update tests to account for changed structure of source data
Browse files Browse the repository at this point in the history
  • Loading branch information
colindouglas committed Feb 20, 2024
1 parent 0226c41 commit dfc0ab3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions R/getRetrosheet.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ getRetrosheet <- function(type, year, team, schedSplit = NULL, stringsAsFactors
"game" = "/gamelogs/gl%d.zip",
"play" = "/events/%deve.zip",
"roster" = "/events/%deve.zip",
"schedule" = "/schedule/%dSKED.ZIP")
"schedule" = "/schedule/%dSKED.zip")

# If cache is NA, download to a temp location
if (is.na(cache)) {
Expand Down Expand Up @@ -107,7 +107,7 @@ getRetrosheet <- function(type, year, team, schedSplit = NULL, stringsAsFactors

if(type == "schedule") {
zcon <- unz(tmp, filename = fname)
out <- read.csv(zcon, header = FALSE, col.names = retrosheetFields$schedule,
out <- read.csv(zcon, header = TRUE, col.names = retrosheetFields$schedule,
stringsAsFactors = stringsAsFactors)
out <- out[!is.na(out$GameNo), ] # Filter out the last line, which is often parsed incorrectly
if(is.character(schedSplit)) {
Expand Down
7 changes: 4 additions & 3 deletions tests/testthat/test-getRetrosheet.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test_that("Caching works", {
expect_equal(play_1, play_2)

# Re-using cached data should give a message about using a local cache
expect_message(getRetrosheet("schedule", 1995, cache = "testdata"), "Using local cache: testdata/schedule/1995SKED.ZIP")
expect_message(getRetrosheet("schedule", 1995, cache = "testdata"), "Using local cache: testdata/schedule/1995SKED.zip")

})

Expand All @@ -50,8 +50,9 @@ test_that("Roster downloading works", {

roster <- getRetrosheet("roster", 1995, cache = "testdata")

# In 1995, there should be 28 regular teams plus All Star teams (NLS + ALS)
expect_equal(length(roster), 28 + 2)
# In 1995, there should be 28 regular teams
# The two All Star teams (NLS + ALS) are no longer included in these data
expect_equal(length(roster), 28)

# Toronto has 39 players on their roster
expect_equal(nrow(roster$TOR), 39)
Expand Down
7 changes: 4 additions & 3 deletions tests/testthat/test-get_retrosheet.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test_that("Caching works", {
expect_equal(play_1, play_2)

# Re-using cached data should give a message about using a local cache
expect_message(get_retrosheet("schedule", 1995, cache = "testdata"), "Using local cache: testdata/schedule/1995SKED.ZIP")
expect_message(get_retrosheet("schedule", 1995, cache = "testdata"), "Using local cache: testdata/schedule/1995SKED.zip")

})

Expand Down Expand Up @@ -62,8 +62,9 @@ test_that("Roster downloading works", {

roster <- get_retrosheet("roster", 1995, cache = "testdata")

# In 1995, there should be 28 regular teams plus All Star teams (NLS + ALS)
expect_equal(length(roster), 28 + 2)
# In 1995, there should be 28 regular teams
# The two All Star teams (NLS + ALS) are no longer included in these data
expect_equal(length(roster), 28)

# In 1995, 39 different players played for TOR
expect_equal(nrow(roster$TOR), 39)
Expand Down

0 comments on commit dfc0ab3

Please sign in to comment.