-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f257f4b
commit 7a35d91
Showing
7 changed files
with
173 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"ignoredFiles": [ | ||
"/tests/testthat/_snaps/*", | ||
"/tests/testthat/*", | ||
"/man/figures/lifecycle*", | ||
"inst/*" | ||
], | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Test offline | ||
|
||
Code | ||
dm <- resmush_file(test_png) | ||
Message | ||
! Offline | ||
|
||
--- | ||
|
||
Code | ||
dm[, -1] | ||
Output | ||
dest_img src_size dest_size compress_ratio notes | ||
1 NA NA NA NA Offline | ||
|
||
# Test not provided file | ||
|
||
Code | ||
dm[, -1] | ||
Output | ||
dest_img src_size dest_size compress_ratio notes | ||
1 NA NA NA NA local file does not exists | ||
|
||
# Not valid file | ||
|
||
Code | ||
dm[, -c(1, 2)] | ||
Output | ||
src_size dest_size compress_ratio | ||
1 21 bytes NA NA | ||
notes | ||
1 403: Unauthorized extension. Allowed are : JPG, PNG, GIF, BMP, TIFF, WEBP | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,121 @@ | ||
test_that("multiplication works", { | ||
expect_equal(2 * 2, 4) | ||
test_that("Test offline", { | ||
skip_on_cran() | ||
test_png <- load_inst_to_temp("example.png") | ||
expect_true(file.exists(test_png)) | ||
|
||
# Options for testing | ||
ops <- options() | ||
options(resmush_test_offline = TRUE) | ||
|
||
expect_true("resmush_test_offline" %in% names(options())) | ||
|
||
expect_snapshot(dm <- resmush_file(test_png)) | ||
|
||
expect_s3_class(dm, "data.frame") | ||
expect_snapshot(dm[, -1]) | ||
|
||
expect_equal(dm$src_img, test_png) | ||
|
||
# Reset ops | ||
options(resmush_test_offline = NULL) | ||
expect_false("resmush_test_offline" %in% names(options())) | ||
}) | ||
|
||
test_that("Test not provided file", { | ||
skip_on_cran() | ||
skip_if_offline() | ||
|
||
# tempfile | ||
fl <- tempfile() | ||
|
||
expect_false(file.exists(fl)) | ||
|
||
expect_message( | ||
dm <- resmush_file(fl), | ||
"not found on disk" | ||
) | ||
|
||
expect_s3_class(dm, "data.frame") | ||
expect_snapshot(dm[, -1]) | ||
|
||
expect_equal(dm$src_img, fl) | ||
}) | ||
|
||
test_that("Not valid file", { | ||
skip_on_cran() | ||
skip_if_offline() | ||
|
||
# tempfile | ||
fl <- tempfile(, fileext = "txt") | ||
|
||
writeLines("testing a fake file", con = fl) | ||
expect_true(file.exists(fl)) | ||
|
||
expect_message( | ||
dm <- resmush_file(fl), | ||
"API Error" | ||
) | ||
|
||
expect_s3_class(dm, "data.frame") | ||
expect_snapshot(dm[, -c(1, 2)]) | ||
expect_false(is.na(dm$src_img)) | ||
expect_equal(dm$src_img, fl) | ||
}) | ||
|
||
test_that("Test default opts with png", { | ||
skip_on_cran() | ||
skip_if_offline() | ||
test_png <- load_inst_to_temp("example.png") | ||
expect_true(file.exists(test_png)) | ||
|
||
expect_silent(dm <- resmush_file(test_png)) | ||
|
||
expect_s3_class(dm, "data.frame") | ||
expect_false(any(is.na(dm))) | ||
expect_equal(dm$src_img, test_png) | ||
expect_equal(dm$dest_img, test_png) | ||
|
||
ratio <- as.double(gsub("%", "", dm$compress_ratio)) | ||
expect_lt(ratio, 100) | ||
}) | ||
|
||
|
||
test_that("Test opts with png", { | ||
skip_on_cran() | ||
skip_if_offline() | ||
test_png <- load_inst_to_temp("example.png") | ||
expect_true(file.exists(test_png)) | ||
outf <- tempfile(fileext = ".png") | ||
expect_false(file.exists(outf)) | ||
expect_message( | ||
dm <- resmush_file(test_png, | ||
outf, | ||
verbose = TRUE | ||
), | ||
"optimized:" | ||
) | ||
|
||
expect_true(file.exists(outf)) | ||
expect_s3_class(dm, "data.frame") | ||
expect_false(any(is.na(dm))) | ||
expect_equal(dm$src_img, test_png) | ||
expect_equal(dm$dest_img, outf) | ||
|
||
ins <- file.size(test_png) | ||
outs <- file.size(outf) | ||
expect_lt(outs, ins) | ||
|
||
# Check units | ||
unts <- make_object_size(ins) | ||
anobj <- object.size(unts) | ||
expect_s3_class(unts, class(unts)) | ||
fmrted <- format(unts, "auto") | ||
|
||
expect_identical(dm$src_size, fmrted) | ||
}) | ||
|
||
test_that("Test qlty par with jpg", { | ||
skip_on_cran() | ||
skip_if_offline() | ||
skip("TODO: Finish tests") | ||
}) |