Skip to content

Commit

Permalink
ARROW-8187: [R] Make test assertions robust to i18n
Browse files Browse the repository at this point in the history
Closes #6695 from nealrichardson/r-i18n-tests

Authored-by: Neal Richardson <neal.p.richardson@gmail.com>
Signed-off-by: Neal Richardson <neal.p.richardson@gmail.com>
  • Loading branch information
nealrichardson committed Mar 25, 2020
1 parent 1e1959c commit e001fe0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions r/R/dplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ filter.arrow_dplyr_query <- function(.data, ..., .preserve = FALSE) {
# else, for things not supported by Arrow return a "try-error",
# which we'll handle differently
msg <- conditionMessage(e)
# TODO: internationalization?
if (grepl("object '.*'.not.found", msg)) {
stop(e)
}
Expand Down
4 changes: 4 additions & 0 deletions r/tests/testthat/helper-expectation.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ expect_equivalent <- function(object, expected, ...) {
expect_type_equal <- function(object, expected, ...) {
expect_equal(object, expected, ..., label = object$ToString(), expected.label = expected$ToString())
}

expect_match_arg_error <- function(object, values=c()) {
expect_error(object, paste0("'arg' .*", paste(dQuote(values), collapse = ", ")))
}
2 changes: 1 addition & 1 deletion r/tests/testthat/test-compressed.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ context("Compressed.*Stream")

test_that("codec_is_available", {
expect_true(codec_is_available("uncompressed")) # Always true
expect_error(codec_is_available("sdfasdf"), "'arg' should be one of")
expect_match_arg_error(codec_is_available("sdfasdf"))
skip_if_not_available("gzip")
expect_true(codec_is_available("gzip"))
expect_true(codec_is_available("GZIP"))
Expand Down
8 changes: 4 additions & 4 deletions r/tests/testthat/test-data-type.R
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,14 @@ test_that("time type unit validation", {
expect_equal(time32(), time32(TimeUnit$MILLI))
expect_error(time32(4), '"unit" should be one of 1 or 0')
expect_error(time32(NULL), '"unit" should be one of "ms" or "s"')
expect_error(time32("years"), "'arg' should be one of")
expect_match_arg_error(time32("years"))

expect_equal(time64(TimeUnit$NANO), time64("n"))
expect_equal(time64(TimeUnit$MICRO), time64("us"))
expect_equal(time64(), time64(TimeUnit$NANO))
expect_error(time64(4), '"unit" should be one of 3 or 2')
expect_error(time64(NULL), '"unit" should be one of "ns" or "us"')
expect_error(time64("years"), "'arg' should be one of")
expect_match_arg_error(time64("years"))
})

test_that("timestamp type input validation", {
Expand Down Expand Up @@ -384,9 +384,9 @@ test_that("DictionaryType validation", {
})

test_that("decimal type and validation", {
expect_error(decimal(), 'argument "precision" is missing, with no default')
expect_error(decimal())
expect_error(decimal("four"), '"precision" must be an integer')
expect_error(decimal(4), 'argument "scale" is missing, with no default')
expect_error(decimal(4))
expect_error(decimal(4, "two"), '"scale" must be an integer')
expect_error(decimal(NA, 2), '"precision" must be an integer')
expect_error(decimal(0, 2), "Invalid: Decimal precision out of range: 0")
Expand Down
1 change: 1 addition & 0 deletions r/tests/testthat/test-dplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ test_that("filter environment scope", {
})

test_that("Filtering on a column that doesn't exist errors correctly", {
skip("Error handling in filter() needs to be internationalized")
expect_error(
batch %>% filter(not_a_col == 42) %>% collect(),
"object 'not_a_col' not found"
Expand Down

0 comments on commit e001fe0

Please sign in to comment.