test: add a testthat suite and CI - #12
Merged
Merged
Conversation
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
This was referenced Sep 14, 2026
Merged
ci: add a testthat suite and move to the shared workflows
PredictiveEcology/Biomass_regenerationPM#4
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a testthat suite and CI to this module, as piloted on PredictiveEcology/fireSense_EscapeFit#4.
What's added
.github/workflows/testthat-module.yamlcalls the sharedtestthat-moduleworkflow (Add testthat-module reusable workflow actions#44). It installs the module'sreqdPkgs, converts the module into a package in a throwaway directory withconvertToPackage(destinationPath = ), runstests/testthat, and writes coverage to the job summary. Nothing is committed back.tests/testthat/setup.Ris actions'examples/module-tests-setup.R: options,moduleName/modulePath, and a temporary directory tree.tests/testthat/test-metadata.Rasserts 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.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 withsubscript out of bounds. It did fire for a row with an empty params table. Checked against the unmodified module, both shapes: zero rows gavesubscript 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 2020test-SpreadPredict.R, which errored on the now-defunctSpaDES.tools::gaussMap()and supplied aweatherinput anddata/mappingparameters the module no longer has. The new test builds inputs shaped like the upstream modules' output on a 10×10 landscape, checks thatsimInit()succeeds, runs onerunevent, and asserts that every flammable pixel gets a spread probability betweenlowerSpreadProband the logistic asymptote, and that the surface is not constant. It also covers the no-parameters error above.Flagged, not changed here: the
runevent readssim$fireSense_spreadFormulaandsim$studyAreaWithSpreadParams, and neither is declared inexpectsInput(). The declaredfireSense_SpreadFittedis used only inside the deadif (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'stestthat-modulerun is the check on the package-conversion path.🤖 Generated with Claude Code
https://claude.ai/code/session_0133867aFrmKtbhpNXasToP9