Skip to content

Add testthat coverage for trait meta-analysis pipeline functions#3858

Open
omkarrr2533 wants to merge 1 commit intoPecanProject:developfrom
omkarrr2533:add-meta-analysis-tests
Open

Add testthat coverage for trait meta-analysis pipeline functions#3858
omkarrr2533 wants to merge 1 commit intoPecanProject:developfrom
omkarrr2533:add-meta-analysis-tests

Conversation

@omkarrr2533
Copy link
Copy Markdown
Contributor

@omkarrr2533 omkarrr2533 commented Mar 9, 2026

What this does

Adds test coverage for the core functions in the meta-analysis pipeline — check_consistent(), run.meta.analysis.pft(), meta_analysis_standalone(), p.point.in.prior(), and documents a structural issue in get.parameter.samples().

These tests lock in existing behavior so that future refactoring (particularly the GSoC modularity work) has a safety net against regressions.

Why

The meta-analysis pipeline currently has minimal test coverage. Before changing anything in these functions, we need tests that confirm what they actually do today. A few things I found worth noting while writing these:

  • get.parameter.samples() ends with save(...) and no return() statement, so it returns invisible(NULL). Callers can't access results without loading the saved file. The test file documents this with a skip explaining the problem — this is the core architectural issue the GSoC project aims to fix.
  • run.meta.analysis.pft() checks for input files before touching the database, which means we can test all its precondition logic without needing a DB connection.
  • check_consistent() is a pure function with no side effects, so it's straightforward to test thoroughly.

What's covered

Function Tests What they check
check_consistent() 7 Normal and gamma priors, both tails, custom thresholds, input validation
run.meta.analysis.pft() 9 Missing file errors, skip-when-cached logic, empty trait data, string coercion, posteriorid checks
meta_analysis_standalone() 2 (skip if no JAGS) Greenhouse data filtering, full return structure verification
p.point.in.prior() 4 Normal/gamma distributions, extreme values, return type
get.parameter.samples() 0 (1 documented skip) Documents the invisible(NULL) problem structurally

22 tests run, 1 strategic skip.

Design decisions

  • No database needed. Every test either targets precondition checks that fire before any DB call, or uses the shared fixtures from helper-test-data.R. The dbcon = NULL calls are safe because run.meta.analysis.pft() validates input files before attempting any database operations.
  • JAGS tests skip gracefully. The integration test in test-meta_analysis_standalone.R checks for rjags installation and actual JAGS availability before running.
  • Shared fixtures in helper-test-data.R. create_test_trait_data(), create_test_priors(), create_test_pft(), and setup_trait_files() build minimal but realistic data structures that match what the pipeline actually produces. These are reusable for future tests.
  • Uses ::: for internal functions. check_consistent, p.point.in.prior, and run.meta.analysis.pft aren't exported, so tests access them via PEcAn.MA:::.

Checklist

  • All tests pass locally with devtools::test()
  • No changes to existing source code
  • Uses skip_on_cran() and skip_if_not_installed() where appropriate
  • R CMD check passes without new warnings

@omkarrr2533 omkarrr2533 changed the title https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fomkarrr2533%2Fpecan%2Fpull%2Fnew%2Fadd-meta-analysis-tests meta-analysis-tests Mar 9, 2026
@omkarrr2533 omkarrr2533 changed the title meta-analysis-tests Add testthat coverage for trait meta-analysis pipeline functions Mar 9, 2026
@omkarrr2533 omkarrr2533 force-pushed the add-meta-analysis-tests branch 2 times, most recently from 23d6ab7 to d9ca08e Compare March 9, 2026 13:45
@omkarrr2533 omkarrr2533 marked this pull request as draft March 10, 2026 17:11
@omkarrr2533 omkarrr2533 force-pushed the add-meta-analysis-tests branch 3 times, most recently from be57177 to 1f495fb Compare March 19, 2026 06:28
@omkarrr2533 omkarrr2533 marked this pull request as ready for review March 19, 2026 06:31
@omkarrr2533 omkarrr2533 force-pushed the add-meta-analysis-tests branch 2 times, most recently from 6b2de10 to 2eab0f0 Compare March 19, 2026 07:24
Add comprehensive test coverage for the core meta-analysis pipeline
functions as preparation for modularity improvements planned in the
GSoC 'Refactoring the PEcAn trait meta-analysis workflow' project.

New test files:
- helper-test-data.R: Shared fixtures
- test-check_consistent.R: Unit tests for check_consistent()
- test-run.meta.analysis.pft.R: Tests for workflow wrapper
- test-meta_analysis_standalone.R: Tests for core analysis function
- test-get.parameter.samples.R: Documents invisible(NULL) return problem

These tests lock in current behavior before any refactoring begins.
No functional changes to existing code.
@omkarrr2533 omkarrr2533 force-pushed the add-meta-analysis-tests branch from 2eab0f0 to 6783775 Compare March 19, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant