Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SS3 integration tests for testing convert_output() #45

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ Imports:
Suggests:
knitr,
rmarkdown,
parallel,
snowfall,
r4ss,
testthat (>= 3.0.0)
VignetteBuilder:
knitr
Remotes:
nmfs-ost/satf
nmfs-ost/satf,
r4ss/r4ss
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
60 changes: 60 additions & 0 deletions tests/testthat/fixtures/prepare_ss3_output_files.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Download SS3 models and place them in the specified directory
ss3_models <- r4ss::download_models(
dir = test_path("fixtures", "ss3_models")
)

# Get the SS3 executable for running the models
ss3_exe <- r4ss::get_ss3_exe(
dir = test_path("fixtures", "ss3_models")
)

# Function to run a specific SS3 model
run_ss3_models <- function(model_id, model_dir, exe_dir){
# Define the working directory for the model
working_dir <- model_dir[model_id]

# Copy the SS3 executable to the model's working directory
file.copy(Sys.which(file.path(exe_dir, "ss3")), working_dir)

# Run SS3 model
r4ss::run(dir = working_dir)
}

# List all the model directories to be processed
all_models <- list.dirs(
file.path(test_path("fixtures", "ss3_models"), "models"),
full.names = TRUE,
recursive = FALSE
)

# Detect the number of available CPU cores, leaving one free
core_num <- parallel::detectCores() - 1

# Initialize snowfall for parallel processing, using the detected core count
snowfall::sfInit(parallel = TRUE, cpus = core_num)

# Run the SS3 models in parallel using the snowfall library
snowfall::sfLapply(
1:length(all_models),
run_ss3_models,
all_models,
test_path("fixtures", "ss3_models")
)

# Stop the snowfall parallel session
snowfall::sfStop()

# Remove the SS3 files except Report.sso from the working directory after the run is complete
all_files <- list.files(
test_path("fixtures", "ss3_models", "models"),
full.names = TRUE,
recursive = TRUE
)
report_files <- file.path(all_models, "Report.sso")

report_id <- match(report_files, all_files)
files_to_delete <- all_files[-report_id]
file.remove(files_to_delete)

# Clean up by removing the SS3 executable from the main directory after running all models
file.remove(Sys.which(test_path("fixtures", "ss3_models", "ss3")))
Loading