Skip to content

Commit

Permalink
Merge pull request #2 from turtletopia/devel
Browse files Browse the repository at this point in the history
fix mclapply() tests
  • Loading branch information
ErdaradunGaztea authored Feb 5, 2023
2 parents 228a453 + 8c08db5 commit fa24e98
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/pb.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' Makes the object spawn a progress bar in response to indexing with `[[`
#' operator. Intended to be used with most iterators in R, e.g.:
#' [base::lapply()] and some of its cousins, [base::Reduce()],
#' [parallel::mclapply()], [purrr::map()], [foreach::foreach()]...
#' [plyr::llply()], [purrr::map()], [foreach::foreach()]...
#'
#' @param object `ANY`\cr
#' An iterable that should spawn a progress bar.
Expand Down
2 changes: 1 addition & 1 deletion man/pb.Rd

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

16 changes: 16 additions & 0 deletions tests/testthat/test-pb-methods.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
test_that("no progress bar call is being made when using str()", {
x <- pb(seq(10))
pre_val <- aurrera:::.PROGRESS_BAR$getVal()
suppress_output(str(x))
expect_equal(
aurrera:::.PROGRESS_BAR$getVal(),
pre_val
)
})

test_that("`aurrera_iter` class is preserved when using c()", {
x <- pb(seq(10))
expect_vector(c(x, 17:20),
ptype = pb(1L),
size = 14)
})
9 changes: 7 additions & 2 deletions tests/testthat/test-pb.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ test_that("purrr::map_chr() returns correct value", {
# PARALLEL::MCLAPPLY ----------------------------------------------------------
test_that("pb() prints progress bar inside parallel::mclapply()", {
expect_equal(
capture_output(parallel::mclapply(pb(x), identity), width = width),
capture_output(
parallel::mclapply(pb(x), identity, mc.preschedule = FALSE),
width = width
),
bar
)
})

test_that("parallel::mclapply() returns correct value", {
suppress_output(ret <- parallel::mclapply(pb(x), identity))
suppress_output(
ret <- parallel::mclapply(pb(x), identity, mc.preschedule = FALSE)
)
expect_equal(ret, x)
})

Expand Down

0 comments on commit fa24e98

Please sign in to comment.