Skip to content

Commit

Permalink
tests: upgrade to testthat version 3
Browse files Browse the repository at this point in the history
and use `usethis::use_tidy_description()`

See #623
  • Loading branch information
davidgohel committed May 4, 2024
1 parent 846631d commit 2739119
Show file tree
Hide file tree
Showing 27 changed files with 69 additions and 107 deletions.
71 changes: 40 additions & 31 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
Package: flextable
Type: Package
Package: flextable
Title: Functions for Tabular Reporting
Version: 0.9.6.010
Version: 0.9.6.011
Authors@R: c(
person("David", "Gohel", role = c("aut", "cre"),
email = "[email protected]"),
person(given = "ArData", role = "cph"),
person("David", "Gohel", , "[email protected]", role = c("aut", "cre")),
person("ArData", role = "cph"),
person("Clementine", "Jager", role = "ctb"),
person("Panagiotis", "Skintzos", role = "aut", email = "[email protected]"),
person("Panagiotis", "Skintzos", , "[email protected]", role = "aut"),
person("Quentin", "Fazilleau", role = "ctb"),
person("Maxim", "Nazarov", role = "ctb", comment = "rmarkdown for docx output"),
person("Maxim", "Nazarov", role = "ctb",
comment = "rmarkdown for docx output"),
person("Titouan", "Robert", role = "ctb"),
person("Michael", "Barrowman", role = "ctb", comment = "inline footnotes"),
person("Atsushi", "Yasumoto", role = "ctb", comment = "support for bookdown cross reference"),
person("Paul", "Julian", role = "ctb", comment = "support for gam objects"),
person("Sean", "Browning", role = "ctb", comment = "work on footnote positioning system"),
person("Rémi", "Thériault", role = "ctb", comment = c(ORCID = "0000-0003-4315-6788", ctb = "theme_apa")),
person("Samuel", "Jobert", role = "ctb", comment = "work on pagination"),
person("Michael", "Barrowman", role = "ctb",
comment = "inline footnotes"),
person("Atsushi", "Yasumoto", role = "ctb",
comment = "support for bookdown cross reference"),
person("Paul", "Julian", role = "ctb",
comment = "support for gam objects"),
person("Sean", "Browning", role = "ctb",
comment = "work on footnote positioning system"),
person("Rémi", "Thériault", role = "ctb",
comment = c(ORCID = "0000-0003-4315-6788", ctb = "theme_apa")),
person("Samuel", "Jobert", role = "ctb",
comment = "work on pagination"),
person("Keith", "Newman", role = "ctb")
)
)
Description: Use a grammar for creating and customizing pretty tables.
The following formats are supported: 'HTML', 'PDF', 'RTF',
'Microsoft Word', 'Microsoft PowerPoint' and R 'Grid Graphics'.
'R Markdown', 'Quarto' and the package 'officer' can be used to produce
the result files. The syntax is the same for the user regardless of
the type of output to be produced. A set of functions allows the
creation, definition of cell arrangement, addition of headers or
footers, formatting and definition of cell content with text and
or images. The package also offers a set of high-level functions
that allow tabular reporting of statistical models and the
creation of complex cross tabulations.
The following formats are supported: 'HTML', 'PDF', 'RTF', 'Microsoft
Word', 'Microsoft PowerPoint' and R 'Grid Graphics'. 'R Markdown',
'Quarto' and the package 'officer' can be used to produce the result
files. The syntax is the same for the user regardless of the type of
output to be produced. A set of functions allows the creation,
definition of cell arrangement, addition of headers or footers,
formatting and definition of cell content with text and or images. The
package also offers a set of high-level functions that allow tabular
reporting of statistical models and the creation of complex cross
tabulations.
License: GPL-3
URL: https://ardata-fr.github.io/flextable-book/,
https://davidgohel.github.io/flextable/
BugReports: https://github.com/davidgohel/flextable/issues
Imports:
data.table (>= 1.13.0),
gdtools (>= 0.3.6),
Expand All @@ -47,14 +56,12 @@ Imports:
utils,
uuid (>= 0.1-4),
xml2
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
Suggests:
bookdown (>= 0.34),
broom,
broom.mixed,
cluster,
chromote,
cluster,
commonmark,
doconv (>= 0.3.0),
equatags,
Expand All @@ -69,11 +76,13 @@ Suggests:
scales,
svglite,
tables (>= 0.9.17),
testthat (>= 2.1.0),
testthat (>= 3.0.0),
webshot2,
withr,
xtable
VignetteBuilder:
knitr
Config/testthat/edition: 3
Encoding: UTF-8
URL: https://ardata-fr.github.io/flextable-book/, https://davidgohel.github.io/flextable/
BugReports: https://github.com/davidgohel/flextable/issues
VignetteBuilder: knitr
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
1 change: 1 addition & 0 deletions man/flextable-package.Rd

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

