Skip to content

Commit

Permalink
430 use expect_no_error in tests instead of expect_error(, NA) (#240
Browse files Browse the repository at this point in the history
)

Part of insightsengineering/coredev-tasks#430

---------

Signed-off-by: Marcin <[email protected]>
Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: André Veríssimo <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2024
1 parent 7562421 commit 57a8db2
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 107 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Suggests:
lattice (>= 0.18-4),
png,
rtables (>= 0.5.1),
testthat (>= 3.0.4),
testthat (>= 3.1.5),
tinytex
VignetteBuilder:
knitr
Expand All @@ -53,4 +53,4 @@ Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.0
5 changes: 5 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
Forkers
Hoffmann
Prebuilt
README
Repo
catched
cloneable
funder
hallal
mahmoud
repo
rmarkdown
roche
26 changes: 26 additions & 0 deletions man/teal.reporter.Rd

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

14 changes: 7 additions & 7 deletions tests/testthat/test-Archiver.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ reporter <- Reporter$new()
reporter$append_cards(list(card1, card2))

testthat::test_that("intialize Archiver", {
expect_error(Archiver$new(), NA)
testthat::expect_no_error(Archiver$new())
})

testthat::test_that("new returns an object of type Archiver", {
Expand All @@ -34,7 +34,7 @@ testthat::test_that("Archiver errors with the abstract methods", {
})

testthat::test_that("intialize FileArchiver", {
testthat::expect_error(FileArchiver$new(), NA)
testthat::expect_no_error(FileArchiver$new())
})

testthat::test_that("FileArchiver creates a temp directory when initialized", {
Expand All @@ -58,7 +58,7 @@ testthat::test_that("FileArchiver dectructor removes the temp dir", {
})

testthat::test_that("intialize JSONArchiver", {
testthat::expect_error(JSONArchiver$new(), NA)
testthat::expect_no_error(JSONArchiver$new())
})

testthat::test_that("JSONArchiver creates a temp directory when initialized", {
Expand All @@ -79,20 +79,20 @@ testthat::test_that("JSONArchiver dectructor removes the temp dir", {
archiver <- JSONArchiver$new()

testthat::test_that("JSONArchiver write a reporter", {
testthat::expect_error(archiver$write(reporter), NA)
testthat::expect_no_error(archiver$write(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
4 changes: 2 additions & 2 deletions tests/testthat/test-ContentBlock.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testthat::test_that("ContentBlock object can be created", {
testthat::expect_error(ContentBlock$new(), regexp = NA)
testthat::expect_no_error(ContentBlock$new())
})

testthat::test_that("new returns an object of type ContentBlock", {
Expand All @@ -8,7 +8,7 @@ testthat::test_that("new returns an object of type ContentBlock", {

testthat::test_that("set_content accepts a character object", {
block <- ContentBlock$new()
testthat::expect_error(block$set_content("test"), regexp = NA)
testthat::expect_no_error(block$set_content("test"))
})

testthat::test_that("set_content asserts the argument is character", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-DownloadReportModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ knitr_args <- list()
temp_dir <- tempdir()

testthat::test_that("report_render_and_compress - valid arguments", {
testthat::expect_error(report_render_and_compress(reporter, input, knitr_args, temp_dir), NA)
testthat::expect_no_error(report_render_and_compress(reporter, input, knitr_args, temp_dir))
})

testthat::test_that("report_render_and_compress - invalid arguments", {
Expand All @@ -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
2 changes: 1 addition & 1 deletion tests/testthat/test-FileBlock.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testthat::test_that("FileBlock object can be created", {
testthat::expect_error(FileBlock$new(), regexp = NA)
testthat::expect_no_error(FileBlock$new())
})

testthat::test_that("new returns an object of type FileBlock", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-NewpageBlock.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testthat::test_that("NewpageBlock object can be created", {
testthat::expect_error(NewpageBlock$new(), regexp = NA)
testthat::expect_no_error(NewpageBlock$new())
})

testthat::test_that("new returns an object of type NewpageBlock", {
Expand All @@ -8,5 +8,5 @@ testthat::test_that("new returns an object of type NewpageBlock", {

testthat::test_that("set_content accepts a string", {
block <- NewpageBlock$new()
testthat::expect_error(block$get_content(), regexp = NA)
testthat::expect_no_error(block$get_content())
})
35 changes: 14 additions & 21 deletions tests/testthat/test-PictureBlock.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Constructor
testthat::test_that("PictureBlock object can be created", {
testthat::expect_error(
PictureBlock$new(),
regexp = NA
testthat::expect_no_error(
PictureBlock$new()
)
})

Expand All @@ -13,9 +12,8 @@ testthat::test_that("new returns an object of type PictureBlock", {
# set_content
testthat::test_that("set_content accepts a plot object", {
block <- PictureBlock$new()
testthat::expect_error(
block$set_content(ggplot2::ggplot(iris)),
regexp = NA
testthat::expect_no_error(
block$set_content(ggplot2::ggplot(iris))
)
})

Expand Down Expand Up @@ -61,9 +59,8 @@ testthat::test_that("get_content returns character(0) on a newly initialized Pic

# set_title
testthat::test_that("set_title accepts a string", {
testthat::expect_error(
PictureBlock$new()$set_title("Test"),
NA
testthat::expect_no_error(
PictureBlock$new()$set_title("Test")
)
})

Expand Down Expand Up @@ -101,9 +98,8 @@ testthat::test_that("get_title returns the set title", {

# set_dim
testthat::test_that("set_dim accepts an array of two numeric values", {
testthat::expect_error(
PictureBlock$new()$set_dim(c(0, 0)),
regexp = NA
testthat::expect_no_error(
PictureBlock$new()$set_dim(c(0, 0))
)
})

Expand Down Expand Up @@ -132,23 +128,20 @@ testthat::test_that("set_content throws if the content is not of the supported t
})

testthat::test_that("set_content accepts a `ggplot` object", {
testthat::expect_error(
PictureBlock$new()$set_content(ggplot2::ggplot(iris)),
regexp = NA
testthat::expect_no_error(
PictureBlock$new()$set_content(ggplot2::ggplot(iris))
)
})

testthat::test_that("set_content accepts a `grob` object", {
testthat::expect_error(
PictureBlock$new()$set_content(ggplot2::ggplotGrob(ggplot2::ggplot(iris))),
regexp = NA
testthat::expect_no_error(
PictureBlock$new()$set_content(ggplot2::ggplotGrob(ggplot2::ggplot(iris)))
)
})

testthat::test_that("set_content accepts a `trellis` object", {
testthat::expect_error(
PictureBlock$new()$set_content(lattice::bwplot(1)),
regexp = NA
testthat::expect_no_error(
PictureBlock$new()$set_content(lattice::bwplot(1))
)
})

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-RcodeBlock.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testthat::test_that("RcodeBlock object can be created", {
testthat::expect_error(RcodeBlock$new(), regexp = NA)
testthat::expect_no_error(RcodeBlock$new())
})

testthat::test_that("new returns an object of type RcodeBlock", {
Expand All @@ -8,7 +8,7 @@ testthat::test_that("new returns an object of type RcodeBlock", {

testthat::test_that("set_content accepts a string", {
block <- RcodeBlock$new()
testthat::expect_error(block$set_content("test"), regexp = NA)
testthat::expect_no_error(block$set_content("test"))
})

testthat::test_that("set_content asserts the argument is a string", {
Expand Down Expand Up @@ -37,7 +37,7 @@ testthat::test_that("set_params accepts one of the styles returned by get_availa
for (param in RcodeBlock$new()$get_available_params()) {
input <- list()
input[[param]] <- NULL
testthat::expect_error(RcodeBlock$new()$set_params(input), regexp = NA)
testthat::expect_no_error(RcodeBlock$new()$set_params(input))
}
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Renderer.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testthat::test_that("Renderer object can be created", {
testthat::expect_error(Renderer$new(), regexp = NA)
testthat::expect_no_error(Renderer$new())
})

testthat::test_that("new returns an object of type Renderer", {
Expand Down
33 changes: 14 additions & 19 deletions tests/testthat/test-ReportCard.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
testthat::test_that("ReportCard object can be created", {
testthat::expect_error(ReportCard$new(), regexp = NA)
testthat::expect_no_error(ReportCard$new())
})

testthat::test_that("new returns an object of type ReportCard", {
testthat::expect_true(inherits(ReportCard$new(), "ReportCard"))
})

testthat::test_that("append_text accepts a character", {
testthat::expect_error(ReportCard$new()$append_text("test"), regexp = NA)
testthat::expect_no_error(ReportCard$new()$append_text("test"))
})

testthat::test_that("append_text returns self", {
Expand All @@ -16,9 +16,8 @@ testthat::test_that("append_text returns self", {
})

testthat::test_that("append_table accepts a data.frame", {
testthat::expect_error(
ReportCard$new()$append_table(iris),
regexp = NA
testthat::expect_no_error(
ReportCard$new()$append_table(iris)
)
})

Expand All @@ -33,31 +32,27 @@ testthat::test_that("append_plot returns self", {
})

testthat::test_that("append_plot accepts a ggplot", {
testthat::expect_error(
ReportCard$new()$append_plot(ggplot2::ggplot(iris)),
regexp = NA
testthat::expect_no_error(
ReportCard$new()$append_plot(ggplot2::ggplot(iris))
)
})

testthat::test_that("append_plot accepts a ggplot with a dim", {
testthat::expect_error(
ReportCard$new()$append_plot(ggplot2::ggplot(iris), c(1000L, 100L)),
regexp = NA
testthat::expect_no_error(
ReportCard$new()$append_plot(ggplot2::ggplot(iris), c(1000L, 100L))
)
})

testthat::test_that("append_rcode accepts a character", {
testthat::expect_error(
ReportCard$new()$append_rcode("x <- 2"),
regexp = NA
testthat::expect_no_error(
ReportCard$new()$append_rcode("x <- 2")
)
})


testthat::test_that("append_rcode returns self", {
testthat::expect_error(
ReportCard$new()$append_rcode("x <- 2"),
regexp = NA
testthat::expect_no_error(
ReportCard$new()$append_rcode("x <- 2")
)
})

Expand Down Expand Up @@ -85,8 +80,8 @@ testthat::test_that("append_metadata returns an object of type ReportCard", {
})

testthat::test_that("append_metadata accepts a character key and a character or list value", {
testthat::expect_error(ReportCard$new()$append_metadata("key1", "value1"), regexp = NA)
testthat::expect_error(ReportCard$new()$append_metadata("key1", list("value1")), regexp = NA)
testthat::expect_no_error(ReportCard$new()$append_metadata("key1", "value1"))
testthat::expect_no_error(ReportCard$new()$append_metadata("key1", list("value1")))
})

testthat::test_that("append_metadata throws error if key is not character", {
Expand Down
Loading

0 comments on commit 57a8db2

Please sign in to comment.