Skip to content

Commit 45a60cf

Browse files
github-actions[bot]Kristina W. Lai
andcommitted
Fix CI failures: lint, test mock, duplicate verbose message, docs
- Fix line length lint errors in R/sim_pop_data_multi.R (lines 28, 30 exceeded 80 chars; wrap check_parallel_cores() call across lines) - Fix check_parallel_cores mock signature in test-sim_pop_data_multi.R: mock was function(x) but production code calls with named args (num_cores, chk, verbose); rewrite test to mock detectCores instead so the full cap path (including env-var cap inside check_parallel_cores) is exercised end-to-end via register_calls - Remove duplicate cli::cli_inform in check_parallel_cores() verbose block - Remove misleading '(Unchanged)' annotation from comment - Update man/check_parallel_cores.Rd: \verb{} -> \code{} for _R_CHECK_LIMIT_CORES_ (roxygen2 8.0.0 uses \code{} for strings without Rd markup characters) Co-authored-by: Kristina W. Lai <undefined@users.noreply.github.com>
1 parent 477cc4d commit 45a60cf

4 files changed

Lines changed: 20 additions & 31 deletions

File tree

R/check_parallel_cores.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,11 @@ check_parallel_cores <- function(num_cores, chk = "", verbose = FALSE) {
4747
)
4848
}
4949

50-
# 3. Report setup if verbose (Unchanged)
50+
# 3. Report setup if verbose
5151
if (verbose) {
5252
cli::cli_inform(
5353
"Setting up parallel processing with `num_cores` = {num_cores}."
5454
)
55-
cli::cli_inform(
56-
"Set up parallel processing with `num_cores`={num_cores}"
57-
)
5855
}
5956

6057
return(as.integer(num_cores))

R/sim_pop_data_multi.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ sim_pop_data_multi <- function(
2525
}
2626

2727
if (num_cores > 1L) {
28-
# Fetch env var and run all environment/safety checks inside check_parallel_cores
2928
chk <- Sys.getenv("_R_CHECK_LIMIT_CORES_", "")
30-
num_cores <- check_parallel_cores(num_cores = num_cores, chk = chk, verbose = verbose)
29+
num_cores <- check_parallel_cores(
30+
num_cores = num_cores, chk = chk, verbose = verbose
31+
)
3132
}
3233

3334
doParallel::registerDoParallel(cores = num_cores)

man/check_parallel_cores.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-sim_pop_data_multi.R

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,14 @@ test_that("`sim_pop_data_multi()` handles _R_CHECK_LIMIT_CORES_ values", {
7272
do.call(sim_pop_data_multi, c(base_args, list(verbose = verbose)))
7373
}
7474

75-
# Track core selections across scenarios.
76-
calls <- list()
75+
# Track the final core count passed to registerDoParallel across scenarios.
76+
# We mock detectCores to return a large number so the hardware-limit path
77+
# in check_parallel_cores() does not interfere with env-var cap testing.
7778
register_calls <- list()
7879
register_parallel <- doParallel::registerDoParallel
7980
testthat::local_mocked_bindings(
80-
check_parallel_cores = function(x) {
81-
calls <<- c(calls, list(x))
82-
x
83-
},
84-
.package = "serocalculator"
81+
detectCores = function(...) 100L,
82+
.package = "parallel"
8583
)
8684
testthat::local_mocked_bindings(
8785
registerDoParallel = function(cores) {
@@ -111,22 +109,15 @@ test_that("`sim_pop_data_multi()` handles _R_CHECK_LIMIT_CORES_ values", {
111109
expect_true(all(sim_data$lambda.sim == 0.05))
112110
expect_true(all(sim_data$cluster == 1))
113111
}
114-
expected_calls <- list(
115-
# TRUE: cap at 2 cores.
116-
cran_cap = min(num_cores, 2L),
117-
# FALSE: no cap.
118-
no_limit = num_cores,
119-
# Numeric value: cap at 1 core.
120-
numeric_cap = min(num_cores, 1L),
121-
# Unrecognized value: conservative cap at 2 cores.
122-
invalid_cap = min(num_cores, 2L)
112+
# Expected final core counts after env-var cap applied by check_parallel_cores()
113+
expected_register_calls <- list(
114+
cran_cap = 2L, # TRUE caps at 2; min(2L, 2L) = 2L
115+
no_limit = 2L, # FALSE: no cap; original num_cores = 2L
116+
numeric_cap = 1L, # "1": cap at 1; min(2L, 1L) = 1L
117+
invalid_cap = 2L # unrecognized: conservative cap at 2; min(2L, 2L) = 2L
123118
)
124-
expect_identical(calls[[1]], expected_calls$cran_cap)
125-
expect_identical(calls[[2]], expected_calls$no_limit)
126-
expect_identical(calls[[3]], expected_calls$numeric_cap)
127-
expect_identical(calls[[4]], expected_calls$invalid_cap)
128-
expect_identical(register_calls[[1]], expected_calls$cran_cap)
129-
expect_identical(register_calls[[2]], expected_calls$no_limit)
130-
expect_identical(register_calls[[3]], expected_calls$numeric_cap)
131-
expect_identical(register_calls[[4]], expected_calls$invalid_cap)
119+
expect_identical(register_calls[[1]], expected_register_calls$cran_cap)
120+
expect_identical(register_calls[[2]], expected_register_calls$no_limit)
121+
expect_identical(register_calls[[3]], expected_register_calls$numeric_cap)
122+
expect_identical(register_calls[[4]], expected_register_calls$invalid_cap)
132123
})

0 commit comments

Comments
 (0)