2 changes: 0 additions & 2 deletions tests/testthat/test-as_flextable.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check as_flextable")

test_that("data.frame", {
dummy_df <- data.frame(
A = rep(letters[1:3], each = 2),
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-borders.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check borders rendering")

init_flextable_defaults()
snap_folder_test_file <- "borders"
defer_cleaning_snapshot_directory(snap_folder_test_file)
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-captions-rmd.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check captions")

init_flextable_defaults()

rmd_file_0 <- "rmd/captions.Rmd"
Expand Down
8 changes: 3 additions & 5 deletions tests/testthat/test-cell_content.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check cell content")

test_that("void works as expected", {
expect_error(void(12, part = "all"))

Expand Down Expand Up @@ -42,7 +40,7 @@ test_that("flextable_defaults values for cell content", {
"1 116 933", "dark", "01/01/2011 09:09:09", "Adrien Dupuy", "29 02 2028",
"2", "53,58175", "167,7560", "1 009 038", "dark", "01/01/2011 09:09:09"
)
expect_equivalent(object = information_data_chunk(ft)$txt, expected)
expect_equal(object = information_data_chunk(ft)$txt, expected, ignore_attr = TRUE)

init_flextable_defaults()
})
Expand Down Expand Up @@ -79,7 +77,7 @@ test_that("colformat_* functions", {
"-26/02/2011-", "-c-", "-b-", "-12,566-", "-4-", "-NON-", "-01/01/2011 090905-",
"-27/02/2011-"
)
expect_equivalent(object = information_data_chunk(ft)$txt, expected)
expect_equal(object = information_data_chunk(ft)$txt, expected, ignore_attr = TRUE)

ft <- colformat_num(x = ft, big.mark = "", decimal.mark = ".", prefix = "+", suffix = "+")
expected <-
Expand All @@ -91,7 +89,7 @@ test_that("colformat_* functions", {
"-26/02/2011-", "-c-", "-b-", "+12.566371+", "+4+", "-NON-",
"-01/01/2011 090905-", "-27/02/2011-"
)
expect_equivalent(object = information_data_chunk(ft)$txt, expected)
expect_equal(object = information_data_chunk(ft)$txt, expected, ignore_attr = TRUE)
})


Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-df_printer.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("df_printer and utilities")

test_that("use_model_printer and use_df_printer works", {
rmd_file <- tempfile(fileext = ".Rmd")
file.copy("rmd/use-printer.Rmd", rmd_file)
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-dimensions.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check widths and heights")

test_that("dimensions are valid", {
dummy_df <- data.frame(my_col = rep(letters[1:3], each = 2), stringsAsFactors = FALSE)
ft <- flextable(dummy_df)
Expand Down
3 changes: 0 additions & 3 deletions tests/testthat/test-errors.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
context("check errors")


test_that("rows selections", {
dummy_df <- data.frame(
my_col = rep(letters[1:3], each = 2),
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-footers.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check footers")

test_that("add_footer", {
data_ref <- structure(
list(
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-footnote.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check footnotes")

ft <- flextable(iris[1:5, ])
ft <- footnote(
x = ft, i = 1:3, j = 1:3,
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-gen_grob.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check grid grob")

gdtools::register_liberationsans()

init_flextable_defaults()
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-headers.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check headers")

test_that("set_header_labels", {
col_keys <- c(
"Species",
Expand Down
18 changes: 8 additions & 10 deletions tests/testthat/test-images.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check images")

data <- iris[c(1:3, 51:53, 101:104), ]
col_keys <- c("Species", "sep_1", "Sepal.Length", "Sepal.Width", "sep_2", "Petal.Length", "Petal.Width")
img.file <- file.path(R.home("doc"), "html", "logo.jpg")
Expand Down Expand Up @@ -107,16 +105,16 @@ test_that("multiple images", {
}

zz <- gen_grob(ft)
expect_is(zz$children$cell_1_1$children$contents$ftgrobs[[1]], "rastergrob")
expect_is(zz$children$cell_2_1$children$contents$ftgrobs[[1]], "rastergrob")
expect_is(zz$children$cell_3_1$children$contents$ftgrobs[[1]], "rastergrob")
expect_s3_class(zz$children$cell_1_1$children$contents$ftgrobs[[1]], "rastergrob")
expect_s3_class(zz$children$cell_2_1$children$contents$ftgrobs[[1]], "rastergrob")
expect_s3_class(zz$children$cell_3_1$children$contents$ftgrobs[[1]], "rastergrob")

ft <- flextable(df)
ft <- colformat_image(ft, j = "plot", width = 300 / 72, height = 300 / 72)
zz <- gen_grob(ft)
expect_is(zz$children$cell_1_1$children$contents$ftgrobs[[1]], "text")
expect_is(zz$children$cell_2_1$children$contents$ftgrobs[[1]], "rastergrob")
expect_is(zz$children$cell_3_1$children$contents$ftgrobs[[1]], "rastergrob")
expect_s3_class(zz$children$cell_1_1$children$contents$ftgrobs[[1]], "text")
expect_s3_class(zz$children$cell_2_1$children$contents$ftgrobs[[1]], "rastergrob")
expect_s3_class(zz$children$cell_3_1$children$contents$ftgrobs[[1]], "rastergrob")
})

test_that("minibar", {
Expand All @@ -131,14 +129,14 @@ test_that("minibar", {
part = "body"
)
minibar1 <- flextable::information_data_chunk(ft)$img_data[[2]]
expect_is(minibar1, "raster")
expect_s3_class(minibar1, "raster")
expect_equal(nrow(minibar1), 1)
expect_equal(ncol(minibar1), 36)
expect_equal(minibar1[1:3], rep("#FF0000", 3))
expect_equal(minibar1[4:36], rep("#FFFF00", 33))

minibar2 <- flextable::information_data_chunk(ft)$img_data[[3]]
expect_is(minibar2, "raster")
expect_s3_class(minibar2, "raster")
expect_equal(nrow(minibar2), 1)
expect_equal(ncol(minibar2), 36)
expect_equal(minibar2[1:7], rep("#FF0000", 7))
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-keep_next.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check keep with next")

init_flextable_defaults()

iris_sum <- summarizor(iris, by = "Species")
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-latex.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("latex table structure")

test_that("white spaces are protected", {
ft <- flextable(data.frame(x = ""))
ft <- delete_part(ft, part = "header")
Expand Down
8 changes: 3 additions & 5 deletions tests/testthat/test-link.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check hyperlink")

data <- data.frame(
code = c("X01", "X02"),
name = c("X Number 1", "X Number 2"),
Expand All @@ -24,7 +22,7 @@ test_that("URL are preserved in docx", {
rid <- xml_attr(xml_find_all(body, "//w:hyperlink"), "id")
rels <- doc$doc_obj$rel_df()
urls <- rels[rels$id %in% rid, "target"]
expect_equivalent(urls, sprintf(url_base, data$code))
expect_equal(urls, sprintf(url_base, data$code), ignore_attr = TRUE)
})

test_that("URL are preserved in pptx", {
Expand All @@ -35,7 +33,7 @@ test_that("URL are preserved in pptx", {
rid <- xml_attr(xml_find_all(xml_slide, "//a:hlinkClick"), "id")
rels <- doc$slide$get_slide(1)$rel_df()
urls <- rels[rels$id %in% rid, "target"]
expect_equivalent(urls, sprintf(url_base, data$code))
expect_equal(urls, sprintf(url_base, data$code), ignore_attr = TRUE)
})

test_that("URL are preserved in html", {
Expand All @@ -46,5 +44,5 @@ test_that("URL are preserved in html", {
str_ <- gsub("</div></template(.*)", "", str_)
doc <- read_html(str_)
urls <- xml_attr(xml_find_all(doc, "//a"), "href")
expect_equivalent(urls, sprintf(url_base, data$code))
expect_equal(urls, sprintf(url_base, data$code), ignore_attr = TRUE)
})
2 changes: 0 additions & 2 deletions tests/testthat/test-md-captions.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check markdown captions")

init_flextable_defaults()
skip_if_not_local_testing(check_html = TRUE)
snap_folder_test_file <- "md-captions"
Expand Down
10 changes: 4 additions & 6 deletions tests/testthat/test-merge.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
context("check merge operations")

test_that("identical values within columns are merged", {
dummy_df <- data.frame(values = rep(letters[1:3], each = 2), stringsAsFactors = FALSE)
ft <- flextable(dummy_df)
ft <- merge_v(x = ft, j = "values")
expect_equivalent(ft$body$spans$columns[, 1], rep(c(2, 0), 3))
expect_equal(ft$body$spans$columns[, 1], rep(c(2, 0), 3), ignore_attr = TRUE)
})

test_that("identical values within rows are merged", {
Expand All @@ -16,7 +14,7 @@ test_that("identical values within rows are merged", {
ft <- flextable(dummy_df)
ft <- merge_h(x = ft)
ref <- matrix(c(rep(2, 26), rep(0, 26)), ncol = 2)
expect_equivalent(ft$body$spans$rows, ref)
expect_equal(ft$body$spans$rows, ref, ignore_attr = TRUE)
})


Expand All @@ -29,9 +27,9 @@ test_that("span at", {
ft <- flextable(dummy_df)
ft <- merge_at(x = ft, i = 1:4, j = 1:2)
ref <- matrix(c(rep(2, 4), rep(1, 22), rep(0, 4), rep(1, 22)), ncol = 2)
expect_equivalent(ft$body$spans$rows, ref)
expect_equal(ft$body$spans$rows, ref, ignore_attr = TRUE)
ref <- matrix(c(4, rep(0, 3), rep(1, 22), 4, rep(0, 3), rep(1, 22)), ncol = 2)
expect_equivalent(ft$body$spans$columns, ref)
expect_equal(ft$body$spans$columns, ref, ignore_attr = TRUE)
})


Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-misc.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check various minor things")

ft <- flextable(iris)

test_that("print as log", {
Expand Down
17 changes: 9 additions & 8 deletions tests/testthat/test-new-rows.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check dim and new rows")

test_that("nrow_part or ncol_keys checks", {
expect_error(nrow_part(12))
expect_error(ncol_keys(12))
Expand Down Expand Up @@ -121,9 +119,10 @@ test_that("add part rows", {
5, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0)
)
expect_true(all(spans$colspan %in% 1))
expect_equivalent(
expect_equal(
colSums(is.na(ft_1$header$dataset)),
rep(0L, ncol(mtcars))
rep(0L, ncol(mtcars)),
ignore_attr = TRUE
)

new_body_sel <- x[x$.part %in% "body" &
Expand All @@ -143,9 +142,10 @@ test_that("add part rows", {
c(5, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0)
)
expect_true(all(spans$colspan %in% 1))
expect_equivalent(
expect_equal(
colSums(is.na(ft_1$body$dataset)),
rep(1L, ncol(mtcars))
rep(1L, ncol(mtcars)),
ignore_attr = TRUE
)

new_footer_sel <- x[x$.part %in% "footer" &
Expand All @@ -162,9 +162,10 @@ test_that("add part rows", {
c(3, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0)
)
expect_true(all(spans$colspan %in% 1))
expect_equivalent(
expect_equal(
colSums(is.na(ft_1$footer$dataset)),
rep(0L, ncol(mtcars))
rep(0L, ncol(mtcars)),
ignore_attr = TRUE
)

})
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-padding.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("check paddings")

test_that("padding overwrite all paddings", {
ft <- flextable(data.frame(a = c("", ""), stringsAsFactors = FALSE))
ft <- padding(ft, padding = 5)
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-pptx-tables.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("ppt table structure")

test_that("row height is valid", {
ft <- flextable(head(iris))
pptx_file <- "test.pptx"
Expand Down
Loading

0 comments on commit 2739119

Please sign in to comment.