Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 14 additions & 30 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
# workflow_dispatch:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage.yaml
name: test-coverage

permissions: read-all

Expand All @@ -15,6 +15,8 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
_R_CHECK_CRAN_INCOMING_: false

steps:
- uses: actions/checkout@v4
Expand All @@ -25,38 +27,20 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
pak-version: devel
upgrade: 'TRUE'
cache-version: 2
extra-packages: |
any::covr
local::.
needs: coverage

- name: Test coverage
run: |
cov <- covr::package_coverage(
options(crayon.enabled = TRUE)
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
token = "${{secrets.CODECOV_TOKEN}}"
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
shell: Rscript {0}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ See our guide on [how to create a great issue](https://code-review.tidyverse.org

* We use [roxygen2](https://cran.r-project.org/package=roxygen2), with [Markdown syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/rd-formatting.html), for documentation.

* We use [testthat](https://cran.r-project.org/package=testthat) for unit tests.
* We use [tinytest](https://cran.r-project.org/package=tinytest) for unit tests.
Contributions with test cases included are easier to accept.

### Writing S7 documentation
Expand Down
15 changes: 7 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: wbw
Title: Whitebox Workflows for R
Version: 0.0.2
Version: 0.0.3
URL: https://wbw.anatolii.nz
BugReports: https://github.com/atsyplenkov/wbw/issues
Authors@R: c(person(given = "Anatoly", family = "Tsyplenkov", role = c("aut", "cre"), email = "atsyplenkov@fastmail.com", comment = c(ORCID = "0000-0003-4144-8402")))
Expand All @@ -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
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# wbw 0.0.2 (2024-01-09)

* Swithced from `{testthat}` to `{tinytest}` to
reduce dependencies

# wbw 0.0.2 (2024-01-07)

* Documentation updates:
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")
}
}

32 changes: 31 additions & 1 deletion R/utils_documentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#' @keywords internal
rd_wbw_link <-
function(fun_name) {
checkmate::assert_character(fun_name, min.chars = 1L)
paste0(
"@references For more information, see ",
"<https://www.whiteboxgeo.com/manual",
Expand All @@ -23,6 +24,7 @@ rd_wbw_link <-
#' @keywords internal
rd_input_raster <-
function(param) {
checkmate::assert_character(param, min.chars = 1L)
paste0(
"@param ", param,
" Raster object of class [WhiteboxRaster]. ",
Expand All @@ -35,6 +37,8 @@ rd_input_raster <-
#' @keywords internal
rd_example <-
function(foo, args = NULL) {
checkmate::assert_character(foo, min.chars = 1L)
checkmate::assert_vector(args, null.ok = TRUE)
paste(
"@examples",
# "\\dontrun{",
Expand All @@ -51,4 +55,30 @@ 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.

Loading
Loading