Skip to content

Commit

Permalink
test: switching from testthat to tinytest. Closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
atsyplenkov committed Jan 9, 2025
1 parent b0c8459 commit 4c83324
Show file tree
Hide file tree
Showing 38 changed files with 622 additions and 1,688 deletions.
13 changes: 6 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ Language: en-US
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Imports:
cli,
checkmate,
graphics,
grDevices,
reticulate,
S7 (>= 0.2.0),
stats,
cli
graphics,
grDevices,
stats
Suggests:
terra (>= 1.7),
testthat (>= 3.0.0)
Config/testthat/edition: 3
tinytest,
terra
SystemRequirements: Python (>= 3.8.0), numpy, whitebox-workflows (>= v1.3.3)
Config/Needs/website: rmarkdown, waldo, bench, whitebox, ggplot2, tidyr
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export(as_matrix)
export(as_rast)
export(as_vector)
export(as_wbw_raster)
export(expect_snapshot)
export(num_cells)
export(print_geotiff_tags)
export(stdev)
Expand Down
10 changes: 1 addition & 9 deletions R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,4 @@ check_input_file <-
}
}

#' Skip tests if we don't have the 'wbw' module
#' @rdname checks
#' @keywords internal
skip_if_no_wbw <- function() {
have_wbw <- reticulate::py_module_available("whitebox_workflows")
if (!have_wbw) {
testthat::skip("WbW is not available for testing")
}
}

26 changes: 26 additions & 0 deletions R/utils_documentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,29 @@ rd_example <-
sep = "\n"
)
}

#' Tinytest Snapshot
#' https://github.com/etiennebacher/astgrepr/
#' blob/ea91137bdb10d22c7a988a8cb1b0bc896935fb0d/R/tinytest.R
#'
#' @keywords internal
#' @export
expect_snapshot <- function(label, current) {
snapshot_file <- file.path("_snapshots", paste0(label, ".txt"))
current2 <- paste(utils::capture.output(print(current)), collapse = "\n")

if (!dir.exists(dirname(snapshot_file))) {
dir.create(dirname(snapshot_file), showWarnings = FALSE, recursive = TRUE)
}
if (!file.exists(snapshot_file)) {
cat(current2, file = snapshot_file, sep = "\n")
message("Creating file ", snapshot_file)
return(invisible())
}
target <- paste(readLines(snapshot_file, warn = FALSE), collapse = "\n")
tinytest::tinytest(
result = identical(current2, target),
call = sys.call(sys.parent(1)),
diff = paste0("Check content of ", snapshot_file)
)
}
5 changes: 0 additions & 5 deletions man/checks.Rd

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

16 changes: 16 additions & 0 deletions man/expect_snapshot.Rd

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

13 changes: 0 additions & 13 deletions tests/test-setup.R

This file was deleted.

11 changes: 11 additions & 0 deletions tests/test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Run package tests
if (requireNamespace("tinytest", quietly = TRUE)) {
# Initialize session
have_wbw <- reticulate::py_module_available("whitebox_workflows")
have_numpy <- reticulate::py_module_available("numpy")
if (!have_wbw & !have_numpy) {
wbw_install(system = TRUE)
}

tinytest::test_package("wbw", pattern = "^test_.*\\.[rR]$")
}
19 changes: 0 additions & 19 deletions tests/testthat.R

This file was deleted.

11 changes: 0 additions & 11 deletions tests/testthat/_snaps/crs.md

This file was deleted.

144 changes: 0 additions & 144 deletions tests/testthat/_snaps/filter.md

This file was deleted.

Loading

0 comments on commit 4c83324

Please sign in to comment.