metrumresearchgroup / mrgvalprep

Helpers for prepping inputs to mrgvalidate
https://metrumresearchgroup.github.io/mrgvalprep
Other
1 stars 0 forks source link

Get tests from a package directory without needing to run tests #56

Open barrettk opened 1 year ago

barrettk commented 1 year ago

Add support for getting tests from a package directory, without needing to run tests

Examples

one testing directory

# one testing directory
pkg_dir <- "/data/Projects/package_dev/bbr"
get_tests(pkg_dir)

# A tibble: 317 × 3
   result_file             TestName                                                      test_dir      
   <chr>                   <chr>                                                         <fs::path>    
 1 test-bbr.R              check_status_code works as expected [BBR-BBR-001]             tests/testthat
 2 test-bbr.R              bbi_dry_run() correctly returns object [BBR-BBR-002]          tests/testthat
 3 test-bbr.R              check_bbi_exe() correctly errors or finds paths [BBR-BBR-003] tests/testthat
 4 test-bbr.R              check_bbi_exe() errors on too low version [BBR-BBR-004]       tests/testthat
 5 test-bbr.R              bbi_init creates bbi.yaml [BBR-BBR-005]                       tests/testthat
 6 test-bbr.R              bbi_init errors with non-existent .dir [BBR-BBR-006]          tests/testthat
 7 test-bbr.R              bbi_init errors with invalid .nonmem_version [BBR-BBR-007]    tests/testthat
 8 test-bbr.R              bbi_init passes .bbi_args [BBR-BBR-008]                       tests/testthat
 9 test-bbr.R              bbi_help captures and relays bbi output [BBR-BBR-009]         tests/testthat
10 test-check-up-to-date.R check_up_to_date.bbi_nonmem_model() happy path [BBR-CUTD-001] tests/testthat
# … with 307 more rows
# ℹ Use `print(n = ...)` to see more rows

multiple testing directories

# multiple testing directories
# - note that only one package directory is still being used
pkg_dirs <- c(
  "/data/Projects/package_dev/bbr",
  "/data/Projects/package_dev/pmforest"
)
tests_df <- get_tests(pkg_dirs[1], test_dirs = get_testing_dir(pkg_dirs))

> head(tests_df)
# A tibble: 6 × 3
  result_file TestName                                                      test_dir      
  <chr>       <chr>                                                         <fs::path>    
1 test-bbr.R  check_status_code works as expected [BBR-BBR-001]             tests/testthat
2 test-bbr.R  bbi_dry_run() correctly returns object [BBR-BBR-002]          tests/testthat
3 test-bbr.R  check_bbi_exe() correctly errors or finds paths [BBR-BBR-003] tests/testthat
4 test-bbr.R  check_bbi_exe() errors on too low version [BBR-BBR-004]       tests/testthat
5 test-bbr.R  bbi_init creates bbi.yaml [BBR-BBR-005]                       tests/testthat
6 test-bbr.R  bbi_init errors with non-existent .dir [BBR-BBR-006]          tests/testthat

# tail data (so you can see the other tests were added - used another pkg to illustrate)
> tail(tests_df)
# A tibble: 6 × 3
  result_file       TestName                                                               test_dir                  
  <chr>             <chr>                                                                  <fs::path>                
1 test-input-data.R plot_forest() input data check warns with extra columns [PMF-DATA-004] ../pmforest/tests/testthat
2 test-nsim-plot.R  Multiple simulations base test [PMF-PLOT-012]                          ../pmforest/tests/testthat
3 test-nsim-plot.R  Multiple CIs with jitter [PMF-PLOT-013]                                ../pmforest/tests/testthat
4 test-summary.R    correct column is summarized [PMF-DATA-001]                            ../pmforest/tests/testthat
5 test-summary.R    Can switch between meanmedian [PMF-DATA-002]                           ../pmforest/tests/testthat
6 test-summary.R    Summary for multiple CIs [PMF-DATA-003]                                ../pmforest/tests/testthat
barrettk commented 1 year ago

Will hold off on adding tests for this until we confirm that the returned object is what we are looking for.

Also - let me know if we want a different function name

barrettk commented 1 year ago

I did just realize we will have to change the inputs to the second function (get_tests()). In cases like mrgsolve we will need a way to specify multiple test directories. I find get_testing_dir to be helpful, so maybe get_tests should actually require a vector of testing directories, with the default using get_testing_dir to get them (would always be of length 1)

Edit: addressed this in latest commit

barrettk commented 1 year ago

This issue seems somewhat related here

seth127 commented 1 year ago

Note to return to later: we may want to format it like described here but maybe without the pass/fail columns

(most of) relevant code is here