From 5e01a472e1b014a98880b0db1306ecdb2079e37e Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 24 Apr 2024 10:24:25 -0400 Subject: [PATCH] Add a test for results and include --- .../python-knitr-engine/knitr-results-hide.md | 5 +++++ tests/testthat/resources/knitr-results-hide.Rmd | 16 ++++++++++++++++ tests/testthat/test-python-knitr-engine.R | 17 +++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 tests/testthat/_snaps/python-knitr-engine/knitr-results-hide.md create mode 100644 tests/testthat/resources/knitr-results-hide.Rmd diff --git a/tests/testthat/_snaps/python-knitr-engine/knitr-results-hide.md b/tests/testthat/_snaps/python-knitr-engine/knitr-results-hide.md new file mode 100644 index 000000000..9f78a3d57 --- /dev/null +++ b/tests/testthat/_snaps/python-knitr-engine/knitr-results-hide.md @@ -0,0 +1,5 @@ + class MyClass: + def _repr_html_(self): + return "

uh-oh

" + + MyClass() diff --git a/tests/testthat/resources/knitr-results-hide.Rmd b/tests/testthat/resources/knitr-results-hide.Rmd new file mode 100644 index 000000000..050e40e98 --- /dev/null +++ b/tests/testthat/resources/knitr-results-hide.Rmd @@ -0,0 +1,16 @@ +--- +title: "Hide and include" +output: md_document +--- + +```{python, results = 'hide'} +class MyClass: + def _repr_html_(self): + return "

uh-oh

" + +MyClass() +``` + +```{python, include = FALSE} +1 + 1 +``` diff --git a/tests/testthat/test-python-knitr-engine.R b/tests/testthat/test-python-knitr-engine.R index bd7300a1a..d972b4f2e 100644 --- a/tests/testthat/test-python-knitr-engine.R +++ b/tests/testthat/test-python-knitr-engine.R @@ -86,6 +86,23 @@ test_that("knitr 'warning=FALSE' option", { }) +test_that("knitr results='hide' and include = FALSE options", { + + skip_on_cran() + skip_if_not_installed("rmarkdown") + + local_edition(3) # needed for expect_snapshot_file() + + owd <- setwd(test_path("resources")) + rmarkdown::render("knitr-results-hide.Rmd", quiet = TRUE) + setwd(owd) + + rendered <- test_path("resources", "knitr-results-hide.md") + + expect_snapshot_file(rendered) + +}) + test_that("Output streams are remaped when kniting", { skip_on_cran()