Skip to content

test: add a testthat suite and CI - #12

Merged
eliotmcintire merged 2 commits into
developmentfrom
feat/add-testthat-ci
Sep 11, 2026
Merged

eliotmcintire merged 2 commits into
developmentfrom
feat/add-testthat-ci

Conversation

@eliotmcintire

Copy link
Copy Markdown
Collaborator

Adds a testthat suite and CI to this module, as piloted on PredictiveEcology/fireSense_EscapeFit#4.

What's added

  • .github/workflows/testthat-module.yaml calls the shared testthat-module workflow (Add testthat-module reusable workflow actions#44). It installs the module's reqdPkgs, converts the module into a package in a throwaway directory with convertToPackage(destinationPath = ), runs tests/testthat, and writes coverage to the job summary. Nothing is committed back.
  • tests/testthat/setup.R is actions' examples/module-tests-setup.R: options, moduleName / modulePath, and a temporary directory tree.
  • tests/testthat/test-metadata.R asserts the declared inputs and outputs (names and classes) and the parameter names, which together are the module's public contract. It was generated from the module's own metadata rather than typed. A deliberate change to any of these should update this file in the same commit, with a matching version bump.
  • The newModule() scaffolding (tests/testthat/test-template.R, tests/unitTests.R) is removed.

Also fixes a bug the new test found (separate commit). The no-fitted-parameters guard from b3146a7 tests NROW(sim$studyAreaWithSpreadParams) == 0L, but it could never fire for zero rows: logisticPars <- sim$studyAreaWithSpreadParams$params[[1]], 30 lines earlier, failed first with subscript out of bounds. It did fire for a row with an empty params table. Checked against the unmodified module, both shapes: zero rows gave subscript out of bounds; after moving the guard above that line, both give its message.

New tests/testthat/test-simInit.R, written from scratch. It replaces the 2020 test-SpreadPredict.R, which errored on the now-defunct SpaDES.tools::gaussMap() and supplied a weather input and data/mapping parameters the module no longer has. The new test builds inputs shaped like the upstream modules' output on a 10×10 landscape, checks that simInit() succeeds, runs one run event, and asserts that every flammable pixel gets a spread probability between lowerSpreadProb and the logistic asymptote, and that the surface is not constant. It also covers the no-parameters error above.

Flagged, not changed here: the run event reads sim$fireSense_spreadFormula and sim$studyAreaWithSpreadParams, and neither is declared in expectsInput(). The declared fireSense_SpreadFitted is used only inside the dead if (FALSE) branch. The metadata test records the declarations as they are, so fixing them means updating that file too.

Verified locally: testthat::test_dir("tests/testthat") passes (R 4.6.1, SpaDES.core 3.2.0, fireSenseUtils 0.2.3.9003). That goes through the module file directly; this PR's testthat-module run is the check on the package-conversion path.

🤖 Generated with Claude Code

https://claude.ai/code/session_0133867aFrmKtbhpNXasToP9

eliotmcintire and others added 2 commits September 10, 2026 11:40
The guard added in b3146a7 tests NROW(sim$studyAreaWithSpreadParams) == 0L,
but could never fire for zero rows: spreadPredictRun() had already run
  logisticPars <- sim$studyAreaWithSpreadParams$params[[1]]
which fails first with "subscript out of bounds". It did work for a row
whose params table is empty. Move the guard above that line so both
shapes get its explanation. Covered by tests/testthat/test-simInit.R.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0133867aFrmKtbhpNXasToP9
- .github/workflows/testthat-module.yaml calls the shared
  PredictiveEcology/actions testthat-module workflow (@main), which tests
  the module as a package via convertToPackage(destinationPath =).
- tests/testthat/setup.R is actions' examples/module-tests-setup.R.
- tests/testthat/test-metadata.R asserts the declared inputs and outputs
  (names and classes) and parameter names -- the module's public contract.
  Generated from the module's own metadata, not typed.
- tests/testthat/test-simInit.R, written from scratch: simInit() with
  inputs shaped like the upstream modules', one run event giving a
  spread-probability SpatRaster bounded by lowerSpreadProb and the logistic
  asymptote, and the no-fitted-parameters error.
- Removes tests/testthat/test-SpreadPredict.R (2020; errored on the
  defunct SpaDES.tools::gaussMap() and supplied inputs and parameters the
  module no longer has) and tests/unitTests.R.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0133867aFrmKtbhpNXasToP9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant