Skip to content

Commit

Permalink
TESTS: Add explicit test for 'filesize' handler [#168]
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Oct 19, 2024
1 parent 2362df2 commit 9a8b43a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions R/handler_filesize.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
handler_filesize <- function(file = "default.progress", intrusiveness = getOption("progressr.intrusiveness.file", 5), target = "file", enable = getOption("progressr.enable", TRUE), ...) {
reporter <- local({
set_file_size <- function(config, state, progression, message = state$message) {
## Troubleshoot https://github.com/HenrikBengtsson/progressr/issues/168
stop_if_not(
length(config$max_steps) == 1L, is.numeric(config$max_steps),
!is.na(config$max_steps), is.finite(config$max_steps),
config$max_steps >= 0,
length(state$step) == 1L, is.numeric(state$step),
!is.na(state$step), is.finite(state$step), state$step >= 0
)

ratio <- if (config$max_steps == 0) 1 else state$step / config$max_steps
size <- round(100 * ratio)
current_size <- file.size(file)
Expand Down

0 comments on commit 9a8b43a

Please sign in to comment.