Skip to content

Commit

Permalink
document and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barrettk committed Jun 28, 2024
1 parent 2fbd57a commit aa78cbb
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ S3method(print,bbi_nmboot_summary)
S3method(print,bbi_nonmem_summary)
S3method(print,bbi_process)
S3method(print,model_tree_static)
S3method(print,nmtran_process)
S3method(print_model_files,default)
S3method(submit_model,bbi_base_model)
S3method(submit_model,bbi_nmboot_model)
Expand Down Expand Up @@ -194,6 +195,7 @@ export(replace_model_field)
export(replace_note)
export(replace_tag)
export(run_log)
export(run_nmtran)
export(setup_bootstrap_run)
export(submit_model)
export(submit_models)
Expand Down
19 changes: 19 additions & 0 deletions man/execute_nmtran.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions man/locate_nmtran.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/print_bbi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions man/run_nmtran.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions tests/testthat/test-workflow-bbi.R
Original file line number Diff line number Diff line change
Expand Up @@ -305,5 +305,103 @@ withr::with_options(list(
run_times <- model_summaries(mods) %>% check_run_times(.wait = FALSE) %>% suppressWarnings()
expect_equal(dim(run_times), c(3, 3))
})

describe("run_nmtran", {
it("locate_nmtran", {
mod1 <- read_model(file.path(MODEL_DIR_BBI, "1"))
# Using model object, looks for bbi.yaml
nmtran_exe <- locate_nmtran(mod1)
# Confirm executable
expect_equal(as.character(nmtran_exe), "/opt/NONMEM/nm74gf/tr/NMTRAN.exe")
# Confirm NONMEM version
expect_equal(attr(nmtran_exe, "nonmem_version"), "nm74gf")

# Passed executable
nmtran_exe <- locate_nmtran(mod1, nmtran_exe = "/opt/NONMEM/nm74gf/tr/NMTRAN.exe")
# Confirm executable
expect_equal(as.character(nmtran_exe), "/opt/NONMEM/nm74gf/tr/NMTRAN.exe")
# Confirm NONMEM version
expect_true(is.null(attr(nmtran_exe, "nonmem_version")))

# Passed config_path
nmtran_exe <- locate_nmtran(.config_path = file.path(MODEL_DIR_BBI, "bbi.yaml"))
# Confirm executable
expect_equal(as.character(nmtran_exe), "/opt/NONMEM/nm74gf/tr/NMTRAN.exe")
# Confirm NONMEM version
expect_equal(attr(nmtran_exe, "nonmem_version"), "nm74gf")

# Wrong nmtran_exe path passed
expect_error(
locate_nmtran(mod1, nmtran_exe = "/opt/NONMEM/nm74gf/tr/NMTRAN2.exe"),
"Could not find an NMTRAN executable"
)

# no configuration file found
expect_error(
locate_nmtran(.config_path = file.path(tempdir(), "bbi.yaml")),
"No bbi configuration was found"
)
})

it("execute_nmtran", {
# Execute in subdirectory to avoid messing with other tests
nmtran_dir <- file.path(MODEL_DIR_BBI, "nmtran")
fs::dir_create(nmtran_dir)
on.exit(fs::dir_delete(nmtran_dir), add = TRUE)

# Copy model file into new model dir
fs::file_copy(CTL_TEST_FILE, nmtran_dir, overwrite = TRUE)
mod1 <- new_model(file.path(nmtran_dir, "1"), .overwrite = TRUE)

# create new bbi.yaml
bbi_init(
nmtran_dir,
.nonmem_dir = Sys.getenv("BBR_TESTS_NONMEM_DIR", "/opt/NONMEM"),
.nonmem_version = Sys.getenv("BBR_TESTS_NONMEM_VERSION", "nm74gf"),
.bbi_args = list(mpi_exec_path = get_mpiexec_path())
)

nmtran_exe <- locate_nmtran(mod1)
nmtran_results <- execute_nmtran(
nmtran_exe, mod_path = basename(get_model_path(mod1)), dir = nmtran_dir
)

# Check attributes
expect_equal(nmtran_dir, nmtran_results$run_dir)
expect_equal(nmtran_results$status_val, 0)
expect_equal(nmtran_results$status, "NMTRAN successful")

# Test failure
data_path <- "test/this/path/data.csv"
modify_data_path_ctl(mod1, data_path)

nmtran_results <- execute_nmtran(
nmtran_exe, mod_path = basename(get_model_path(mod1)), dir = nmtran_dir
)

# Check attributes
expect_equal(nmtran_results$status_val, 4)
expect_equal(nmtran_results$status, "NMTRAN failed. See errors.")
})

it("run_nmtran", {
# create model
mod1 <- read_model(file.path(MODEL_DIR_BBI, "1"))

nmtran_results <- run_nmtran(mod1, delete_on_exit = FALSE)
on.exit(fs::dir_delete(nmtran_results$run_dir))

# Check attributes
expect_equal(get_model_path(mod1), nmtran_results$absolute_model_path)
expect_equal(
file.path(nmtran_results$run_dir, basename(get_model_path(mod1))),
nmtran_results$nmtran_model
)
expect_equal(nmtran_results$nonmem_version, "nm74gf")
expect_equal(nmtran_results$status_val, 0)
expect_equal(nmtran_results$status, "NMTRAN successful")
})
})

}) # closing withr::with_options

0 comments on commit aa78cbb

Please sign in to comment.