Skip to content

Commit

Permalink
init tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherkenny committed Feb 6, 2024
1 parent 5c2000e commit 74478ca
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ Imports:
tibble,
tidyr
URL: http://christophertkenny.com/planscorer/
Suggests:
httptest2,
spelling,
testthat (>= 3.0.0)
Config/testthat/edition: 3
Language: en-US
7 changes: 7 additions & 0 deletions inst/httptest2/redact.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function(resp) {
resp |>
# shorten url
httptest2::gsub_response(pattern = 'api.planscore.org/', '') |>
# redact key
httptest2::gsub_response(pattern = planscorer::ps_get_key(), '')
}
3 changes: 3 additions & 0 deletions tests/spelling.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if(requireNamespace('spelling', quietly = TRUE))
spelling::spell_check_test(vignettes = TRUE, error = FALSE,
skip_on_cran = TRUE)
12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(planscorer)

test_check("planscorer")
1 change: 1 addition & 0 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
library(httptest2)
10 changes: 10 additions & 0 deletions tests/testthat/t/mdlvrs/model_versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
[
"2022F",
"New: rerun the 2020 election with more accurate updated data (updated May 2022)"
],
[
"2021B",
"Original: rerun an average election from the past 10 years with best available data from before Census release"
]
]
5 changes: 5 additions & 0 deletions tests/testthat/test-model_versions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
with_mock_dir("t/mdlvrs", {
test_that("`ps_model_versions()` works", {
expect_s3_class(ps_model_versions(), "data.frame")
})
})

0 comments on commit 74478ca

Please sign in to comment.