Last active
October 5, 2017 19:24
-
-
Save cderv/341dc2c97d5dafb5cce3d24dfb65180c to your computer and use it in GitHub Desktop.
TidyEvalution with testthat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(testthat) | |
library(lubridate) | |
base <- as.POSIXct("2009-08-03 12:01:59.23", tz = "UTC") | |
expect_floor_equal <- function(unit, time) { | |
unit <- rlang::enquo(unit) | |
time <- rlang::enquo(time) | |
as_time <- function(x) as.POSIXct(x, tz = "UTC") | |
rlang::expr(expect_equal(floor_date(base, rlang::UQE(unit)), as_time(rlang::UQE(time)))) | |
# expect_equal(floor_date(base, rlang::UQ(unit)), as_time(rlang::UQ(time))) | |
} | |
expect_floor_equal("year", "2009-01-01 00:00:00") | |
expect_floor_equal("year", "2008-01-01 00:00:00") | |
####################################### | |
context("Download_ressources") | |
# Create temporary folder | |
dest_dir <- tempfile() | |
dir.create(dest_dir) | |
on.exit(unlink(dest_dir, recursive = T), add = T) | |
# Create asset dir | |
dest_dir_asset <- file.path(dest_dir, "asset") | |
dir.create(dest_dir_asset, recursive = T) | |
# Change working dir | |
oldwd <- setwd(dest_dir) | |
on.exit(setwd(oldwd), add = T) | |
expect_copied <- function(fun, filename) { | |
fun <- rlang::enquo(fun) | |
filename <- rlang::enquo(filename) | |
eval(rlang::expr(expect_true(rlang::UQE(fun)()))) | |
eval(expect_true(file.exists(rlang::UQE(filename)))) | |
eval(rlang::expr(expect_true(rlang::UQE(fun)(copy_to = dest_dir_asset)))) | |
eval(expect_true(file.exists(file.path(dest_dir_asset, rlang::UQE(filename))))) | |
} | |
test_that("logo is downloaded", { | |
expect_copied(getLogo, "img.png") | |
}) | |
test_that("SlideCSS is downloaded", { | |
expect_copied(getSlidesCSS, "styles_slides.css") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment