Skip to content

Commit

Permalink
update get_syllabus test; add ben
Browse files Browse the repository at this point in the history
Note: I switched the warning test to use a snapshot because I was
running into something similar to r-lib/testthat#1646
  • Loading branch information
zkamvar committed May 16, 2023
1 parent e628a09 commit c5e9a7b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
11 changes: 7 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ Authors@R: c(
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0003-1458-7108")),
person(given = "François",
family = "Michonneau",
role = c("ctb"),
email = "[email protected]"),
person(given = "Julien",
family = "Colomb",
role = c("ctb"),
comment = c(ORCID = "0000-0002-3127-5520")),
person(given = "Benjamin",
family = "Companjen",
role = c("ctb")),
person(given = "Toby",
family = "Hodges",
role = c("ctb"),
email = "[email protected]"),
person(given = "François",
family = "Michonneau",
role = c("ctb"),
email = "[email protected]"),
person())
Description: We provide tools to build a Carpentries-themed lesson repository
into an accessible standalone static website. These include local tools and
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# sandpaper 0.11.17 (unreleased)

## BUG FIX

* Break timing is now included in the overall schedule. (reported: @karenword,
#437; fixed: @bencomp, #455).

## TEST SUITE

* An upstream feature in {renv}, forcing it to be silent when testing caused
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/_snaps/get_syllabus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# episodes missing question blocks and timings do not throw error

Code
res <- get_syllabus(tmp, questions = TRUE)
Condition
Warning:
No section called 'questions'
Warning:
No section called 'questions'
Warning:
There are missing timings from 1 episode.
* 'draft.md'
i The default value of 5 minutes will be used for teaching and exercises.

42 changes: 30 additions & 12 deletions tests/testthat/test-get_syllabus.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,39 @@ test_that("syllabus will update with new files", {

test_that("episodes missing question blocks and timings do not throw error", {

# preamble: create two empty episodes, one in draft with n timings, and one
# with timings, but no break.
writeLines(
"---\ntitle: Break\nteaching: XX\n---\n\nThis should not error.",
"---\ntitle: Draft\nteaching: XX\n---\n\nThis should not error.",
fs::path(tmp, "episodes", "draft.md")
)
writeLines(
"---\ntitle: Break\nteaching: 0\nexercises: 0\nbreak: 15\n---\n\nHave a nice cold coffee.",
fs::path(tmp, "episodes", "break.md")
)

set_episodes(tmp, c(get_episodes(tmp), "break.md"), write = TRUE)

(res <- get_syllabus(tmp, questions = TRUE)) %>%
expect_warning("No section called 'questions'") %>%
expect_warning("missing timings from 1 episode")
expect_equal(nrow(res), 4)
expect_equal(res$timings, c("00h 00m", "00h 12m", "00h 24m", "00h 34m"))
expect_equal(res$percents, c("0", "35", "71", "100"))
expect_equal(res$episode, c("introduction", "postroduction", "Break", "Finish"))
expect_equal(fs::path_file(res$path), c("introduction.html", "postroduction.html", "break.html", ""))
expect_equal(res$questions, c(rep(q, 2), "", ""))
# "introduction", "postroduction", "draft", "break"
expected <- c(get_episodes(tmp), "draft.md", "break.md")
set_episodes(tmp, expected, write = TRUE)

expect_snapshot(res <- get_syllabus(tmp, questions = TRUE))

# output is a table with five rows
expect_equal(nrow(res), 5)

expect_equal(res$timings,
c("00h 00m", "00h 12m", "00h 24m", "00h 34m", "00h 49m"))
expect_equal(res$percents,
c("0", "24", "49", "69", "100"))
expect_equal(res$episode,
c("introduction", "postroduction", "Draft", "Break", "Finish"))

# path is the path to the the HTML file from the root of the site
expect_equal(fs::path_file(res$path),
c(fs::path_ext_set(expected, "html"), ""))

# q is defined at the top of this file and files with no questions are blank
expect_equal(res$questions,
c(rep(q, 2), "", "", ""))

})

0 comments on commit c5e9a7b

Please sign in to comment.