|
1 | 1 | # Collection of functions and data pre-processing to help with testing
|
2 | 2 |
|
3 |
| -# Utility function to manually test local snapshots ---------------------------- |
4 |
| -skip_if_not_local_testing <- function(min_pandoc_version = "2", check_html = FALSE) { |
5 |
| - skip_on_cran() # When doing manual testing, it should be always skipped on CRAN |
6 |
| - local_edition(3, .env = parent.frame()) # Set the local_edition at 3 |
7 |
| - skip_if_not_installed("doconv") |
8 |
| - skip_if_not(doconv::msoffice_available()) |
9 |
| - if (!is.null(min_pandoc_version)) { # Can be turned off with NULL |
10 |
| - skip_if_not(rmarkdown::pandoc_version() >= numeric_version(min_pandoc_version)) |
11 |
| - } |
12 |
| - if (isTRUE(check_html)) { |
13 |
| - skip_if_not_installed("webshot2") |
14 |
| - } |
15 |
| - invisible(TRUE) |
16 |
| -} |
17 |
| - |
18 |
| - |
19 | 3 | # xml related functions --------------------------------------------------------
|
20 | 4 | get_docx_xml <- function(x) {
|
21 | 5 | if (inherits(x, "flextable")) {
|
@@ -82,3 +66,34 @@ render_rmd <- function(file, rmd_format) {
|
82 | 66 | )
|
83 | 67 | sucess
|
84 | 68 | }
|
| 69 | + |
| 70 | +# Utility function to manually test local snapshots ---------------------------- |
| 71 | +skip_if_not_local_testing <- function(min_pandoc_version = "2", check_html = FALSE) { |
| 72 | + skip_on_cran() # When doing manual testing, it should be always skipped on CRAN |
| 73 | + local_edition(3, .env = parent.frame()) # Set the local_edition at 3 |
| 74 | + skip_if_not_installed("doconv") |
| 75 | + skip_if_not(doconv::msoffice_available()) |
| 76 | + if (!is.null(min_pandoc_version)) { # Can be turned off with NULL |
| 77 | + skip_if_not(rmarkdown::pandoc_version() >= numeric_version(min_pandoc_version)) |
| 78 | + } |
| 79 | + if (isTRUE(check_html)) { |
| 80 | + skip_if_not_installed("webshot2") |
| 81 | + } |
| 82 | + invisible(TRUE) |
| 83 | +} |
| 84 | + |
| 85 | +# Getting snapshots in the _snaps folder for local testing if conditions are met |
| 86 | +test_that("setting up manual testing with msoffice", { |
| 87 | + skip_if_not_local_testing(check_html = TRUE) |
| 88 | + |
| 89 | + # Folder where the snapshots are stored |
| 90 | + folder_to_copy <- system.file("snapshots_for_manual_tests", package = "flextable") |
| 91 | + |
| 92 | + # Get the path to the tests/testthat directory |
| 93 | + path_to_testthat <- system.file("tests", "testthat", package = "flextable") |
| 94 | + |
| 95 | + # Construct the path to the _snaps folder |
| 96 | + path_to_snaps <- file.path(path_to_testthat, "_snaps") |
| 97 | + |
| 98 | + file.copy(folder_to_copy, path_to_snaps, recursive = TRUE, overwrite = TRUE) |
| 99 | +}) |
0 commit comments