Skip to content

Closes #2990 Tests: Move data within testthat calls for test-derive_param_bsa.R#2991

Open
Copilot wants to merge 2 commits intomainfrom
copilot/move-data-in-testthat-calls
Open

Closes #2990 Tests: Move data within testthat calls for test-derive_param_bsa.R#2991
Copilot wants to merge 2 commits intomainfrom
copilot/move-data-in-testthat-calls

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

Seven BSA formula helper functions in tests/testthat/test-derive_param_bsa.R were defined at the top-level file scope, leaking into the global test environment and risking state spillover between tests. Each function is now scoped inside its corresponding test_that block.

Changes:

  • Moved mosteller, dubois, haycock, gehan, boyd, fujimoto, and takahira helper functions from top-level scope into Tests 28–34 respectively

Before:

mosteller <- function(hgt, wgt) sqrt(hgt * wgt / 3600)

test_that("derive_param_bsa Test 28: ...", {
  ...mosteller(170, 75)...
})

After:

test_that("derive_param_bsa Test 28: ...", {
  mosteller <- function(hgt, wgt) sqrt(hgt * wgt / 3600)
  ...mosteller(170, 75)...
})

Thank you for your Pull Request! We have developed this task checklist from the Development Process Guide to help with the final steps of the process. Completing the below tasks helps to ensure our reviewers can maximize their time on your code as well as making sure the admiral codebase remains robust and consistent.

Please check off each taskbox as an acknowledgment that you completed the task or check off that it is not relevant to your Pull Request. This checklist is part of the Github Action workflows and the Pull Request will not be merged into the main branch until you have checked off each task.

  • Place Closes #<insert_issue_number> into the beginning of your Pull Request Title (Use Edit button in top-right if you need to update)
  • Code is formatted according to the tidyverse style guide. Run styler::style_file() to style R and Rmd files
  • Updated relevant unit tests or have written new unit tests, which should consider realistic data scenarios and edge cases, e.g. empty datasets, errors, boundary cases etc. - See Unit Test Guide
  • If you removed/replaced any function and/or function parameters, did you fully follow the deprecation guidance? N/A
  • Review the Cheat Sheet. Make any required updates to it by editing the file inst/cheatsheet/admiral_cheatsheet.pptx and re-upload a PDF and a PNG version of it to the same folder. (The PNG version can be created by taking a screenshot of the PDF version.) N/A
  • Update to all relevant roxygen headers and examples, including keywords and families. Refer to the categorization of functions to tag appropriate keyword/family. N/A
  • Run devtools::document() so all .Rd files in the man folder and the NAMESPACE file in the project root are updated appropriately. N/A
  • Address any updates needed for vignettes and/or templates. N/A
  • Update NEWS.md under the header # admiral (development version) if the changes pertain to a user-facing function (i.e. it has an @export tag) or documentation aimed at users (rather than developers). N/A — test-only change
  • Build admiral site pkgdown::build_site() and check that all affected examples are displayed correctly and that all new functions occur on the "Reference" page. N/A
  • Address or fix all lintr warnings and errors - lintr::lint_package(). N/A
  • Run R CMD check locally and address all errors and warnings - devtools::check()
  • Link the issue in the Development Section on the right hand side.
  • Address all merge conflicts and resolve appropriately
  • Pat yourself on the back for a job well done! Much love to your accomplishment!
Original prompt

This section details on the original issue you should resolve

<issue_title>Tests: Move data within testthat calls</issue_title>
<issue_description>## Background

Please see #2978 for additional background and discussion.

The tests in "tests/testthat/test-derive_param_bsa.R" have data being created outside of the testthat calls which can have unintended side effects.

The data should be moved inside the testthat calls if it is small. For data that is large or repeatedly used throughout tests another method should be used, e.g. use of withr and/or creating an additional subfolder within testthat called testdata. All efforts should be made to ensure data does not spillover into another test.

Definition of done

  • Tests in "tests/testthat/test-derive_param_bsa.R" have all data self-contained
  • Test Data is documented as needed
    </issue_description>

<agent_instructions>Please only update the tests for derive_param_base.R in the corresponding test-derive_param_bsa.R Please make an effort to tear down any testdata used to ensure no spillovers happen with other admiral tests</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@bms63 @adcascone do you have the Assign Copilot?

Image</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: bms63 <10111024+bms63@users.noreply.github.com>
Copilot AI changed the title [WIP] Update tests to ensure data is within testthat calls Closes #[issue] Tests: Move data within testthat calls for test-derive_param_bsa.R Feb 27, 2026
@bms63 bms63 changed the title Closes #[issue] Tests: Move data within testthat calls for test-derive_param_bsa.R Closes #2990 Tests: Move data within testthat calls for test-derive_param_bsa.R Feb 27, 2026
@bms63
Copy link
Collaborator

bms63 commented Feb 27, 2026

@adcascone I made this with co-pilot. Do you mind reviewing? This one didn't have any data in it just the functions - which was interesting it caught that!!

@bms63 bms63 marked this pull request as ready for review February 27, 2026 21:38
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

Code Coverage

Package Line Rate Health
admiral 100%
Summary 100% (6131 / 6144)

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.

Tests: Move data within testthat calls

2 participants