From df7b11150fff04a73c5bd1d56d132d4a50e2a323 Mon Sep 17 00:00:00 2001 From: Claudia Beleites Date: Sat, 31 Jul 2021 16:13:26 +0200 Subject: [PATCH 1/2] Fix issue 26: explicitly set unit test language ...for unit tests depending on English error messages or warnings. --- DESCRIPTION | 3 ++- R/DEPRECATED-read.mat.Witec.R | 4 +++- R/DEPRECATED-read.spc.R | 3 ++- R/DEPRECATED-read.spe.R | 3 ++- R/DEPRECATED-read.txt.Renishaw.R | 9 +++++++-- R/DEPRECATED-read.txt.Shimadzu.R | 4 +++- R/plot.R | 4 +++- 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 02fb8e59..e1a3e565 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -48,7 +48,8 @@ Imports: rlang, testthat, utils, - xml2 + xml2, + withr Suggests: baseline, bookdown, diff --git a/R/DEPRECATED-read.mat.Witec.R b/R/DEPRECATED-read.mat.Witec.R index 7eec132e..dc609ff8 100644 --- a/R/DEPRECATED-read.mat.Witec.R +++ b/R/DEPRECATED-read.mat.Witec.R @@ -57,7 +57,9 @@ hySpc.testthat::test(read.mat.Witec) <- function() { test_that( "deprecated", expect_warning( - expect_error(read.mat.Witec(file = ""), "Can only read a MAT file"), + expect_error( + with_envvar(list (LANGUAGE = "en_US"), read.mat.Witec(file = "")), + "Can only read a MAT file"), "deprecated|supports" ) ) diff --git a/R/DEPRECATED-read.spc.R b/R/DEPRECATED-read.spc.R index 2600832a..96ad2170 100644 --- a/R/DEPRECATED-read.spc.R +++ b/R/DEPRECATED-read.spc.R @@ -855,7 +855,8 @@ hySpc.testthat::test(read.spc) <- function() { test_that( "deprecated", expect_warning( - expect_error(read.spc(file = ""), "can only read"), + expect_error(with_envvar(list (LANGUAGE = "en_US"), read.spc(file = "")), + "can only read"), "deprecated" ) ) diff --git a/R/DEPRECATED-read.spe.R b/R/DEPRECATED-read.spe.R index 20ca1d0f..e6b6fff7 100644 --- a/R/DEPRECATED-read.spe.R +++ b/R/DEPRECATED-read.spe.R @@ -361,7 +361,8 @@ hySpc.testthat::test(read.spe) <- function() { test_that( "deprecated", expect_warning( - expect_error(read.spe(filename = ""), "can only read"), + expect_error(with_envvar(list (LANGUAGE = "en_US"), read.spe(filename = "")), + "can only read"), "deprecated" ) ) diff --git a/R/DEPRECATED-read.txt.Renishaw.R b/R/DEPRECATED-read.txt.Renishaw.R index 3746e004..33256eb2 100644 --- a/R/DEPRECATED-read.txt.Renishaw.R +++ b/R/DEPRECATED-read.txt.Renishaw.R @@ -172,7 +172,9 @@ hySpc.testthat::test(read.txt.Renishaw) <- function() { test_that( "deprecated", expect_warning( - expect_error(read.txt.Renishaw(file = ""), "cannot open"), + expect_error( + with_envvar(list (LANGUAGE = "en_US"), read.txt.Renishaw(file = "")), + "cannot open"), "deprecated" ) ) @@ -199,7 +201,10 @@ hySpc.testthat::test(read.zip.Renishaw) <- function() { test_that( "deprecated", expect_warning( - expect_error(read.zip.Renishaw(file = ""), "cannot open"), + expect_error( + with_envvar(list (LANGUAGE = "en_US"), + read.zip.Renishaw(file = "")), + "cannot open"), "deprecated" ) ) diff --git a/R/DEPRECATED-read.txt.Shimadzu.R b/R/DEPRECATED-read.txt.Shimadzu.R index 7559f405..5decc488 100644 --- a/R/DEPRECATED-read.txt.Shimadzu.R +++ b/R/DEPRECATED-read.txt.Shimadzu.R @@ -232,7 +232,9 @@ hySpc.testthat::test(read.txt.Shimadzu) <- function() { test_that( "deprecated", expect_warning( - expect_error(read.txt.Shimadzu(file = ""), "attempt to select"), + expect_error( + with_envvar(list (LANGUAGE = "en_US"), read.txt.Shimadzu(file = "")), + "attempt to select"), "deprecated" ) ) diff --git a/R/plot.R b/R/plot.R index 6bc2134a..2fc99171 100644 --- a/R/plot.R +++ b/R/plot.R @@ -156,6 +156,7 @@ setGeneric("plot") #' @concept plot generation #' #' @export +#' @importFrom withr with_envvar #' @examples #' #' plot(flu) @@ -199,7 +200,8 @@ hySpc.testthat::test(.plot) <- function() { expect_warning(plot(hy_spectra, "c"), "Intensity at first wavelengh only is used.") # Regular tests: errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - expect_error(plot(hy_spectra, "depth"), "object 'z' not found") + expect_error(with_envvar(list (LANGUAGE = "en_US"), plot(hy_spectra, "depth")), + "object 'z' not found") expect_error(plot(hy_spectra[0, ]), "No spectra.") expect_error(plot(hy_spectra, xoffset = "a"), "xoffset must be a numeric") expect_error(plot(hy_spectra, func = "a"), "func needs to be a function") From 2b101a31263732b566a4479fdf4e628b0e44ae26 Mon Sep 17 00:00:00 2001 From: Claudia Beleites Date: Sun, 1 Aug 2021 15:29:03 +0200 Subject: [PATCH 2/2] Style fixed unit tests --- R/DEPRECATED-read.mat.Witec.R | 5 +++-- R/DEPRECATED-read.spc.R | 6 ++++-- R/DEPRECATED-read.spe.R | 6 ++++-- R/DEPRECATED-read.txt.Renishaw.R | 14 +++++++++----- R/DEPRECATED-read.txt.Shimadzu.R | 5 +++-- R/plot.R | 6 ++++-- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/R/DEPRECATED-read.mat.Witec.R b/R/DEPRECATED-read.mat.Witec.R index dc609ff8..af1d2700 100644 --- a/R/DEPRECATED-read.mat.Witec.R +++ b/R/DEPRECATED-read.mat.Witec.R @@ -58,8 +58,9 @@ hySpc.testthat::test(read.mat.Witec) <- function() { "deprecated", expect_warning( expect_error( - with_envvar(list (LANGUAGE = "en_US"), read.mat.Witec(file = "")), - "Can only read a MAT file"), + with_envvar(list(LANGUAGE = "en_US"), read.mat.Witec(file = "")), + "Can only read a MAT file" + ), "deprecated|supports" ) ) diff --git a/R/DEPRECATED-read.spc.R b/R/DEPRECATED-read.spc.R index 96ad2170..9ed908ed 100644 --- a/R/DEPRECATED-read.spc.R +++ b/R/DEPRECATED-read.spc.R @@ -855,8 +855,10 @@ hySpc.testthat::test(read.spc) <- function() { test_that( "deprecated", expect_warning( - expect_error(with_envvar(list (LANGUAGE = "en_US"), read.spc(file = "")), - "can only read"), + expect_error( + with_envvar(list(LANGUAGE = "en_US"), read.spc(file = "")), + "can only read" + ), "deprecated" ) ) diff --git a/R/DEPRECATED-read.spe.R b/R/DEPRECATED-read.spe.R index e6b6fff7..e69286ed 100644 --- a/R/DEPRECATED-read.spe.R +++ b/R/DEPRECATED-read.spe.R @@ -361,8 +361,10 @@ hySpc.testthat::test(read.spe) <- function() { test_that( "deprecated", expect_warning( - expect_error(with_envvar(list (LANGUAGE = "en_US"), read.spe(filename = "")), - "can only read"), + expect_error( + with_envvar(list(LANGUAGE = "en_US"), read.spe(filename = "")), + "can only read" + ), "deprecated" ) ) diff --git a/R/DEPRECATED-read.txt.Renishaw.R b/R/DEPRECATED-read.txt.Renishaw.R index 33256eb2..e283e540 100644 --- a/R/DEPRECATED-read.txt.Renishaw.R +++ b/R/DEPRECATED-read.txt.Renishaw.R @@ -173,8 +173,9 @@ hySpc.testthat::test(read.txt.Renishaw) <- function() { "deprecated", expect_warning( expect_error( - with_envvar(list (LANGUAGE = "en_US"), read.txt.Renishaw(file = "")), - "cannot open"), + with_envvar(list(LANGUAGE = "en_US"), read.txt.Renishaw(file = "")), + "cannot open" + ), "deprecated" ) ) @@ -202,9 +203,12 @@ hySpc.testthat::test(read.zip.Renishaw) <- function() { "deprecated", expect_warning( expect_error( - with_envvar(list (LANGUAGE = "en_US"), - read.zip.Renishaw(file = "")), - "cannot open"), + with_envvar( + list(LANGUAGE = "en_US"), + read.zip.Renishaw(file = "") + ), + "cannot open" + ), "deprecated" ) ) diff --git a/R/DEPRECATED-read.txt.Shimadzu.R b/R/DEPRECATED-read.txt.Shimadzu.R index 5decc488..a611dd6c 100644 --- a/R/DEPRECATED-read.txt.Shimadzu.R +++ b/R/DEPRECATED-read.txt.Shimadzu.R @@ -233,8 +233,9 @@ hySpc.testthat::test(read.txt.Shimadzu) <- function() { "deprecated", expect_warning( expect_error( - with_envvar(list (LANGUAGE = "en_US"), read.txt.Shimadzu(file = "")), - "attempt to select"), + with_envvar(list(LANGUAGE = "en_US"), read.txt.Shimadzu(file = "")), + "attempt to select" + ), "deprecated" ) ) diff --git a/R/plot.R b/R/plot.R index 2fc99171..e036e2a4 100644 --- a/R/plot.R +++ b/R/plot.R @@ -200,8 +200,10 @@ hySpc.testthat::test(.plot) <- function() { expect_warning(plot(hy_spectra, "c"), "Intensity at first wavelengh only is used.") # Regular tests: errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - expect_error(with_envvar(list (LANGUAGE = "en_US"), plot(hy_spectra, "depth")), - "object 'z' not found") + expect_error( + with_envvar(list(LANGUAGE = "en_US"), plot(hy_spectra, "depth")), + "object 'z' not found" + ) expect_error(plot(hy_spectra[0, ]), "No spectra.") expect_error(plot(hy_spectra, xoffset = "a"), "xoffset must be a numeric") expect_error(plot(hy_spectra, func = "a"), "func needs to be a function")