Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tanho63 committed Jan 16, 2022
1 parent f501979 commit 0b5a1c2
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 22 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Imports:
nflreadr (>= 1.1.2),
purrr (>= 0.3.0),
rappdirs (>= 0.3.0),
recipes (>= 0.1.16),
rlang (>= 0.1.0),
stats,
stringr (>= 1.4.0),
Expand Down
5 changes: 3 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(print,ffep_download)
S3method(print,ffep_output)
S3method(print,ffopps_build)
S3method(print,ffopps_load)
export("%>%")
export(.get_rosters)
export(ep_build)
Expand All @@ -10,6 +10,7 @@ export(ep_load)
export(ep_predict)
export(ep_preprocess)
export(ep_summarize)
import(recipes)
import(xgboost)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
Expand Down
4 changes: 2 additions & 2 deletions R/ep_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ ep_build <- function(season = nflreadr:::most_recent_season(), version = "latest
ep_version = version,
timestamp = Sys.time()
),
class = "ffep_output"
class = "ffopps_build"
)
return(out)
}

#' @export
#' @noRd
print.ffep_output <- function(x, ...) {
print.ffopps_build <- function(x, ...) {
cli::cli_alert("<ffopportunity predictions>")
cli::cli_alert("Generated {x$timestamp} with model version {x$ep_version}")
utils::str(x, max.level = 2, give.attr = FALSE)
Expand Down
4 changes: 2 additions & 2 deletions R/ep_load.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ep_load <- function(season = nflreadr:::most_recent_season(),
rawToChar() %>%
as.POSIXct()

class(out) <- c("ffep_download","tbl_df", "tbl", "data.frame")
class(out) <- c("ffopps_load","tbl_df", "tbl", "data.frame")
attr(out, "ep_version") <- version
attr(out, "ep_timestamp") <- ts
attr(out, "ep_type") <- type
Expand All @@ -54,7 +54,7 @@ ep_load <- function(season = nflreadr:::most_recent_season(),

#' @export
#' @noRd
print.ffep_download <- function(x, ...) {
print.ffopps_load <- function(x, ...) {
cli::cli_alert("<ffopportunity predictions>")
cli::cli_alert("Generated {.val {attr(x,'ep_timestamp')}} with ep model version {.val {attr(x,'ep_version')}}")
NextMethod(print,x)
Expand Down
1 change: 1 addition & 0 deletions R/ep_predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#' @return a dataframe with the expected fields added
#'
#' @import xgboost
#' @import recipes
#'
#' @export
ep_predict <- function(preprocessed_pbp, version = c("latest", "v1.0.0")) {
Expand Down
6 changes: 3 additions & 3 deletions R/ep_preprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#' @examples
#' \donttest{
#' try({ # catch failures for CRAN purposes
#' preprocessed <- readRDS(system.file("pbp_download.rds",package = "ffopportunity"))
#' # this file is equivalent to nflreadr::load_pbp(2021) %>% head(100)
#' ep_preprocess(preprocessed)
#' pbp_download <- readRDS(system.file("pbp_download.rds",package = "ffopportunity"))
#' # this file is equivalent to nflreadr::load_pbp(2021) %>% head(1000)
#' ep_preprocess(pbp_download)
#' })
#' }
#'
Expand Down
2 changes: 1 addition & 1 deletion R/ep_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ep_cache_models <- function(version = c("latest","v1.0.0"), force = FALSE, ask =

cache_dir <- rappdirs::user_cache_dir(appname = "ffopportunity", appauthor = "ffverse")

if(!dir.exists(cache_dir)) dir.create(cache_dir)
if(!dir.exists(cache_dir)) dir.create(cache_dir, recursive = TRUE)

if(!force){
if(file.exists(file.path(cache_dir,version))) return(invisible(NULL))
Expand Down
Binary file modified inst/pbp_download.rds
Binary file not shown.
6 changes: 3 additions & 3 deletions man/ep_preprocess.Rd

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

22 changes: 22 additions & 0 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
suppressPackageStartupMessages({
library(testthat)
})

gha_online <- !is.null(curl::nslookup("github.com", error = FALSE))

skip <- !gha_online

if(gha_online){
tryCatch(
expr = {
ep_cache_models(version = "v1.0.0")
pbp_2020 <- nflreadr::load_pbp(2020)
},
warning = function(e) skip <<- TRUE,
error = function(e) skip <<- TRUE
)
}

skippy <- function() NULL
if (skip) skippy <- function() testthat::skip(message = "Unable to connect to GHA")

17 changes: 17 additions & 0 deletions tests/testthat/test-ep_build.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
test_that("ep_build and ep_load work", {
skippy()
ep_2020 <- ep_build(2020, version = "v1.0.0")
expect_s3_class(ep_2020,"ffopps_build")
expect_gte(nrow(ep_2020$ep_weekly), 5000)
expect_gte(nrow(ep_2020$ep_pbp_pass), 18000)
expect_gte(nrow(ep_2020$ep_pbp_rush), 13000)

ep_weekly <- ep_load(2020, type = "weekly",version = "v1.0.0")
ep_pbp_pass <- ep_load(2020, type = "pbp_pass",version = "v1.0.0")
ep_pbp_rush <- ep_load(2020, type = "pbp_rush",version = "v1.0.0")

expect_equal(nrow(ep_2020$ep_weekly), nrow(ep_weekly))
expect_equal(nrow(ep_2020$ep_pbp_pass), nrow(ep_pbp_pass))
expect_equal(nrow(ep_2020$ep_pbp_rush), nrow(ep_pbp_rush))

})
3 changes: 0 additions & 3 deletions tests/testthat/test-ep_calculate.R

This file was deleted.

3 changes: 0 additions & 3 deletions tests/testthat/test-ep_load.R

This file was deleted.

3 changes: 0 additions & 3 deletions tests/testthat/test-preprocess.R

This file was deleted.

0 comments on commit 0b5a1c2

Please sign in to comment.