From 471b4756785e5166173df0c61598c6b52f86c880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:07:59 +0100 Subject: [PATCH] adds some missing prefixes on test_that --- tests/testthat/test-Archiver.R | 6 +-- tests/testthat/test-DownloadReportModule.R | 2 +- tests/testthat/test-Reporter.R | 48 +++++++++++----------- tests/testthat/test-addCardModule.R | 6 +-- tests/testthat/test-utils.R | 2 +- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tests/testthat/test-Archiver.R b/tests/testthat/test-Archiver.R index 013ba53e..aeee4498 100644 --- a/tests/testthat/test-Archiver.R +++ b/tests/testthat/test-Archiver.R @@ -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) }) @@ -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) }) diff --git a/tests/testthat/test-DownloadReportModule.R b/tests/testthat/test-DownloadReportModule.R index 89a274ee..5c343b30 100644 --- a/tests/testthat/test-DownloadReportModule.R +++ b/tests/testthat/test-DownloadReportModule.R @@ -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))) diff --git a/tests/testthat/test-Reporter.R b/tests/testthat/test-Reporter.R index 6a5f6781..d3b90a62 100644 --- a/tests/testthat/test-Reporter.R +++ b/tests/testthat/test-Reporter.R @@ -28,11 +28,11 @@ 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() @@ -40,14 +40,14 @@ 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", { @@ -97,7 +97,7 @@ 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() @@ -105,23 +105,23 @@ 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") @@ -129,18 +129,18 @@ 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()) ) @@ -148,7 +148,7 @@ testthat::test_that("to_jsondir and from_jsondir could be used to save and retri 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() @@ -156,23 +156,23 @@ 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") @@ -180,16 +180,16 @@ 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()) }) diff --git a/tests/testthat/test-addCardModule.R b/tests/testthat/test-addCardModule.R index 8153b225..4f6c3176 100644 --- a/tests/testthat/test-addCardModule.R +++ b/tests/testthat/test-addCardModule.R @@ -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)) } ) @@ -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)) } ) @@ -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)) } ) }) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index b2c47f7b..a21b8a34 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -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", {