Skip to content

Commit

Permalink
adds some missing prefixes on test_that
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Jan 23, 2024
1 parent d0c48c6 commit 471b475
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions tests/testthat/test-Archiver.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ testthat::test_that("JSONArchiver write a reporter", {
path_with_files <- archiver$get_output_dir()

testthat::test_that("JSONArchiver write a reporter with a json file and static files", {
expect_true(dir.exists(archiver$get_output_dir()))
testthat::expect_true(dir.exists(archiver$get_output_dir()))
files <- list.files(archiver$get_output_dir())
testthat::expect_true(length(files) == 4)
testthat::expect_true("Report.json" %in% files)
})

testthat::test_that("JSONArchiver read back the Reporter instance", {
expect_s3_class(archiver$read(), "Reporter")
testthat::expect_s3_class(archiver$read(), "Reporter")
testthat::expect_length(archiver$read()$get_cards(), 2L)
testthat::expect_length(archiver$read()$get_blocks(), 8L)
})
Expand All @@ -109,7 +109,7 @@ testthat::test_that("JSONArchiver read back and all table/picture statics exists
archiver2 <- JSONArchiver$new()
testthat::test_that("JSONArchiver read back the Reporter instance, from a path", {
reporter_temp <- archiver2$read(path_with_files)
expect_s3_class(reporter_temp, "Reporter")
testthat::expect_s3_class(reporter_temp, "Reporter")
testthat::expect_length(reporter_temp$get_cards(), 2L)
testthat::expect_length(reporter_temp$get_blocks(), 8L)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-DownloadReportModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ testthat::test_that("report_render_and_compress - render an html document", {
temp_dir <- tempdir()
knitr_args <- list()
res_path <- report_render_and_compress(reporter, input, knitr_args, temp_dir)
expect_identical(res_path, temp_dir)
testthat::expect_identical(res_path, temp_dir)
files <- list.files(temp_dir, recursive = TRUE)
testthat::expect_true(any(grepl("[.]Rmd", files)))
testthat::expect_true(any(grepl("[.]html", files)))
Expand Down
48 changes: 24 additions & 24 deletions tests/testthat/test-Reporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ reporter <- Reporter$new()
reporter$append_cards(list(card1, card2))

testthat::test_that("get_cards returns the same cards which was added to reporter", {
expect_identical(reporter$get_cards(), list(card1, card2))
testthat::expect_identical(reporter$get_cards(), list(card1, card2))
})

testthat::test_that("get_blocks returns the same blocks which was added to reporter, sep = NULL", {
expect_identical(reporter$get_blocks(sep = NULL), append(card1$get_content(), card2$get_content()))
testthat::expect_identical(reporter$get_blocks(sep = NULL), append(card1$get_content(), card2$get_content()))
})

reporter_blocks <- reporter$get_blocks()
reporter_blocks2 <- append(reporter_blocks[1:3], NewpageBlock$new())
reporter_blocks2 <- append(reporter_blocks2, reporter_blocks[5:8])

testthat::test_that("get_blocks by default adds NewpageBlock$new() between cards", {
expect_equal(reporter$get_blocks(), reporter_blocks2)
testthat::expect_equal(reporter$get_blocks(), reporter_blocks2)
})

reporter2 <- Reporter$new()

testthat::test_that("get_blocks and get_cards return empty list by default", {
expect_identical(reporter2$get_blocks(), list())
expect_identical(reporter2$get_cards(), list())
testthat::expect_identical(reporter2$get_blocks(), list())
testthat::expect_identical(reporter2$get_cards(), list())
})

testthat::test_that("The deep copy constructor copies the content files to new files", {
Expand Down Expand Up @@ -97,99 +97,99 @@ testthat::test_that("get_metadata", {
})

testthat::test_that("from_reporter returns identical/equal object from the same reporter", {
expect_identical(reporter, reporter$from_reporter(reporter))
testthat::expect_identical(reporter, reporter$from_reporter(reporter))
})

reporter1 <- Reporter$new()
reporter1$append_cards(list(card1, card2))
reporter2 <- Reporter$new()

testthat::test_that("from_reporter does not return identical/equal object form other reporter", {
expect_false(identical(reporter1, reporter2$from_reporter(reporter1)))
testthat::expect_false(identical(reporter1, reporter2$from_reporter(reporter1)))
})

testthat::test_that("from_reporter persists the cards structure", {
expect_identical(reporter1$get_cards(), reporter2$from_reporter(reporter1)$get_cards())
testthat::expect_identical(reporter1$get_cards(), reporter2$from_reporter(reporter1)$get_cards())
})

testthat::test_that("from_reporter persists the reactive_add_card count", {
expect_identical(
testthat::expect_identical(
shiny::isolate(reporter1$get_reactive_add_card()),
shiny::isolate(reporter2$from_reporter(reporter1)$get_reactive_add_card())
)
})

testthat::test_that("to_jsondir require the existing directory path", {
expect_error(reporter1$to_list(), 'argument "output_dir" is missing, with no default')
expect_error(reporter1$to_list("/path/WRONG"), "Directory '/path/WRONG' does not exist.")
testthat::expect_error(reporter1$to_list(), 'argument "output_dir" is missing, with no default')
testthat::expect_error(reporter1$to_list("/path/WRONG"), "Directory '/path/WRONG' does not exist.")
})

temp_dir <- file.path(tempdir(), "test")
unlink(temp_dir, recursive = TRUE)
dir.create(temp_dir)

testthat::test_that("to_jsondir returns a list.", {
expect_equal(
testthat::expect_equal(
list(version = "1", cards = list(), metadata = list()),
Reporter$new()$to_list(temp_dir)
)
})

testthat::test_that("to_jsondir and from_jsondir could be used to save and retrive a Reporter ", {
expect_identical(
testthat::expect_identical(
length(reporter1$get_cards()),
length(Reporter$new()$from_list(reporter1$to_list(temp_dir), temp_dir)$get_cards())
)
expect_identical(
testthat::expect_identical(
length(reporter1$get_blocks()),
length(Reporter$new()$from_list(reporter1$to_list(temp_dir), temp_dir)$get_blocks())
)
})


testthat::test_that("from_reporter returns identical/equal object from the same reporter", {
expect_identical(reporter, reporter$from_reporter(reporter))
testthat::expect_identical(reporter, reporter$from_reporter(reporter))
})

reporter1 <- Reporter$new()
reporter1$append_cards(list(card1, card2))
reporter2 <- Reporter$new()

testthat::test_that("from_reporter does not return identical/equal object form other reporter", {
expect_false(identical(reporter1, reporter2$from_reporter(reporter1)))
testthat::expect_false(identical(reporter1, reporter2$from_reporter(reporter1)))
})

testthat::test_that("from_reporter persists the cards structure", {
expect_identical(reporter1$get_cards(), reporter2$from_reporter(reporter1)$get_cards())
testthat::expect_identical(reporter1$get_cards(), reporter2$from_reporter(reporter1)$get_cards())
})

testthat::test_that("from_reporter persists the reactive_add_card count", {
expect_identical(
testthat::expect_identical(
shiny::isolate(reporter1$get_reactive_add_card()),
shiny::isolate(reporter2$from_reporter(reporter1)$get_reactive_add_card())
)
})

testthat::test_that("to_jsondir require the existing directory path", {
expect_error(reporter$to_jsondir(), 'argument "output_dir" is missing, with no default')
expect_error(reporter$to_jsondir("/path/WRONG"), "Directory '/path/WRONG' does not exist.")
testthat::expect_error(reporter$to_jsondir(), 'argument "output_dir" is missing, with no default')
testthat::expect_error(reporter$to_jsondir("/path/WRONG"), "Directory '/path/WRONG' does not exist.")
})

temp_dir <- file.path(tempdir(), "test")
unlink(temp_dir, recursive = TRUE)
dir.create(temp_dir)

testthat::test_that("to_jsondir returns the same dir it was provided to it", {
expect_identical(temp_dir, reporter$to_jsondir(temp_dir))
testthat::expect_identical(temp_dir, reporter$to_jsondir(temp_dir))
})

testthat::test_that("from_jsondir returns identical/equal object", {
unlink(list.files(temp_dir), recursive = TRUE)
expect_identical(reporter, reporter$from_jsondir(temp_dir))
testthat::expect_identical(reporter, reporter$from_jsondir(temp_dir))
})

testthat::test_that("to_jsondir and from_jsondir could be used to save and retrive a Reporter", {
reporter_arch <- reporter$from_jsondir(reporter$to_jsondir(temp_dir))
expect_identical(reporter$get_cards(), reporter_arch$get_cards())
expect_identical(reporter$get_metadata(), reporter_arch$get_metadata())
testthat::expect_identical(reporter$get_cards(), reporter_arch$get_cards())
testthat::expect_identical(reporter$get_metadata(), reporter_arch$get_metadata())
})
6 changes: 3 additions & 3 deletions tests/testthat/test-addCardModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ testthat::test_that("add_card_button_srv try the card_fun", {
args = list(reporter = Reporter$new(), card_fun = card_fun),
expr = {
session$setInputs(`add_report_card_button` = 0)
expect_warning(session$setInputs(`add_card_ok` = 0))
testthat::expect_warning(session$setInputs(`add_card_ok` = 0))
}
)

Expand All @@ -99,7 +99,7 @@ testthat::test_that("add_card_button_srv try the card_fun", {
args = list(reporter = Reporter$new(), card_fun = card_fun),
expr = {
session$setInputs(`add_report_card_button` = 0)
expect_warning(session$setInputs(`add_card_ok` = 0))
testthat::expect_warning(session$setInputs(`add_card_ok` = 0))
}
)

Expand All @@ -112,7 +112,7 @@ testthat::test_that("add_card_button_srv try the card_fun", {
args = list(reporter = Reporter$new(), card_fun = card_fun),
expr = {
session$setInputs(`add_report_card_button` = 0)
expect_warning(session$setInputs(`add_card_ok` = 0))
testthat::expect_warning(session$setInputs(`add_card_ok` = 0))
}
)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ testthat::test_that("to_flextable: supported class", {

testthat::test_that("to_flextable: unsupported class", {
unsupported_data <- list(a = 1, b = 2)
expect_error(to_flextable(unsupported_data), "Unsupported class")
testthat::expect_error(to_flextable(unsupported_data), "Unsupported class")
})

testthat::test_that("custom_theme to flextable", {
Expand Down

0 comments on commit 471b475

Please sign in to comment.