Skip to content

Commit

Permalink
Merge branch 'cansavvy/test-framework' into cansavvy/reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
cansavvy committed Jun 26, 2024
2 parents 090394d + ec4cb38 commit ee27a10
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 4 deletions.
1 change: 0 additions & 1 deletion .github/.gitignore

This file was deleted.

6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: ottrpal
Title: Companion Tools for Open-Source Tools for Training Resources (OTTR)
Version: 1.2.1
Version: 1.3.0
Authors@R: c(
person("Candace", "Savonen", , c("cansav09@gmail.com","csavonen@fredhutch.org"), role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-6331-7070")),
Expand Down Expand Up @@ -37,10 +37,11 @@ Imports:
rvest,
stringr,
xml2,
quarto,
yaml
Suggests:
remotes,
testthat,
testthat (>= 3.0.0),
tibble,
utils
VignetteBuilder:
Expand All @@ -49,3 +50,4 @@ ByteCompile: true
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.1
Config/testthat/edition: 3
2 changes: 1 addition & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ download_ottr_template <- function(dir = "inst/extdata", type = "rmd") {

url <- switch(type,
rmd = "https://github.com/jhudsl/OTTR_Template/archive/refs/heads/main.zip",
quarto = "https://github.com/fhdsl/ottr/archive/refs/heads/main.zip",
quarto = "https://github.com/fhdsl/OTTR_Quarto/archive/refs/heads/main.zip",
rmd_website = "https://github.com/jhudsl/OTTR_Template_Website/archive/refs/heads/main.zip",
quarto_website = "https://github.com/fhdsl/OTTR_Quarto_Website/archive/refs/heads/main.zip"
)
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(ottrpal)

test_check("ottrpal")
28 changes: 28 additions & 0 deletions tests/testthat/test-quarto_leanpub_prep.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
test_that("Tocless render for Quarto", {

dir <- download_ottr_template(dir = "inst/extdata", type = "quarto")

# render_without_toc()

# TODO: This should be functionalized and incorporated into the package
# curl -o make_screenshots.R https://raw.githubusercontent.com/jhudsl/ottr-reports/main/scripts/make_screenshots.R
# chapt_urls=$(Rscript --vanilla make_screenshots.R \
# --git_pat ${{ secrets.GH_PAT }} \
# --repo $GITHUB_REPOSITORY \
# --output_dir resources/chapt_screen_images)
unlink(dir, recursive = TRUE)
})


test_that("Create Leanpub IFrames for Quarto", {
# ottrpal::bookdown_to_embed_leanpub(
# render = FALSE, \
# chapt_img_key = 'resources/chapt_screen_images/chapter_urls.tsv', \
# make_book_txt = as.logical('${{needs.yaml-check.outputs.make_book_txt}}'), \
# quiz_dir = NULL)

# ottrpal::bookdown_to_embed_leanpub(
# render = FALSE, \
# chapt_img_key = 'resources/chapt_screen_images/chapter_urls.tsv', \
# make_book_txt = as.logical('${{needs.yaml-check.outputs.make_book_txt}}'))
})
23 changes: 23 additions & 0 deletions tests/testthat/test-quizzes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
test_that("Quiz checks", {
# Using good quiz md example

quiz_path <- good_quiz_path()
good_quiz <- readLines(quiz_path)
good_quiz_specs <- parse_quiz(good_quiz)
good_quiz_checks <- check_all_questions(good_quiz_specs)

# Using bad quiz md example

bad_quiz <- readLines(bad_quiz_path())
bad_quiz_specs <- parse_quiz(bad_quiz)
bad_quiz_checks <- check_all_questions(bad_quiz_specs)

## Make a temporary quiz directory
quiz_dir <- dirname(good_quiz_path())

## Now check the quizzes in that directory
all_quiz_results <- check_quizzes(quiz_dir = quiz_dir)

# Need to download OTTR course for testing
# ottrpal::check_quizzes(quiz_dir = file.path(root_dir, "quizzes"), write_report = TRUE, verbose = TRUE)
})
36 changes: 36 additions & 0 deletions tests/testthat/test-rendering.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
test_that("Rmd Rendering", {
dir <- download_ottr_template(dir = ".", type = "rmd")

bookdown::render_book("OTTR_Template-main")
unlink(dir)
})

test_that("Quarto Rendering", {
dir <- download_ottr_template(dir = ".", type = "quarto")

quarto::quarto_render(dir)
quarto::quarto_render(dir,
metadata = list(sidebar = F, toc = F),
quarto_args = c("--output-dir", "docs/no_toc/")
)
unlink(dir)
})

test_that("Rmd Website Rendering", {
dir <- download_ottr_template(dir = ".", type = "rmd_website")

rmarkdown::clean_site(dir, preview = FALSE)

rmarkdown::render_site(dir)

unlink(dir)
})


test_that("Quarto Website Rendering", {
dir <- download_ottr_template(dir = ".", type = "quarto_website")

quarto::quarto_render(dir)

unlink(dir)
})
33 changes: 33 additions & 0 deletions tests/testthat/test-rmd_leanpub_prep.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

test_that("Tocless render for Rmd", {
# render_without_toc()
dir <- download_ottr_template(dir = ".", type = "rmd")

# TODO: This should be functionalized and incorporated into the package
# curl -o make_screenshots.R https://raw.githubusercontent.com/jhudsl/ottr-reports/main/scripts/make_screenshots.R
# chapt_urls=$(Rscript --vanilla make_screenshots.R \
# --git_pat ${{ secrets.GH_PAT }} \
# --repo $GITHUB_REPOSITORY \
# --output_dir resources/chapt_screen_images)

unlink("dir", recursive = TRUE)
})


test_that("Create Leanpub IFrames for Rmd", {

dir <- download_ottr_template(dir = ".", type = "rmd")

# ottrpal::bookdown_to_embed_leanpub(
# render = FALSE, \
# chapt_img_key = 'resources/chapt_screen_images/chapter_urls.tsv', \
# make_book_txt = as.logical('${{needs.yaml-check.outputs.make_book_txt}}'), \
# quiz_dir = NULL)

# ottrpal::bookdown_to_embed_leanpub(
# render = FALSE, \
# chapt_img_key = 'resources/chapt_screen_images/chapter_urls.tsv', \
# make_book_txt = as.logical('${{needs.yaml-check.outputs.make_book_txt}}'))

unlink(dir, recursive = TRUE)
})

0 comments on commit ee27a10

Please sign in to comment.