From c5e9a7b008618598e920f08d35fff52b62c01071 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Tue, 16 May 2023 14:59:12 -0700 Subject: [PATCH] update get_syllabus test; add ben Note: I switched the warning test to use a snapshot because I was running into something similar to https://github.com/r-lib/testthat/issues/1646 --- DESCRIPTION | 11 ++++--- NEWS.md | 5 ++++ tests/testthat/_snaps/get_syllabus.md | 14 +++++++++ tests/testthat/test-get_syllabus.R | 42 +++++++++++++++++++-------- 4 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 tests/testthat/_snaps/get_syllabus.md diff --git a/DESCRIPTION b/DESCRIPTION index 284a89ad4..ae3c26e98 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,18 +7,21 @@ Authors@R: c( role = c("aut", "cre"), email = "zkamvar@carpentries.org", comment = c(ORCID = "0000-0003-1458-7108")), - person(given = "François", - family = "Michonneau", - role = c("ctb"), - email = "francois@carpentries.org"), 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 = "tobyhodges@carpentries.org"), + person(given = "François", + family = "Michonneau", + role = c("ctb"), + email = "francois@carpentries.org"), person()) Description: We provide tools to build a Carpentries-themed lesson repository into an accessible standalone static website. These include local tools and diff --git a/NEWS.md b/NEWS.md index 61a229db7..ac930abb4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/tests/testthat/_snaps/get_syllabus.md b/tests/testthat/_snaps/get_syllabus.md new file mode 100644 index 000000000..5691637fb --- /dev/null +++ b/tests/testthat/_snaps/get_syllabus.md @@ -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. + diff --git a/tests/testthat/test-get_syllabus.R b/tests/testthat/test-get_syllabus.R index 12722dfa9..1de01c42a 100644 --- a/tests/testthat/test-get_syllabus.R +++ b/tests/testthat/test-get_syllabus.R @@ -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), "", "", "")) })