From 1fdabe6248d288b2ee34dc32f6368154961b1441 Mon Sep 17 00:00:00 2001 From: elimillera Date: Wed, 26 Jan 2022 02:33:39 +0000 Subject: [PATCH 1/3] Updates to move to testthat version 3 and move to snapshot tests for warnings and errors. A couple additions of 'any_of' to silence some warnings that appear in a new version of rlang. --- DESCRIPTION | 1 + NEWS.md | 2 +- R/count.R | 4 +- R/nested.R | 4 +- cran-comments.md | 1 + tests/testthat/_snaps/column_headers.md | 40 +++++ tests/testthat/_snaps/count.md | 156 ++++++++++++++++++++ tests/testthat/_snaps/desc.md | 9 ++ tests/testthat/_snaps/format.md | 12 ++ tests/testthat/_snaps/functional.md | 8 + tests/testthat/_snaps/get_numeric.md | 48 ++++++ tests/testthat/_snaps/layer.md | 96 ++++++++++++ tests/testthat/_snaps/layering.md | 16 ++ tests/testthat/_snaps/pop_data.md | 12 ++ tests/testthat/_snaps/print.md | 171 ++++++++++++++++++++++ tests/testthat/_snaps/properties_layer.md | 28 ++++ tests/testthat/_snaps/riskdiff.md | 20 +++ tests/testthat/_snaps/shift.md | 9 ++ tests/testthat/_snaps/table.md | 4 + tests/testthat/_snaps/table_bindings.md | 44 ++++++ tests/testthat/test-assertions.R | 8 +- tests/testthat/test-column_headers.R | 25 ++-- tests/testthat/test-count.R | 99 +++++++------ tests/testthat/test-desc.R | 10 +- tests/testthat/test-format.R | 7 +- tests/testthat/test-functional.R | 2 +- tests/testthat/test-get_numeric.R | 31 ++-- tests/testthat/test-layer.R | 65 ++++---- tests/testthat/test-layering.R | 14 +- tests/testthat/test-opts.R | 1 - tests/testthat/test-pop_data.R | 6 +- tests/testthat/test-precision.R | 1 - tests/testthat/test-print.R | 16 +- tests/testthat/test-properties_layer.R | 20 ++- tests/testthat/test-riskdiff.R | 29 ++-- tests/testthat/test-shift.R | 2 +- tests/testthat/test-sort.R | 98 ++++++------- tests/testthat/test-table.R | 6 +- tests/testthat/test-table_bindings.R | 26 ++-- tests/testthat/test-utils.R | 17 +-- 40 files changed, 911 insertions(+), 257 deletions(-) create mode 100644 tests/testthat/_snaps/column_headers.md create mode 100644 tests/testthat/_snaps/count.md create mode 100644 tests/testthat/_snaps/desc.md create mode 100644 tests/testthat/_snaps/format.md create mode 100644 tests/testthat/_snaps/functional.md create mode 100644 tests/testthat/_snaps/get_numeric.md create mode 100644 tests/testthat/_snaps/layer.md create mode 100644 tests/testthat/_snaps/layering.md create mode 100644 tests/testthat/_snaps/pop_data.md create mode 100644 tests/testthat/_snaps/print.md create mode 100644 tests/testthat/_snaps/properties_layer.md create mode 100644 tests/testthat/_snaps/riskdiff.md create mode 100644 tests/testthat/_snaps/shift.md create mode 100644 tests/testthat/_snaps/table.md create mode 100644 tests/testthat/_snaps/table_bindings.md diff --git a/DESCRIPTION b/DESCRIPTION index 38589ab4..53a1f42f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -57,3 +57,4 @@ Suggests: VignetteBuilder: knitr RoxygenNote: 7.1.2 RdMacros: lifecycle +Config/testthat/edition: 3 diff --git a/NEWS.md b/NEWS.md index fb57542a..08287911 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# Tplyr 0.4.3.9000 (Development) +# Tplyr 0.4.4 - Added new functionality per issue #10. Adds 'Both' an option for sorting outer layers of nested count. diff --git a/R/count.R b/R/count.R index 3db806cb..2b4a8b76 100644 --- a/R/count.R +++ b/R/count.R @@ -245,7 +245,7 @@ filter_nested_inner_layer <- function(.group, target, outer_name, inner_name, in if(text_outer) { target_inner_values <- target %>% - select(inner_name) %>% + select(any_of(inner_name)) %>% unlist() %>% paste0(indentation, .) } else { @@ -253,7 +253,7 @@ filter_nested_inner_layer <- function(.group, target, outer_name, inner_name, in target_inner_values <- target %>% filter(!!sym(outer_name) == current_outer_value) %>% - select(inner_name) %>% + select(any_of(inner_name)) %>% unlist() %>% paste0(indentation, .) } diff --git a/R/nested.R b/R/nested.R index 8fa33c14..de15a640 100644 --- a/R/nested.R +++ b/R/nested.R @@ -82,7 +82,7 @@ filter_nested_inner_layer <- function(.group, target, outer_name, inner_name, in if(text_outer) { lvs <- levels(target[[inner_name]]) target_inner_values <- target %>% - select(inner_name) %>% + select(any_of(inner_name)) %>% unlist() %>% c(lvs) %>% unique() %>% @@ -93,7 +93,7 @@ filter_nested_inner_layer <- function(.group, target, outer_name, inner_name, in target_inner_values <- target %>% filter(!!sym(outer_name) == current_outer_value) %>% - select(inner_name) %>% + select(any_of(inner_name)) %>% unlist() %>% paste0(indentation, .) } diff --git a/cran-comments.md b/cran-comments.md index 9b460fd2..4ee9d510 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,5 +1,6 @@ ## Submission 0.4.4 * Functionality update for sorting nested count layers +* Updates for changes to rlang ## Test Environments diff --git a/tests/testthat/_snaps/column_headers.md b/tests/testthat/_snaps/column_headers.md new file mode 100644 index 00000000..c514a0d7 --- /dev/null +++ b/tests/testthat/_snaps/column_headers.md @@ -0,0 +1,40 @@ +# All columns must be character + + When binding headers, all columns must be character + +# Nested headers are not allowed + + Nested spanning headers are not yet supported + +# Header strings must have the same number of columns as the data frame + + Number of columns provided in header string does not match data + +--- + + Number of columns provided in header string does not match data + +--- + + Number of columns provided in header string does not match data + +--- + + Number of columns provided in header string does not match data + +--- + + Number of columns provided in header string does not match data + +--- + + Number of columns provided in header string does not match data + +# Unmatched spanner brackers + + Unmatched brackets for spanning headers + +# add_column_headers throws an error when you use a token and don't pass header_n + + You must pass a header_n if you are using replacement tokens + diff --git a/tests/testthat/_snaps/count.md b/tests/testthat/_snaps/count.md new file mode 100644 index 00000000..3bfc719f --- /dev/null +++ b/tests/testthat/_snaps/count.md @@ -0,0 +1,156 @@ +# Count layer clauses with invalid syntax give informative error + + group_count `where` condition `bad == code` is invalid. Filter error: + Error in `h()`: + ! Problem with `filter()` input `..1`. + i Input `..1` is `bad == code`. + x object 'bad' not found + + +# Total rows and missing counts are displayed correctly(0.1.5 Updates) + + structure(list(row_label1 = c("6", "8", "Missing", "Total"), + var1_3 = c(" 2 (13.3)", "12 (80.0)", " 1", " 15 [100.0]" + ), var1_4 = c(" 4 (33.3)", " 0 ( 0.0)", " 8", " 12 [100.0]" + ), var1_5 = c(" 1 (20.0)", " 2 (40.0)", " 2", " 5 [100.0]" + ), ord_layer_index = c(1L, 1L, 1L, 1L), ord_layer_1 = c(1, + 2, 3, 4)), row.names = c(NA, -4L), class = c("tbl_df", "tbl", + "data.frame")) + +--- + + structure(list(row_label1 = c("6", "8", "Missing", "Not Found", + "Total"), var1_3 = c(" 2 (13.3)", "12 (80.0)", " 1", " 0", " 15 [100.0]" + ), var1_4 = c(" 4 (33.3)", " 0 ( 0.0)", " 8", " 0", " 12 [100.0]" + ), var1_5 = c(" 1 (20.0)", " 2 (40.0)", " 2", " 0", " 5 [100.0]" + ), ord_layer_index = c(1L, 1L, 1L, 1L, 1L), ord_layer_1 = c(1, + 2, 3, 4, 5)), row.names = c(NA, -5L), class = c("tbl_df", "tbl", + "data.frame")) + +--- + + structure(list(row_label1 = c("0", "Missing", "Not Found", "Total" + ), var1_3 = c("15 (100.0)", " 0", " 0", " 15 [100.0]"), var1_4 = c(" 4 (33.3)", + " 8", " 0", " 12 [100.0]"), var1_5 = c(" 0 ( 0.0)", " 5", " 0", + " 5 [100.0]"), ord_layer_index = c(1L, 1L, 1L, 1L), ord_layer_1 = c(1, + 5689, 5690, 9999)), row.names = c(NA, -4L), class = c("tbl_df", + "tbl", "data.frame")) + +--- + + structure(list(row_label1 = c("6", "8", "Missing", "Not Found", + "Total"), var1_3 = c(" 2 (13.3)", "12 (80.0)", " 1", " 0", " 15 [100.0]" + ), var1_4 = c(" 4 (33.3)", " 0 ( 0.0)", " 8", " 0", " 12 [100.0]" + ), var1_5 = c(" 1 (20.0)", " 2 (40.0)", " 2", " 0", " 5 [100.0]" + ), ord_layer_index = c(1L, 1L, 1L, 1L, 1L), ord_layer_1 = c(4, + 0, 999, 1000, 9999)), row.names = c(NA, -5L), class = c("tbl_df", + "tbl", "data.frame")) + +--- + + structure(list(row_label1 = c("6", "8", "Missing", "Total"), + var1_3 = c(" 2 (13.3)", "12 (80.0)", " 1", " 15 [100.0]" + ), var1_4 = c(" 4 (33.3)", " 0 ( 0.0)", " 8", " 12 [100.0]" + ), var1_5 = c(" 1 (20.0)", " 2 (40.0)", " 2", " 5 [100.0]" + ), ord_layer_index = c(1L, 1L, 1L, 1L), ord_layer_1 = c(1, + 2, 3, 7862)), row.names = c(NA, -4L), class = c("tbl_df", + "tbl", "data.frame")) + +--- + + structure(list(row_label1 = c("0", "Missing", "Total"), var1_3 = c("15 (100.0)", + " 0", " 15 [100.0]"), var1_4 = c(" 4 (33.3)", " 8", " 12 [100.0]" + ), var1_5 = c(" 0 ( 0.0)", " 5", " 5 [100.0]"), ord_layer_index = c(1L, + 1L, 1L), ord_layer_1 = c(1, 3, -Inf)), row.names = c(NA, -3L), class = c("tbl_df", + "tbl", "data.frame")) + +--- + + structure(list(row_label1 = c("6", "8", "Missing", "Total"), + var1_3 = c(" 2 (13.3)", "12 (80.0)", " 1", " 15 [100.0]" + ), var1_4 = c(" 4 (33.3)", " 0 ( 0.0)", " 8", " 12 [100.0]" + ), var1_5 = c(" 1 (20.0)", " 2 (40.0)", " 2", " 5 [100.0]" + ), ord_layer_index = c(1L, 1L, 1L, 1L), ord_layer_1 = c(4, + 0, 8, -6795)), row.names = c(NA, -4L), class = c("tbl_df", + "tbl", "data.frame")) + +--- + + structure(list(row_label1 = c("6", "8", "NA", "Total"), var1_3 = c(" 2 (13.3)", + "12 (80.0)", " 1 ( 6.7)", "15 (100.0)"), var1_4 = c(" 4 (33.3)", + " 0 ( 0.0)", " 8 (66.7)", "12 (100.0)"), var1_5 = c(" 1 (20.0)", + " 2 (40.0)", " 2 (40.0)", " 5 (100.0)"), ord_layer_index = c(1L, + 1L, 1L, 1L), ord_layer_1 = c(1, 2, 3, 3)), row.names = c(NA, + -4L), class = c("tbl_df", "tbl", "data.frame")) + +--- + + structure(list(row_label1 = c("2", "3", "4", "6", "8", "Missing_" + ), var1_3 = c(" 0 ( 0.0)", " 0 ( 0.0)", " 0 ( 0.0)", " 2 (13.3)", + "12 (80.0)", " 1"), var1_4 = c(" 0 ( 0.0)", " 0 ( 0.0)", " 0 ( 0.0)", + " 4 (33.3)", " 0 ( 0.0)", " 8"), var1_5 = c(" 0 ( 0.0)", " 0 ( 0.0)", + " 0 ( 0.0)", " 1 (20.0)", " 2 (40.0)", " 2"), ord_layer_index = c(1L, + 1L, 1L, 1L, 1L, 1L), ord_layer_1 = c(1, 2, 3, 4, 5, 6)), row.names = c(NA, + -6L), class = c("tbl_df", "tbl", "data.frame")) + +# set_denom_where works as expected + + structure(list(row_label1 = c("4", "8"), var1_3 = c(" 1 ( 6.7)", + "12 (80.0)"), var1_4 = c(" 8 (66.7)", " 0 ( 0.0)"), var1_5 = c(" 2 (40.0)", + " 2 (40.0)"), ord_layer_index = c(1L, 1L), ord_layer_1 = c(1, + 3)), row.names = c(NA, -2L), class = c("tbl_df", "tbl", "data.frame" + )) + +--- + + structure(list(row_label1 = c("4", "8"), var1_3 = c(" 1 ( 7.1)", + "12 (85.7)"), var1_4 = c(" 8 (200.0)", " 0 ( 0.0)"), var1_5 = c(" 2 (66.7)", + " 2 (66.7)"), ord_layer_index = c(1L, 1L), ord_layer_1 = c(1, + 3)), row.names = c(NA, -2L), class = c("tbl_df", "tbl", "data.frame" + )) + +--- + + A `denom_where` has been set with a pop_data. The `denom_where` has been ignored.You should use `set_pop_where` instead of `set_denom_where`. + + +--- + + structure(list(row_label1 = c("4", "8"), var1_3 = c(" 1 ( 7.7)", + "12 (92.3)"), var1_4 = c(" 8 (100.0)", " 0 ( 0.0)"), var1_5 = c(" 2 (50.0)", + " 2 (50.0)"), ord_layer_index = c(1L, 1L), ord_layer_1 = c(1, + 3)), row.names = c(NA, -2L), class = c("tbl_df", "tbl", "data.frame" + )) + +# nested count layers can accecpt text values in the first variable + + Inner layers must be data driven variables + +# Variable names will be coersed into symbols + + The first target variable has been coerced into a symbol. You should pass variable names unquoted. + +--- + + The second target variable has been coerced into a symbol.You should pass variable names unquoted. + +# keep_levels works as expeceted + + group_count `where` condition `TRUE` is invalid. Filter error: + Error: level passed to `kept_levels` not found: 10 20 + + +--- + + group_count `where` condition `TRUE` is invalid. Filter error: + Error: level passed to `kept_levels` not found: nothere + + +# nested count layers handle `set_denoms_by` as expected + + You can not pass the second variable in `vars` as a denominator. + +# nested count layers will error out if second variable is bigger than the first + + The number of values of your second variable must be greater than the number of levels in your first variable + diff --git a/tests/testthat/_snaps/desc.md b/tests/testthat/_snaps/desc.md new file mode 100644 index 00000000..ffd5558a --- /dev/null +++ b/tests/testthat/_snaps/desc.md @@ -0,0 +1,9 @@ +# Desc layer clauses with invalid syntax give informative error + + group_desc `where` condition `bad == code` is invalid. Filter error: + Error in `h()`: + ! Problem with `filter()` input `..1`. + i Input `..1` is `bad == code`. + x object 'bad' not found + + diff --git a/tests/testthat/_snaps/format.md b/tests/testthat/_snaps/format.md new file mode 100644 index 00000000..fdb9f303 --- /dev/null +++ b/tests/testthat/_snaps/format.md @@ -0,0 +1,12 @@ +# Format string must be character + + Argument `format_string` must be character. Instead a class of "numeric" was passed. + +# Error is thrown when format doesn't match variables + + In `f_str` 2 formats were entered in the format string xx.x xx.xbut 1 variables were assigned. + +--- + + In `f_str` 1 formats were entered in the format string xx.xbut 2 variables were assigned. + diff --git a/tests/testthat/_snaps/functional.md b/tests/testthat/_snaps/functional.md new file mode 100644 index 00000000..0b6afe18 --- /dev/null +++ b/tests/testthat/_snaps/functional.md @@ -0,0 +1,8 @@ +# all test tables can be built without errors or warnings + + Problem with `mutate()` column `col_i`. + i `col_i = fct_expand(...)`. + x object 'col_i' not found + Caused by error: + ! object 'col_i' not found + diff --git a/tests/testthat/_snaps/get_numeric.md b/tests/testthat/_snaps/get_numeric.md new file mode 100644 index 00000000..ff71d6b5 --- /dev/null +++ b/tests/testthat/_snaps/get_numeric.md @@ -0,0 +1,48 @@ +# Error handling - numeric + + If `where` is provided, a single `layer` value must be specified + +--- + + If `where` is provided, a single `layer` value must be specified + +--- + + Layer(s) blah do(es) not exist + +--- + + Layer(s) blah do(es) not exist + +--- + + Provided layer index is out of range + +--- + + Provided layer index is out of range + +# Error handling - statistic + + If `where` is provided, `layer_name` and `statistic` must be specified + +--- + + If `where` is provided, `layer_name` and `statistic` must be specified + +--- + + Layer(s) blah do(es) not exist + +--- + + Layer(s) am, blah do(es) not exist + +--- + + Provided layer index is out of range + +--- + + Provided layer index is out of range + diff --git a/tests/testthat/_snaps/layer.md b/tests/testthat/_snaps/layer.md new file mode 100644 index 00000000..e65803ac --- /dev/null +++ b/tests/testthat/_snaps/layer.md @@ -0,0 +1,96 @@ +# `tplyr_layer` errors when no arguments provided + + The `parent` argument must be provided. + +# type field can only contain one of 'count', 'desc', or 'shift' + + `type` must be one of "count", "desc", or "shift" + +--- + + `type` must be one of "count", "desc", or "shift" + +--- + + `type` must be one of "count", "desc", or "shift" + +--- + + `type` must be one of "count", "desc", or "shift" + +# Parent must be a `tplyr_table`, `tplyr_layer`, or `tplyr_subgroup_layer` + + Must provide `tplyr_table`, `tplyr_layer`, or `tplyr_subgroup_layer` object from the `tplyr` package. + +# `by` must me a string, a variable name, or multiple variables submitted using `dplyr::vars` + + Invalid input to `by`. Submit either a string, a variable name, or multiple variable names using `dplyr::vars`. + +--- + + Invalid input to `~list("a", "b")`. Submit either a string, a variable name, or multiple variable names using `dplyr::vars`. + +--- + + Invalid input to `~c("a", "b")`. Submit either a string, a variable name, or multiple variable names using `dplyr::vars`. + +--- + + Invalid input to `by`. Submit either a string, a variable name, or multiple variable names using `dplyr::vars`. + +--- + + Invalid input to `by`. Submit either a string, a variable name, or multiple variable names using `dplyr::vars`. + +# `target_var` must me a string, a variable name, or multiple variables submitted using `dplyr::vars` + + Invalid input to `target_var`. Submit either a string, a variable name, or multiple variable names using `dplyr::vars`. + +--- + + Invalid input to `~list("a", "b")`. Submit either a string, a variable name, or multiple variable names using `dplyr::vars`. + +--- + + Invalid input to `~c("a", "b")`. Submit either a string, a variable name, or multiple variable names using `dplyr::vars`. + +--- + + Invalid input to `target_var`. Submit either a string, a variable name, or multiple variable names using `dplyr::vars`. + +--- + + Invalid input to `target_var`. Submit either a string, a variable name, or multiple variable names using `dplyr::vars`. + +# `target_var` must exist in target dataset + + `target_var` variable `BadVar` does not exist in target dataset + +--- + + `target_var` variable `BadVar` does not exist in target dataset + +# `by` varaibles must exist in the target dataset + + `by` variable `BadVars` does not exist in target dataset + +--- + + `by` variable `BadVars` does not exist in target dataset + +# `where` must be programming logic (quosure of class 'call') + + The `where` parameter must contain subsetting logic (enter without quotes) + +# Desc layers only accept numeric variables + + Target variable `supp` is not numeric. Target variables must be numeric for desc layers. + +--- + + Target variable `supp` is not numeric. Target variables must be numeric for desc layers. + +--- + + Target variable `supp` is not numeric. Target variables must be numeric for desc layers. + diff --git a/tests/testthat/_snaps/layering.md b/tests/testthat/_snaps/layering.md new file mode 100644 index 00000000..4ce7816b --- /dev/null +++ b/tests/testthat/_snaps/layering.md @@ -0,0 +1,16 @@ +# All parameters must be provided + + `parent` parameter must be provided + +--- + + `layer` parameter must be provided + +# Parent argument is a valid class (pass through to `tplyr_layer`) + + Must provide `tplyr_table`, `tplyr_layer`, or `tplyr_subgroup_layer` object from the `tplyr` package. + +# Only `Tplyr` methods are allowed in the `layer` parameter + + Functions called within `add_layer` must be part of `Tplyr` + diff --git a/tests/testthat/_snaps/pop_data.md b/tests/testthat/_snaps/pop_data.md new file mode 100644 index 00000000..ed89efa6 --- /dev/null +++ b/tests/testthat/_snaps/pop_data.md @@ -0,0 +1,12 @@ +# add_treat_grps errors function properly + + Treatment group arguments must have names + +--- + + Treatment groups can only be added to `tplyr_table` objects + +# add_total_group errors function properly + + Argument `group_name` must be character. Instead a class of "numeric" was passed. + diff --git a/tests/testthat/_snaps/print.md b/tests/testthat/_snaps/print.md new file mode 100644 index 00000000..23e0895e --- /dev/null +++ b/tests/testthat/_snaps/print.md @@ -0,0 +1,171 @@ +# tplyr_table is printed as expected + + *** tplyr_table *** + Target (data.frame): + Name: mtcars + Rows: 32 + Columns: 11 + treat_var variable (quosure) + gear + header_n: header groups + treat_grps groupings (list) + Total + Table Columns (cols): + vs + where: TRUE + Number of layer(s): 1 + layer_output: 0 + +--- + + *** target data.frame *** + Target Name: mtcars + 'data.frame': 6 obs. of 11 variables: + $ mpg : num 21 21 22.8 21.4 18.7 18.1 + $ cyl : num 6 6 4 6 8 6 + $ disp: num 160 160 108 258 360 225 + $ hp : num 110 110 93 110 175 105 + $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 + $ wt : num 2.62 2.88 2.32 3.21 3.44 ... + $ qsec: num 16.5 17 18.6 19.4 17 ... + $ vs : num 0 0 1 1 0 1 + $ am : num 1 1 1 0 0 0 + $ gear: num 4 4 4 3 3 3 + $ carb: num 4 4 1 1 2 1 + *** treat_var*** + gear + *** pop_data data.frame *** + 'data.frame': 32 obs. of 11 variables: + $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... + $ cyl : num 6 6 4 6 8 6 8 4 4 6 ... + $ disp: num 160 160 108 258 360 ... + $ hp : num 110 110 93 110 175 105 245 62 95 123 ... + $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ... + $ wt : num 2.62 2.88 2.32 3.21 3.44 ... + $ qsec: num 16.5 17 18.6 19.4 17 ... + $ vs : num 0 0 1 1 0 1 0 1 1 1 ... + $ am : num 1 1 1 0 0 0 0 0 0 0 ... + $ gear: num 4 4 4 3 3 3 3 4 4 4 ... + $ carb: num 4 4 1 1 2 1 4 2 2 4 ... + *** pop_treat_var *** + gear + *** treat_grps *** + Total: + 4 3 5 + +--- + + *** tplyr_table *** + Target (data.frame): + Name: mtcars + Rows: 32 + Columns: 11 + treat_var variable (quosure) + gear + header_n: 8 header groups + treat_grps groupings (list) + Total + Table Columns (cols): + vs + where: TRUE + Number of layer(s): 1 + layer_output: 0 + +--- + + *** target data.frame *** + Target Name: mtcars + 'data.frame': 6 obs. of 11 variables: + $ mpg : num 21 21 22.8 21.4 18.7 18.1 + $ cyl : num 6 6 4 6 8 6 + $ disp: num 160 160 108 258 360 225 + $ hp : num 110 110 93 110 175 105 + $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 + $ wt : num 2.62 2.88 2.32 3.21 3.44 ... + $ qsec: num 16.5 17 18.6 19.4 17 ... + $ vs : num 0 0 1 1 0 1 + $ am : num 1 1 1 0 0 0 + $ gear: num 4 4 4 3 3 3 + $ carb: num 4 4 1 1 2 1 + *** treat_var*** + gear + *** pop_data data.frame *** + 'data.frame': 32 obs. of 11 variables: + $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... + $ cyl : num 6 6 4 6 8 6 8 4 4 6 ... + $ disp: num 160 160 108 258 360 ... + $ hp : num 110 110 93 110 175 105 245 62 95 123 ... + $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ... + $ wt : num 2.62 2.88 2.32 3.21 3.44 ... + $ qsec: num 16.5 17 18.6 19.4 17 ... + $ vs : num 0 0 1 1 0 1 0 1 1 1 ... + $ am : num 1 1 1 0 0 0 0 0 0 0 ... + $ gear: num 4 4 4 3 3 3 3 4 4 4 ... + $ carb: num 4 4 1 1 2 1 4 2 2 4 ... + *** pop_treat_var *** + gear + *** treat_grps *** + Total: + 4 3 5 + +# tplyr layers are printed as expected + + *** count_layer *** + + target_var: + cyl + by: am + where: TRUE + Layer(s): 0 + +--- + + *** tplyr_layer *** + Target Name: mtcars + *** target_var *** + cyl + *** by *** + am + *** where *** + TRUE + +# f_str objects are printed as expected + + $n_counts + *** Format String *** + xx (xx.xx%) [xxx] [xx.xx%] + *** vars, extracted formats, and settings *** + distinct_n formated as: xx + integer length: 2 + decimal length: 0 + distinct_pct formated as: xx.xx + integer length: 2 + decimal length: 2 + n formated as: xxx + integer length: 3 + decimal length: 0 + pct formated as: xx.xx + integer length: 2 + decimal length: 2 + Total Format Size: 26 + +--- + + List of 1 + $ n_counts:*** Format String *** + xx (xx.xx%) [xxx] [xx.xx%] + *** vars, extracted formats, and settings *** + distinct_n formated as: xx + integer length: 2 + decimal length: 0 + distinct_pct formated as: xx.xx + integer length: 2 + decimal length: 2 + n formated as: xxx + integer length: 3 + decimal length: 0 + pct formated as: xx.xx + integer length: 2 + decimal length: 2 + Total Format Size: 26 + diff --git a/tests/testthat/_snaps/properties_layer.md b/tests/testthat/_snaps/properties_layer.md new file mode 100644 index 00000000..71b6a457 --- /dev/null +++ b/tests/testthat/_snaps/properties_layer.md @@ -0,0 +1,28 @@ +# target_var errors raise appropriately + + Invalid input to `target_var`. Submit either a variable name or multiple variable names using `dplyr::vars`. + +--- + + Invalid input to `~quos(filter = Species2)`. Submit either a variable name or multiple variable names using `dplyr::vars`. + +# by raises expected errors + + Invalid input to `~list(Species)`. Submit either a string, a variable name, or multiple variable names using `dplyr::vars`. + +--- + + Invalid input to `by`. Submit either a string, a variable name, or multiple variable names using `dplyr::vars`. + +--- + + Invalid input to `by`. Submit either a string, a variable name, or multiple variable names using `dplyr::vars`. + +# where throws errors as expected + + The `where` parameter must contain subsetting logic (enter without quotes) + +--- + + The `where` parameter must contain subsetting logic (enter without quotes) + diff --git a/tests/testthat/_snaps/riskdiff.md b/tests/testthat/_snaps/riskdiff.md new file mode 100644 index 00000000..c4bd7621 --- /dev/null +++ b/tests/testthat/_snaps/riskdiff.md @@ -0,0 +1,20 @@ +# `add_risk_diff` can't be applied to a non-count layer + + Risk difference can only be applied to a count layer. + +# Improper parameter entry is handled correctly + + Comparisons provided must be two-element character vectors + +--- + + Comparisons provided must be two-element character vectors + +--- + + All arguments provided via `args` must be valid arguments of `prop.test` + +# Invalid name to format string call errors properly + + Invalid format names supplied. Count layers only accept the following format names: n_counts, riskdiff + diff --git a/tests/testthat/_snaps/shift.md b/tests/testthat/_snaps/shift.md new file mode 100644 index 00000000..7ff62c37 --- /dev/null +++ b/tests/testthat/_snaps/shift.md @@ -0,0 +1,9 @@ +# Shift layer clauses with invalid syntax give informative error + + group_shift `where` condition `bad == code` is invalid. Filter error: + Error in `h()`: + ! Problem with `filter()` input `..1`. + i Input `..1` is `bad == code`. + x object 'bad' not found + + diff --git a/tests/testthat/_snaps/table.md b/tests/testthat/_snaps/table.md new file mode 100644 index 00000000..fc50f6aa --- /dev/null +++ b/tests/testthat/_snaps/table.md @@ -0,0 +1,4 @@ +# tplyr_table throws error when passed a bad table argument + + unused argument (a = 1:10) + diff --git a/tests/testthat/_snaps/table_bindings.md b/tests/testthat/_snaps/table_bindings.md new file mode 100644 index 00000000..99f355ab --- /dev/null +++ b/tests/testthat/_snaps/table_bindings.md @@ -0,0 +1,44 @@ +# pop_data binding throws expected errors + + 'pop_data' argument passed to tplyr_table must be a data.frame, + instead a class of: 'character' was passed. + +--- + + 'pop_data' argument passed to tplyr_table must be a data.frame, + instead a class of: 'array' was passed. + +--- + + 'pop_data' argument passed to tplyr_table must be a data.frame, + instead a class of: 'logical' was passed. + +--- + + 'pop_data' argument passed to tplyr_table must be a data.frame, + instead a class of: 'NULL' was passed. + +# treat_var throws errors as expected + + treat_var column not found in target dataset + +--- + + treat_var column not found in target dataset + +--- + + A treat_var argument must be supplied + +# pop_treat_var throws errors as expected + + pop_treat_var passed to tplyr_table is not a column of pop_data + +--- + + pop_treat_var passed to tplyr_table is not a column of pop_data + +--- + + pop_treat_var passed to tplyr_table is not a column of pop_data + diff --git a/tests/testthat/test-assertions.R b/tests/testthat/test-assertions.R index d01fb078..c29a25ca 100644 --- a/tests/testthat/test-assertions.R +++ b/tests/testthat/test-assertions.R @@ -27,8 +27,8 @@ # l <- group_count(tab, Species) # # expect_silent(assert_is_layer(l)) -# expect_error(assert_is_layer(tab), "asdf") -# expect_error(assert_is_layer(list()), "asdf") +# expect_snapshot_error(assert_is_layer(tab), "asdf") +# expect_snapshot_error(assert_is_layer(list()), "asdf") # }) # # test_that("assert_is_table raises errors properly", { @@ -36,7 +36,7 @@ # l <- group_count(tab, Species) # # expect_silent(assert_is_table(tab)) -# expect_error(assert_is_table(l), "asdf") -# expect_error(assert_is_table(list()), "asdf") +# expect_snapshot_error(assert_is_table(l), "asdf") +# expect_snapshot_error(assert_is_table(list()), "asdf") # }) diff --git a/tests/testthat/test-column_headers.R b/tests/testthat/test-column_headers.R index 0cf90f12..db76237d 100644 --- a/tests/testthat/test-column_headers.R +++ b/tests/testthat/test-column_headers.R @@ -1,16 +1,15 @@ -context("column_headers.R") # Need a simple data frame to test with iris2 <- iris %>% mutate_all(as.character) test_that("All columns must be character", { - expect_error(add_column_headers(iris, "header_text"), "When binding headers") + expect_snapshot_error(add_column_headers(iris, "header_text")) }) test_that("Nested headers are not allowed", { header_string = "TEXT | TEXT {TEXT {TEXT} TEXT } | TEXT" - expect_error(add_column_headers(iris2, header_string), "Nested spanning headers") + expect_snapshot_error(add_column_headers(iris2, header_string)) }) test_that("Header strings must have the same number of columns as the data frame", { @@ -27,19 +26,19 @@ test_that("Header strings must have the same number of columns as the data frame # Test the results expect_silent(add_column_headers(iris2, good_no_spanner)) expect_silent(add_column_headers(iris2, good_spanner)) - err <- "Number of columns provided" - expect_error(add_column_headers(iris2, less_no_spanner), err) - expect_error(add_column_headers(iris2, more_no_spanner), err) - expect_error(add_column_headers(iris2, less_spanner), err) - expect_error(add_column_headers(iris2, more_spanner), err) - expect_error(add_column_headers(iris2, nested_less), err) - expect_error(add_column_headers(iris2, nested_more), err) + + expect_snapshot_error(add_column_headers(iris2, less_no_spanner)) + expect_snapshot_error(add_column_headers(iris2, more_no_spanner)) + expect_snapshot_error(add_column_headers(iris2, less_spanner)) + expect_snapshot_error(add_column_headers(iris2, more_spanner)) + expect_snapshot_error(add_column_headers(iris2, nested_less)) + expect_snapshot_error(add_column_headers(iris2, nested_more)) }) test_that("Unmatched spanner brackers", { header_string = "TEXT | TEXT {TEXT {TEXT} TEXT | TEXT" - expect_error(add_column_headers(iris2, header_string), "Unmatched brackets for spanning headers") + expect_snapshot_error(add_column_headers(iris2, header_string)) }) test_that("Spanning headers produce correctly", { @@ -73,7 +72,7 @@ test_that("Spanning headers produce correctly", { }) test_that("add_column_headers throws an error when you use a token and don't pass header_n", { - expect_error({ + expect_snapshot_error({ mtcars2 <- mtcars %>% mutate_all(as.character) @@ -87,7 +86,7 @@ test_that("add_column_headers throws an error when you use a token and don't pas count_string <- "Rows | am0 **0** | am1 **1**" add_column_headers(b_t, count_string) - }, "You must pass a header_n if you are using replacement tokens") + }) }) test_that("add_column_headers returns the expected result when tokens are passed", { diff --git a/tests/testthat/test-count.R b/tests/testthat/test-count.R index 912aa1cf..9aadeb15 100644 --- a/tests/testthat/test-count.R +++ b/tests/testthat/test-count.R @@ -141,35 +141,35 @@ test_that("Count layers are built as expected", { "target_var", "precision_by", "layers", "format_strings", "result_order_var", "distinct_by")) - expect_equal(c1$by, quos()) - expect_equal(c2$by, quos(am)) - expect_equal(c3$by, quos(am, vs)) - expect_equal(c4$by, quos(am, vs)) - expect_equal(c5$by, quos(am, vs)) - expect_equal(c6$by, quos()) - expect_equal(c7$by, quos()) - expect_equal(c8$by, quos()) - expect_equal(c9$by, quos()) - expect_equal(c10$by, quos()) - - expect_equal(c1$target_var, quos(cyl)) - expect_equal(c2$target_var, quos(cyl)) - expect_equal(c3$target_var, quos(cyl)) - expect_equal(c4$target_var, quos(cyl)) - expect_equal(c5$target_var, quos(cyl)) - expect_equal(c6$target_var, quos(cyl)) - expect_equal(c7$target_var, quos(cyl, grp)) - expect_equal(c8$target_var, quos(cyl)) - expect_equal(c9$target_var, quos(cyl, grp)) - expect_equal(c10$target_var, quos(cyl)) + expect_equal(unname(map_chr(c1$by, as_name)), character()) + expect_equal(unname(map_chr(c2$by, as_name)), "am") + expect_equal(unname(map_chr(c3$by, as_name)), c("am", "vs")) + expect_equal(unname(map_chr(c4$by, as_name)), c("am", "vs")) + expect_equal(unname(map_chr(c5$by, as_name)), c("am", "vs")) + expect_equal(unname(map_chr(c6$by, as_name)), character()) + expect_equal(unname(map_chr(c7$by, as_name)), character()) + expect_equal(unname(map_chr(c8$by, as_name)), character()) + expect_equal(unname(map_chr(c9$by, as_name)), character()) + expect_equal(unname(map_chr(c10$by, as_name)), character()) + + expect_equal(unname(map_chr(c1$target_var, as_name)), "cyl") + expect_equal(unname(map_chr(c2$target_var, as_name)), "cyl") + expect_equal(unname(map_chr(c3$target_var, as_name)), "cyl") + expect_equal(unname(map_chr(c4$target_var, as_name)), "cyl") + expect_equal(unname(map_chr(c5$target_var, as_name)), "cyl") + expect_equal(unname(map_chr(c6$target_var, as_name)), "cyl") + expect_equal(unname(map_chr(c7$target_var, as_name)), c("cyl", "grp")) + expect_equal(unname(map_chr(c8$target_var, as_name)), "cyl") + expect_equal(unname(map_chr(c9$target_var, as_name)), c("cyl", "grp")) + expect_equal(unname(map_chr(c10$target_var, as_name)), "cyl") expect_equal(c4$format_strings$n_counts, f_str("xxx", n)) expect_equal(c5$include_total_row, TRUE) - expect_equal(c6$distinct_by, quos(cyl)) - expect_equal(c8$distinct_by, quos(am)) + expect_equal(unname(map_chr(c6$distinct_by, as_name)), "cyl") + expect_equal(unname(map_chr(c8$distinct_by, as_name)), "am") expect_equal(c9$indentation, "") expect_equal(c10$count_row_prefix, "abc") - expect_equal(c15$distinct_by, quos(am, vs)) + expect_equal(unname(map_chr(c15$distinct_by, as_name)), c("am", "vs")) }) test_that("Count layers are summarized without errors and warnings", { @@ -326,7 +326,7 @@ test_that("Count layer clauses with invalid syntax give informative error", { group_count(am, where=bad == code) ) - expect_error(build(t), "group_count `where` condition `bad == code` is invalid.") + expect_snapshot_error(build(t)) }) @@ -435,15 +435,15 @@ test_that("Total rows and missing counts are displayed correctly(0.1.5 Updates)" build() - expect_output_file(dput(t1), "count_t1") - expect_output_file(dput(t2), "count_t2") - expect_output_file(dput(t3), "count_t3") - expect_output_file(dput(t4), "count_t4") - expect_output_file(dput(t5), "count_t5") - expect_output_file(dput(t6), "count_t6") - expect_output_file(dput(t7), "count_t7") - expect_output_file(dput(t8), "count_t8") - expect_output_file(dput(t9), "count_t9") + expect_snapshot_output(dput(t1)) + expect_snapshot_output(dput(t2)) + expect_snapshot_output(dput(t3)) + expect_snapshot_output(dput(t4)) + expect_snapshot_output(dput(t5)) + expect_snapshot_output(dput(t6)) + expect_snapshot_output(dput(t7)) + expect_snapshot_output(dput(t8)) + expect_snapshot_output(dput(t9)) }) test_that("set_denom_where works as expected", { @@ -457,7 +457,7 @@ test_that("set_denom_where works as expected", { set_format_strings(f_str("xx (xx.x)", n, pct)) ) %>% build() - expect_output_file(dput(t10), "count_t10") + expect_snapshot_output(dput(t10)) t11 <- tplyr_table(mtcars, gear) %>% add_layer( group_count(cyl, where = cyl != 6) %>% @@ -465,7 +465,7 @@ test_that("set_denom_where works as expected", { set_format_strings(f_str("xx (xx.x)", n, pct)) ) %>% build() - expect_output_file(dput(t11), "count_t11") + expect_snapshot_output(dput(t11)) t12 <- tplyr_table(mtcars, gear) %>% set_pop_data(pop_mtcars) %>% @@ -474,7 +474,7 @@ test_that("set_denom_where works as expected", { set_denom_where(cyl != 6) %>% set_distinct_by(am) ) - expect_warning(build(t12), "A `denom_where` has been set") + expect_snapshot_warning(build(t12)) t13 <- tplyr_table(mtcars, gear) %>% add_layer( @@ -485,7 +485,7 @@ test_that("set_denom_where works as expected", { ) %>% build() - expect_output_file(dput(t13), "count_t13") + expect_snapshot_output(dput(t13)) }) test_that("missing counts can be set without a format and it inherits the layer format", { @@ -547,7 +547,7 @@ test_that("nested count layers can accecpt text values in the first variable", { add_layer( group_count(vars(cyl, "Txt")) ) - expect_error(build(t2), "Inner layers must be data driven variables") + expect_snapshot_error(build(t2)) mtcars$cyl <- factor(as.character(mtcars$cyl), c("4", "6", "8", "25")) t2 <- tplyr_table(mtcars, gear) %>% @@ -566,17 +566,17 @@ test_that("Variable names will be coersed into symbols", { add_layer( group_count("cyl") ) - expect_warning(build(t1), "The first target variable has been coerced") + expect_snapshot_warning(build(t1)) t2 <- tplyr_table(mtcars2, gear) %>% add_layer( group_count(vars("all cyl", "cyl")) ) - expect_warning(build(t2), "The second target variable has been coerced") + expect_snapshot_warning(build(t2)) }) test_that("nested count layers can be build with character value in first position and risk difference", { - expect_warning({ + suppressWarnings({ t1 <- tplyr_table(mtcars, gear) %>% add_layer( group_count(vars("all_cyl", cyl)) %>% @@ -586,7 +586,7 @@ test_that("nested count layers can be build with character value in first positi ) ) %>% build() - }, "Chi-squared approximation may be incorrect") + }) expect_equal(t1$rdiff_4_5, c(" 0.000 ( 0.000, 0.000)", @@ -616,14 +616,14 @@ test_that("keep_levels works as expeceted", { expect_equal(t2$var1_3, c(" 12 ( 80%)", " 12 ( 80%)")) expect_equal(dim(t2), c(2, 8)) - expect_error({ + expect_snapshot_error({ t3 <- tplyr_table(mtcars, gear) %>% add_layer( group_count(cyl) %>% keep_levels("10", "20") ) %>% build() - }, "Error: level passed to `kept_levels` not found: 10 20") + }) mtcars$grp <- paste0("grp.", as.numeric(mtcars$cyl) + rep(c(0, 0.5), 16)) t4 <- tplyr_table(mtcars, gear) %>% @@ -631,7 +631,7 @@ test_that("keep_levels works as expeceted", { group_count(vars(cyl, grp)) %>% keep_levels("nothere") ) - expect_error(build(t4), "level passed to `kept_levels` not found: nothere") + expect_snapshot_error(build(t4)) }) test_that("nested count layers can be built with restrictive where logic", { @@ -655,13 +655,13 @@ test_that("nested count layers handle `set_denoms_by` as expected", { mtcars <- mtcars2 mtcars$grp <- paste0("grp.", mtcars$cyl + rep(c(0, 0.5), 16)) - expect_error({ + expect_snapshot_error({ t1 <- tplyr_table(mtcars, gear) %>% add_layer( group_count(vars(cyl,grp)) %>% set_denoms_by(grp) ) - }, "You can not pass the second variable in") + }) t2 <- tplyr_table(mtcars, gear) %>% add_layer( @@ -732,8 +732,7 @@ test_that("nested count layers will error out if second variable is bigger than group_count(vars(grp, cyl)) ) - expect_error(build(t), - "The number of values of your second variable must be greater") + expect_snapshot_error(build(t)) }) test_that("Posix columns don't cause the build to error out.", { diff --git a/tests/testthat/test-desc.R b/tests/testthat/test-desc.R index 466f9696..29bb67a4 100644 --- a/tests/testthat/test-desc.R +++ b/tests/testthat/test-desc.R @@ -202,10 +202,10 @@ test_that("Auto precision builds correctly", { t_uncap_comp <- readr::read_csv('t_uncap.csv') t_cap_comp <- readr::read_csv('t_cap.csv') - expect_equivalent(mutate_all(t_uncap, as.character), - mutate_all(t_uncap_comp, as.character)) - expect_equivalent(mutate_all(t_cap, as.character), - mutate_all(t_cap_comp, as.character)) + expect_equal(mutate_all(t_uncap, as.character), + mutate_all(t_uncap_comp, as.character), ignore_attr = TRUE) + expect_equal(mutate_all(t_cap, as.character), + mutate_all(t_cap_comp, as.character), ignore_attr = TRUE) }) @@ -215,5 +215,5 @@ test_that("Desc layer clauses with invalid syntax give informative error", { group_desc(drat, where=bad == code) ) - expect_error(build(t), "group_desc `where` condition `bad == code` is invalid.") + expect_snapshot_error(build(t)) }) diff --git a/tests/testthat/test-format.R b/tests/testthat/test-format.R index 29c778e6..e5b50f22 100644 --- a/tests/testthat/test-format.R +++ b/tests/testthat/test-format.R @@ -1,14 +1,13 @@ -context('format.R') test_that("Format string must be character", { - expect_error(f_str(123)) # Need to come back to issues with assert_has_class to address the fact that + expect_snapshot_error(f_str(123)) # Need to come back to issues with assert_has_class to address the fact that # error messages don't work in testthat }) # Errors are generated when too few or too many variables test_that("Error is thrown when format doesn't match variables", { - expect_error(f_str("xx.x xx.x", a), "In `f_str` 2 formats were entered") - expect_error(f_str("xx.x", a, b), "In `f_str` 1 formats were entered") + expect_snapshot_error(f_str("xx.x xx.x", a)) + expect_snapshot_error(f_str("xx.x", a, b)) }) # Variables are picked up appropriately diff --git a/tests/testthat/test-functional.R b/tests/testthat/test-functional.R index a12f8db6..f2741eb6 100644 --- a/tests/testthat/test-functional.R +++ b/tests/testthat/test-functional.R @@ -113,7 +113,7 @@ test_that("all test tables can be built without errors or warnings", { expect_silent(build(t4)) expect_silent(build(t5)) expect_silent(suppressWarnings(build(t6))) # This seems to be a bug https://github.com/tidyverse/dplyr/issues/5149 - expect_error(build(t7), "object 'col_i' not found") + expect_snapshot_error(build(t7)) }) test_that("all tables have the expected dimentions", { diff --git a/tests/testthat/test-get_numeric.R b/tests/testthat/test-get_numeric.R index 7477188e..cdb39ea1 100644 --- a/tests/testthat/test-get_numeric.R +++ b/tests/testthat/test-get_numeric.R @@ -1,4 +1,3 @@ -context('get_numeric.R') ## Numeric Data ---- test_that("Error handling - numeric", { @@ -11,12 +10,12 @@ test_that("Error handling - numeric", { group_count(cyl) ) - expect_error(get_numeric_data(t, where=x==1), "If `where`") - expect_error(get_numeric_data(t, layer=c('drat', 'cyl'), where=x==1), "If `where`") - expect_error(get_numeric_data(t, layer='blah'), regexp="do\\(es\\) not exist$") - expect_error(get_numeric_data(t, layer=c('drat','blah')), regexp="do\\(es\\) not exist$") - expect_error(get_numeric_data(t, layer=10), "Provided layer index is out of range") - expect_error(get_numeric_data(t, layer=c(1, 10)), "Provided layer index is out of range") + expect_snapshot_error(get_numeric_data(t, where=x==1)) + expect_snapshot_error(get_numeric_data(t, layer=c('drat', 'cyl'), where=x==1)) + expect_snapshot_error(get_numeric_data(t, layer='blah')) + expect_snapshot_error(get_numeric_data(t, layer=c('drat','blah'))) + expect_snapshot_error(get_numeric_data(t, layer=10)) + expect_snapshot_error(get_numeric_data(t, layer=c(1, 10))) }) @@ -86,12 +85,12 @@ test_that("Error handling - statistic", { add_risk_diff(c('4', '3')) ) - expect_error(get_stats_data(t, where=x==1), "If `where`") - expect_error(get_stats_data(t, layer=c(1, 2), where=x==1), "If `where`") - expect_error(get_stats_data(t, layer='blah'), regexp="do\\(es\\) not exist$") - expect_error(get_stats_data(t, layer=c('am', 'blah')), regexp="do\\(es\\) not exist$") - expect_error(get_stats_data(t, layer=10), "Provided layer index is out of range") - expect_error(get_stats_data(t, layer=c(1, 10)), "Provided layer index is out of range") + expect_snapshot_error(get_stats_data(t, where=x==1)) + expect_snapshot_error(get_stats_data(t, layer=c(1, 2), where=x==1)) + expect_snapshot_error(get_stats_data(t, layer='blah')) + expect_snapshot_error(get_stats_data(t, layer=c('am', 'blah'))) + expect_snapshot_error(get_stats_data(t, layer=10)) + expect_snapshot_error(get_stats_data(t, layer=c(1, 10))) }) @@ -127,7 +126,7 @@ test_that("No parameters gives a list of statistics data in a list of layers", { # Elements of list contain a list walk(dat_list, expect_type, type='list') # No stats on first two - empty - expect_equivalent(map_int(dat_list, length), c(0, 0, 1, 1)) + expect_equal(map_int(dat_list, length), c(0, 0, 1, 1), ignore_attr = TRUE) # Last 2 have dataframes expect_s3_class(dat_list[[3]][[1]], 'tbl_df') expect_s3_class(dat_list[[4]][[1]], 'tbl_df') @@ -144,7 +143,7 @@ test_that("Multiple layers gives a list of statistics data in a list for those l # Elements of list contain a list walk(dat_list, expect_type, type='list') # No stats on first two - empty - expect_equivalent(map_int(dat_list, length), c(0, 0, 1, 1)) + expect_equal(map_int(dat_list, length), c(0, 0, 1, 1), ignore_attr = TRUE) # Last 2 have dataframes expect_s3_class(dat_list[[3]][[1]], 'tbl_df') expect_s3_class(dat_list[[4]][[1]], 'tbl_df') @@ -156,7 +155,7 @@ test_that("Multiple layers gives a list of statistics data in a list for those l # Elements of list contain a list walk(dat_list, expect_type, type='list') # No stats on first two - empty - expect_equivalent(map_int(dat_list, length), c(1, 1)) + expect_equal(map_int(dat_list, length), c(1, 1), ignore_attr = TRUE) # Last 2 have dataframes expect_s3_class(dat_list[[1]][[1]], 'tbl_df') expect_s3_class(dat_list[[2]][[1]], 'tbl_df') diff --git a/tests/testthat/test-layer.R b/tests/testthat/test-layer.R index bf0ed439..cb4dfd83 100644 --- a/tests/testthat/test-layer.R +++ b/tests/testthat/test-layer.R @@ -1,8 +1,7 @@ -context("layer.R") ## Check empty return ---- test_that("`tplyr_layer` errors when no arguments provided", { - expect_error(tplyr_layer(), "The `parent` argument must be provided.") + expect_snapshot_error(tplyr_layer()) }) @@ -52,18 +51,14 @@ test_that("type field can only contain one of 'count', 'desc', or 'shift'", { expect_silent(tplyr_layer(t, target_var=quos(Species), by=quos(NULL), cols=quos(NULL), where=quo(TRUE), type='count')) expect_silent(tplyr_layer(t, target_var=quos(Sepal.Length), by=quos(NULL), cols=quos(NULL), where=quo(TRUE), type='desc')) expect_silent(tplyr_layer(t, target_var=quos(Species), by=quos(NULL), cols=quos(NULL), where=quo(TRUE), type='shift')) - expect_error(tplyr_layer(t, target_var=quos(Species), by=quos(NULL), cols=quos(NULL), where=quo(TRUE), type=c('shift', 'desc')), - '`type` must be one of "count", "desc", or "shift"') - expect_error(tplyr_layer(t, target_var=quos(Species), by=quos(NULL), cols=quos(NULL), where=quo(TRUE), type=c('count', 'desc')), - '`type` must be one of "count", "desc", or "shift"') - expect_error(tplyr_layer(t, target_var=quos(Species), by=quos(NULL), cols=quos(NULL), where=quo(TRUE), type=c('count', 'desc', 'shift')), - '`type` must be one of "count", "desc", or "shift"') - expect_error(tplyr_layer(t, target_var=quos(Species), by=quos(NULL), cols=quos(NULL), where=quo(TRUE), type="bad"), - '`type` must be one of "count", "desc", or "shift"') + expect_snapshot_error(tplyr_layer(t, target_var=quos(Species), by=quos(NULL), cols=quos(NULL), where=quo(TRUE), type=c('shift', 'desc'))) + expect_snapshot_error(tplyr_layer(t, target_var=quos(Species), by=quos(NULL), cols=quos(NULL), where=quo(TRUE), type=c('count', 'desc'))) + expect_snapshot_error(tplyr_layer(t, target_var=quos(Species), by=quos(NULL), cols=quos(NULL), where=quo(TRUE), type=c('count', 'desc', 'shift'))) + expect_snapshot_error(tplyr_layer(t, target_var=quos(Species), by=quos(NULL), cols=quos(NULL), where=quo(TRUE), type="bad")) }) test_that("Parent must be a `tplyr_table`, `tplyr_layer`, or `tplyr_subgroup_layer`", { - expect_error(group_count(env()), "Must provide `tplyr_table`, `tplyr_layer`, or `tplyr_subgroup_layer` object from the `tplyr` package.") + expect_snapshot_error(group_count(env())) }) test_that("`by` must me a string, a variable name, or multiple variables submitted using `dplyr::vars`", { @@ -73,12 +68,12 @@ test_that("`by` must me a string, a variable name, or multiple variables submitt expect_silent(group_count(t, target_var=Species, by=Petal.Width)) expect_silent(group_count(t, target_var=Species, by=vars('character', Petal.Width))) # Error checks - err = "Submit either a string, a variable name, or multiple variable names using `dplyr::vars`." - expect_error(group_count(t, target_var=Species, by=1), err) - expect_error(group_count(t, target_var=Species, by=list('a', 'b')), err) - expect_error(group_count(t, target_var=Species, by=c('a', 'b')), err) - expect_error(group_count(t, target_var=Species, by=vars('character', Petal.Width, 1)), err) - expect_error(group_count(t, target_var=Species, by=vars('character', Petal.Width, x+y)), err) + + expect_snapshot_error(group_count(t, target_var=Species, by=1)) + expect_snapshot_error(group_count(t, target_var=Species, by=list('a', 'b'))) + expect_snapshot_error(group_count(t, target_var=Species, by=c('a', 'b'))) + expect_snapshot_error(group_count(t, target_var=Species, by=vars('character', Petal.Width, 1))) + expect_snapshot_error(group_count(t, target_var=Species, by=vars('character', Petal.Width, x+y))) }) test_that("`target_var` must me a string, a variable name, or multiple variables submitted using `dplyr::vars`", { @@ -87,12 +82,11 @@ test_that("`target_var` must me a string, a variable name, or multiple variables expect_silent(group_count(t, target_var=Species)) expect_silent(group_count(t, target_var=vars(Petal.Width, Petal.Length))) # Error checks - err = "Submit either a string, a variable name, or multiple variable names using `dplyr::vars`." - expect_error(group_count(t, target_var=1), err) - expect_error(group_count(t, target_var=list('a', 'b')), err) - expect_error(group_count(t, target_var=c('a', 'b')), err) - expect_error(group_count(t, target_var=vars('character', Petal.Width, 1)), err) - expect_error(group_count(t, target_var=vars('character', Petal.Width, x+y)), err) + expect_snapshot_error(group_count(t, target_var=1)) + expect_snapshot_error(group_count(t, target_var=list('a', 'b'))) + expect_snapshot_error(group_count(t, target_var=c('a', 'b'))) + expect_snapshot_error(group_count(t, target_var=vars('character', Petal.Width, 1))) + expect_snapshot_error(group_count(t, target_var=vars('character', Petal.Width, x+y))) }) @@ -101,23 +95,20 @@ test_that("`target_var` must exist in target dataset", { # Variable exists expect_silent(group_count(t, target_var=Species)) # Variable does not - expect_error(group_count(t, target_var=BadVar), "`target_var` variable `BadVar` does not exist in target dataset") - expect_error(group_count(t, target_var=vars(Species, BadVar)), "`target_var` variable `BadVar` does not exist in target dataset") + expect_snapshot_error(group_count(t, target_var=BadVar)) + expect_snapshot_error(group_count(t, target_var=vars(Species, BadVar))) }) test_that("`by` varaibles must exist in the target dataset", { t <- tplyr_table(iris, Sepal.Width) - expect_error(group_count(t, target_var=Species, by=BadVars), - "`by` variable `BadVars` does not exist in target dataset") - expect_error(group_count(t, target_var=Species, by=vars(Species, BadVars)), - "`by` variable `BadVars` does not exist in target dataset") + expect_snapshot_error(group_count(t, target_var=Species, by=BadVars)) + expect_snapshot_error(group_count(t, target_var=Species, by=vars(Species, BadVars))) }) test_that("`where` must be programming logic (quosure of class 'call')", { t <- tplyr_table(iris, Sepal.Width) expect_silent(group_count(t, target_var=Species, where=a == b)) - expect_error(group_count(t, target_var=Species, where=VARAIBLE), - "The `where` parameter") + expect_snapshot_error(group_count(t, target_var=Species, where=VARAIBLE)) }) ## Coded defaults ---- @@ -150,23 +141,23 @@ test_that("Parent of layer is appropraitely parent environment", { test_that("Desc layers only accept numeric variables", { - expect_error({tplyr_table(ToothGrowth, dose) %>% + expect_snapshot_error({tplyr_table(ToothGrowth, dose) %>% add_layer( group_desc(supp) ) - }, regexp = "Target variables must be numeric for desc layers\\.") + }) - expect_error({tplyr_table(ToothGrowth, dose) %>% + expect_snapshot_error({tplyr_table(ToothGrowth, dose) %>% add_layer( group_desc(vars(len, supp)) ) - }, regexp = "Target variables must be numeric for desc layers\\.") + }) - expect_error({tplyr_table(ToothGrowth, dose) %>% + expect_snapshot_error({tplyr_table(ToothGrowth, dose) %>% add_layer( group_desc(vars(supp, len)) ) - }, regexp = "Target variables must be numeric for desc layers\\.") + }) }) diff --git a/tests/testthat/test-layering.R b/tests/testthat/test-layering.R index 43cda2d7..9b76f6ad 100644 --- a/tests/testthat/test-layering.R +++ b/tests/testthat/test-layering.R @@ -1,4 +1,3 @@ -context("layering.R") ## group_ family of functions ---- @@ -30,14 +29,13 @@ test_that("`group_` function pass parameters through appropriately", { ## `add_layer` error testing test_that("All parameters must be provided", { t <- tplyr_table(iris, Sepal.Width) - expect_error(add_layer(), "`parent` parameter must be provided") - expect_error(add_layer(t), "`layer` parameter must be provided") + expect_snapshot_error(add_layer()) + expect_snapshot_error(add_layer(t)) expect_silent(add_layer(t, group_desc(target_var=Sepal.Length))) }) test_that("Parent argument is a valid class (pass through to `tplyr_layer`)", { - expect_error(add_layer(iris, group_desc(target_var=Sepal.Length)), - "Must provide `tplyr_table`, `tplyr_layer`, or `tplyr_subgroup_layer` object from the `tplyr` package.") + expect_snapshot_error(add_layer(iris, group_desc(target_var=Sepal.Length))) }) test_that("Only `Tplyr` methods are allowed in the `layer` parameter", { @@ -48,13 +46,13 @@ test_that("Only `Tplyr` methods are allowed in the `layer` parameter", { ) }) - expect_error({ + expect_snapshot_error({ t <- tplyr_table(iris, Sepal.Width) %>% add_layer( group_desc(target_var=Sepal.Length) %>% print() ) - }, "Functions called within `add_layer` must be part of `Tplyr`") + }) }) ## `add_layer` functionality testing @@ -66,7 +64,7 @@ test_that("`add_layer` attaches layer object into parent", { expect_true(length(t$layers) == 1) expect_s3_class(t$layers[[1]], 'tplyr_layer') - expect_equal(t$layers[[1]]$target_var, vars(Sepal.Length)) + expect_equal(unname(map_chr(t$layers[[1]]$target_var, as_name)), "Sepal.Length") }) test_that("Using `add_layer` within `add_layer` adds child layers into a layer object", { diff --git a/tests/testthat/test-opts.R b/tests/testthat/test-opts.R index 2da17ef3..388e2dde 100644 --- a/tests/testthat/test-opts.R +++ b/tests/testthat/test-opts.R @@ -1,4 +1,3 @@ -context('zzz.R') # Store the default options diff --git a/tests/testthat/test-pop_data.R b/tests/testthat/test-pop_data.R index 491fec10..547a1c0c 100644 --- a/tests/testthat/test-pop_data.R +++ b/tests/testthat/test-pop_data.R @@ -5,16 +5,16 @@ test_that("add_treat_grps errors function properly", { t <- tplyr_table(mtcars, gear) # Must be named - expect_error(add_treat_grps(t, c("blah", "bloh")), "Treatment group arguments must have names") + expect_snapshot_error(add_treat_grps(t, c("blah", "bloh"))) # Must attach to tplyr_table l <- group_count(t, am) - expect_error(add_treat_grps(l, "one" = c(1,2,3)), msg = "Treatment groups can only be added to `tplyr_table` objects") + expect_snapshot_error(add_treat_grps(l, "one" = c(1,2,3))) }) test_that("add_total_group errors function properly", { t <- tplyr_table(mtcars, gear) - expect_error(add_total_group(t, 1), msg = "Argument `group_name` in function `add_total_group` must be character") + expect_snapshot_error(add_total_group(t, 1)) }) test_that("add_total_group adds treat_grps bindings properly", { diff --git a/tests/testthat/test-precision.R b/tests/testthat/test-precision.R index d72d9680..bfbeafef 100644 --- a/tests/testthat/test-precision.R +++ b/tests/testthat/test-precision.R @@ -1,4 +1,3 @@ -context('precision.R') mtcars_long <- mtcars %>% rownames_to_column(var = "model") %>% diff --git a/tests/testthat/test-print.R b/tests/testthat/test-print.R index 80493340..b1d953fe 100644 --- a/tests/testthat/test-print.R +++ b/tests/testthat/test-print.R @@ -11,26 +11,26 @@ t_ <- tplyr_table(mtcars, gear, cols = vs) %>% test_that("tplyr_table is printed as expected", { - expect_known_output(print(t_), test_path("table_print.txt")) + expect_snapshot_output(print(t_)) - expect_known_output(str(t_), test_path("table_str.txt")) + expect_snapshot_output(str(t_)) build(t_) - expect_known_output(print(t_), test_path("table_built_print.txt")) + expect_snapshot_output(print(t_)) - expect_known_output(str(t_), test_path("table_built_str.txt")) + expect_snapshot_output(str(t_)) }) test_that("tplyr layers are printed as expected", { - expect_output_file(print(t_$layers[[1]], print_env = FALSE), test_path("layer_print.txt")) + expect_snapshot_output(print(t_$layers[[1]], print_env = FALSE)) - expect_known_output(str(t_$layers[[1]], print_env = FALSE), test_path("layer_str.txt")) + expect_snapshot_output(str(t_$layers[[1]], print_env = FALSE)) }) test_that("f_str objects are printed as expected", { - expect_known_output(print(t_$layers[[1]]$format_strings), test_path("fstr_print.txt")) + expect_snapshot_output(print(t_$layers[[1]]$format_strings)) - expect_known_output(str(t_$layers[[1]]$format_strings), test_path("fstr_str.txt")) + expect_snapshot_output(str(t_$layers[[1]]$format_strings)) }) diff --git a/tests/testthat/test-properties_layer.R b/tests/testthat/test-properties_layer.R index 837cd962..e30566fc 100644 --- a/tests/testthat/test-properties_layer.R +++ b/tests/testthat/test-properties_layer.R @@ -6,7 +6,7 @@ test_that("target_var layer bindings attaches properly", { tab <- tplyr_table(iris_a, Species) %>% group_count(Species) - expect_equal(get_target_var(tab), quos(Species)) + expect_equal(unname(map_chr(get_target_var(tab), as_name)), "Species") set_target_var(tab, Species2) expect_equal(get_target_var(tab), quos(Species2)) @@ -16,9 +16,8 @@ test_that("target_var errors raise appropriately", { tab <- tplyr_table(iris_a, Species) %>% group_count(Species) - expect_error(set_target_var(tab, "Species2"), "Invalid input to `target_var`") - expect_error(set_target_var(tab, quos(filter = Species2)), - "Submit either a variable name or multiple variable names using `dplyr::vars`.") + expect_snapshot_error(set_target_var(tab, "Species2")) + expect_snapshot_error(set_target_var(tab, quos(filter = Species2))) expect_silent(set_target_var(tab, Species2)) }) ##### by tests ##### @@ -35,17 +34,16 @@ test_that("by binds as expected", { expect_equal(get_by(tab), quos(Species2)) set_by(tab, vars(Species2, Sepal.Width)) - expect_equal(get_by(tab), vars(Species2, Sepal.Width)) + expect_equal(unname(map_chr(get_by(tab), as_name)), c("Species2", "Sepal.Width")) }) test_that("by raises expected errors", { tab <- tplyr_table(iris_a, Species) %>% group_count(Species) - msg = "Submit either a string, a variable name, or multiple variable names using `dplyr::vars`." - expect_error(set_by(tab, list(Species)), msg) - expect_error(set_by(tab, vars(Species, list())), msg) - expect_error(set_by(tab, vars(Species, 2)), msg) + expect_snapshot_error(set_by(tab, list(Species))) + expect_snapshot_error(set_by(tab, vars(Species, list()))) + expect_snapshot_error(set_by(tab, vars(Species, 2))) }) ##### where tests ##### @@ -63,8 +61,8 @@ test_that("where throws errors as expected", { tab <- tplyr_table(iris_a, Species) %>% group_count(Species) - expect_error(set_where(tab, "aString"), "The `where` parameter must contain subsetting logic") - expect_error(set_where(tab, Species), "The `where` parameter must contain subsetting logic") + expect_snapshot_error(set_where(tab, "aString")) + expect_snapshot_error(set_where(tab, Species)) expect_silent(set_where(tab, quo(Petal.Length > 3))) }) diff --git a/tests/testthat/test-riskdiff.R b/tests/testthat/test-riskdiff.R index ecbe44c1..3c3346e6 100644 --- a/tests/testthat/test-riskdiff.R +++ b/tests/testthat/test-riskdiff.R @@ -1,4 +1,3 @@ -context("riskdiff.R") ## Initial set-up and framework exists test_that("A container named `stats` exists in a new layer", { @@ -29,13 +28,13 @@ test_that("`add_risk_diff` adds an element of the correct type to the `stats` co test_that("`add_risk_diff` can't be applied to a non-count layer", { - expect_error({ + expect_snapshot_error({ t <- tplyr_table(mtcars, gear) %>% add_layer( group_desc(mpg) %>% add_risk_diff(c('5', '3')) ) - }, "Risk difference can only be applied to a count layer.") + }) }) @@ -45,19 +44,19 @@ test_that("Improper parameter entry is handled correctly", { l1 <- group_count(t, carb) # Not character - expect_error({ + expect_snapshot_error({ l1 %>% add_risk_diff(c(1,2)) - }, "Comparisons provided must") + }) # Not two elements - expect_error({ + expect_snapshot_error({ l1 %>% add_risk_diff(c('1', '2', '3')) - }, "Comparisons provided must") + }) # Invalid arguments to prop.test - expect_error({ + expect_snapshot_error({ l1 %>% add_risk_diff(c('5', '4'), args=list(badname = 2)) - }, "All arguments provided") + }) }) @@ -146,14 +145,14 @@ test_that("Invalid name to format string call errors properly", { t <- tplyr_table(mtcars, gear) # Basic risk diff for two groups, using defaults - expect_error({ + expect_snapshot_error({ l1 <- group_count(t, carb) %>% # Compare 4 vs. 3, 5 vs. 3 add_risk_diff( c('4', '3') ) %>% set_format_strings(badname = f_str('xx.xxx', dif)) - }, "Invalid format names supplied") + }) }) @@ -227,10 +226,10 @@ test_that("Make sure display values accurately reflect prop.test results", { c(carb_4$estimate[1], carb_4$estimate[2], carb_4$estimate[1] - carb_4$estimate[2], carb_4$conf.int[1], carb_4$conf.int[2]) ) - expect_equal(results[[1]], carb_1_res, tolerance = .000001) - expect_equal(results[[2]], carb_2_res, tolerance = .000001) - expect_equal(results[[3]], carb_3_res, tolerance = .000001) - expect_equal(results[[4]], carb_4_res, tolerance = .000001) + expect_equal(results[[2]], carb_2_res, tolerance = .00001) + expect_equal(results[[3]], carb_3_res, tolerance = .00001) + expect_equal(results[[4]], carb_4_res, tolerance = .00001) + expect_equal(results[[1]], carb_1_res, tolerance = .00001) }) test_that("Distinct or non-distinct values are chosen properly", { diff --git a/tests/testthat/test-shift.R b/tests/testthat/test-shift.R index d5302266..789c81e1 100644 --- a/tests/testthat/test-shift.R +++ b/tests/testthat/test-shift.R @@ -81,5 +81,5 @@ test_that("Shift layer clauses with invalid syntax give informative error", { group_shift(vars(row=vs, column=am), where=bad == code) ) - expect_error(build(t), "group_shift `where` condition `bad == code` is invalid.") + expect_snapshot_error(build(t)) }) diff --git a/tests/testthat/test-sort.R b/tests/testthat/test-sort.R index 94706392..1916854f 100644 --- a/tests/testthat/test-sort.R +++ b/tests/testthat/test-sort.R @@ -6,9 +6,9 @@ test_that("A group_count layer can be ordered properly with factors", { group_count(cyl) ) b_t <- build(t) - expect_equivalent(b_t[, 1], tibble(row_label1 = as.character(c(4, 6, 8)))) - expect_equivalent(b_t[, 5], tibble(ord_layer_index = as.integer(c(1, 1, 1)))) - expect_equivalent(b_t[, 6], tibble(ord_layer_1 = as.numeric(c(1, 2, 3)))) + expect_equal(b_t[, 1], tibble(row_label1 = as.character(c(4, 6, 8))), ignore_attr = TRUE) + expect_equal(b_t[, 5], tibble(ord_layer_index = as.integer(c(1, 1, 1))), ignore_attr = TRUE) + expect_equal(b_t[, 6], tibble(ord_layer_1 = as.numeric(c(1, 2, 3))), ignore_attr = TRUE) mtcars$cyl <- factor(mtcars$cyl, c(6, 8, 4)) t2 <- tplyr_table(mtcars, gear) %>% @@ -16,9 +16,9 @@ test_that("A group_count layer can be ordered properly with factors", { group_count(cyl) ) b_t2 <- build(t2) - expect_equivalent(b_t2[, 1], tibble(row_label1 = as.character(c(6, 8, 4)))) - expect_equivalent(b_t2[, 5], tibble(ord_layer_index = as.integer(c(1, 1, 1)))) - expect_equivalent(b_t2[, 6], tibble(ord_layer_1 = as.numeric(c(1, 2, 3)))) + expect_equal(b_t2[, 1], tibble(row_label1 = as.character(c(6, 8, 4))), ignore_attr = TRUE) + expect_equal(b_t2[, 5], tibble(ord_layer_index = as.integer(c(1, 1, 1))), ignore_attr = TRUE) + expect_equal(b_t2[, 6], tibble(ord_layer_1 = as.numeric(c(1, 2, 3))), ignore_attr = TRUE) t3 <- tplyr_table(mtcars, gear) %>% add_layer( @@ -26,13 +26,13 @@ test_that("A group_count layer can be ordered properly with factors", { ) b_t3 <- build(t3) %>% arrange(ord_layer_1, ord_layer_2, ord_layer_3) - expect_equivalent(b_t3[, 1], tibble(row_label1 = as.character(rep(c(0, 1), each = 6)))) - expect_equivalent(b_t3[, 2], tibble(row_label2 = as.character(rep(c(0, 0, 0, 1, 1, 1), 2)))) - expect_equivalent(b_t3[, 3], tibble(row_label3 = as.character(rep(c(6, 8, 4), 4)))) - expect_equivalent(b_t3[, 7], tibble(ord_layer_index = as.integer(rep(1, 12)))) - expect_equivalent(b_t3[, 8], tibble(ord_layer_1 = as.integer(rep(c(1, 2), each = 6)))) - expect_equivalent(b_t3[, 9], tibble(ord_layer_2 = as.integer(rep(c(1, 1, 1, 2, 2, 2), 2)))) - expect_equivalent(b_t3[, 10], tibble(ord_layer_3 = as.numeric(rep(c(1, 2, 3), 4)))) + expect_equal(b_t3[, 1], tibble(row_label1 = as.character(rep(c(0, 1), each = 6))), ignore_attr = TRUE) + expect_equal(b_t3[, 2], tibble(row_label2 = as.character(rep(c(0, 0, 0, 1, 1, 1), 2))), ignore_attr = TRUE) + expect_equal(b_t3[, 3], tibble(row_label3 = as.character(rep(c(6, 8, 4), 4))), ignore_attr = TRUE) + expect_equal(b_t3[, 7], tibble(ord_layer_index = as.integer(rep(1, 12))), ignore_attr = TRUE) + expect_equal(b_t3[, 8], tibble(ord_layer_1 = as.integer(rep(c(1, 2), each = 6))), ignore_attr = TRUE) + expect_equal(b_t3[, 9], tibble(ord_layer_2 = as.integer(rep(c(1, 1, 1, 2, 2, 2), 2))), ignore_attr = TRUE) + expect_equal(b_t3[, 10], tibble(ord_layer_3 = as.numeric(rep(c(1, 2, 3), 4))), ignore_attr = TRUE) }) test_that("A group_count layer can be ordered properly by counts", { @@ -43,16 +43,16 @@ test_that("A group_count layer can be ordered properly by counts", { ) b_t1 <- build(t1) %>% arrange(ord_layer_1, ord_layer_2, ord_layer_2) - expect_equivalent(b_t1[, 1], tibble(row_label1 = as.character(rep(c(0, 1), each = 6)))) - expect_equivalent(b_t1[, 2], tibble(row_label2 = as.character(rep(c(0, 0, 0, 1, 1, 1), 2)))) - expect_equivalent(b_t1[, 3], tibble(row_label3 = as.character(rep(c(4, 6, 8), 4)))) - expect_equivalent(b_t1[, 7], tibble(ord_layer_index = as.integer(rep(1, 12)))) - expect_equivalent(b_t1[, 8], tibble(ord_layer_1 = as.integer(rep(c(1, 2), each = 6)))) - expect_equivalent(b_t1[, 9], tibble(ord_layer_2 = as.integer(rep(c(1, 1, 1, 2, 2, 2), 2)))) - expect_equivalent(b_t1[, 10], tibble(ord_layer_3 = as.numeric(c(0, 0, 0, + expect_equal(b_t1[, 1], tibble(row_label1 = as.character(rep(c(0, 1), each = 6))), ignore_attr = TRUE) + expect_equal(b_t1[, 2], tibble(row_label2 = as.character(rep(c(0, 0, 0, 1, 1, 1), 2))), ignore_attr = TRUE) + expect_equal(b_t1[, 3], tibble(row_label3 = as.character(rep(c(4, 6, 8), 4))), ignore_attr = TRUE) + expect_equal(b_t1[, 7], tibble(ord_layer_index = as.integer(rep(1, 12))), ignore_attr = TRUE) + expect_equal(b_t1[, 8], tibble(ord_layer_1 = as.integer(rep(c(1, 2), each = 6))), ignore_attr = TRUE) + expect_equal(b_t1[, 9], tibble(ord_layer_2 = as.integer(rep(c(1, 1, 1, 2, 2, 2), 2))), ignore_attr = TRUE) + expect_equal(b_t1[, 10], tibble(ord_layer_3 = as.numeric(c(0, 0, 0, 2, 2, 0, 0, 2, 0, - 6, 0, 0)))) + 6, 0, 0))), ignore_attr = TRUE) t2 <- tplyr_table(mtcars, gear) %>% add_layer( @@ -62,16 +62,16 @@ test_that("A group_count layer can be ordered properly by counts", { ) b_t2 <- build(t2) %>% arrange(ord_layer_1, ord_layer_2, ord_layer_3) - expect_equivalent(b_t2[, 1], tibble(row_label1 = as.character(rep(c(0, 1), each = 6)))) - expect_equivalent(b_t2[, 2], tibble(row_label2 = as.character(rep(c(0, 0, 0, 1, 1, 1), 2)))) - expect_equivalent(b_t2[, 3], tibble(row_label3 = as.character(c(4, 6, 8, 8, 4, 6, 4, 6, 8, 4, 6, 8)))) - expect_equivalent(b_t2[, 7], tibble(ord_layer_index = as.integer(rep(1, 12)))) - expect_equivalent(b_t2[, 8], tibble(ord_layer_1 = as.integer(rep(c(1, 2), each = 6)))) - expect_equivalent(b_t2[, 9], tibble(ord_layer_2 = as.integer(rep(c(1, 1, 1, 2, 2, 2), 2)))) - expect_equivalent(b_t2[, 10], tibble(ord_layer_3 = as.numeric(c(0, 0, 12, + expect_equal(b_t2[, 1], tibble(row_label1 = as.character(rep(c(0, 1), each = 6))), ignore_attr = TRUE) + expect_equal(b_t2[, 2], tibble(row_label2 = as.character(rep(c(0, 0, 0, 1, 1, 1), 2))), ignore_attr = TRUE) + expect_equal(b_t2[, 3], tibble(row_label3 = as.character(c(4, 6, 8, 8, 4, 6, 4, 6, 8, 4, 6, 8))), ignore_attr = TRUE) + expect_equal(b_t2[, 7], tibble(ord_layer_index = as.integer(rep(1, 12))), ignore_attr = TRUE) + expect_equal(b_t2[, 8], tibble(ord_layer_1 = as.integer(rep(c(1, 2), each = 6))), ignore_attr = TRUE) + expect_equal(b_t2[, 9], tibble(ord_layer_2 = as.integer(rep(c(1, 1, 1, 2, 2, 2), 2))), ignore_attr = TRUE) + expect_equal(b_t2[, 10], tibble(ord_layer_3 = as.numeric(c(0, 0, 12, 0, 1, 2, 0, 0, 0, - 0, 0, 0)))) + 0, 0, 0))), ignore_attr = TRUE) }) @@ -85,13 +85,13 @@ test_that("A group_count layer can be ordered properly by a VARN", { b_t1 <- build(t1) %>% arrange(ord_layer_1, ord_layer_2) - expect_equivalent(b_t1[, 1], tibble(row_label1 = as.character(rep(c(0, 1), each = 6)))) - expect_equivalent(b_t1[, 2], tibble(row_label2 = as.character(rep(c(0, 0, 0, 1, 1, 1), 2)))) - expect_equivalent(b_t1[, 3], tibble(row_label3 = as.character(rep(c(4, 6, 8), 4)))) - expect_equivalent(b_t1[, 7], tibble(ord_layer_index = as.integer(rep(1, 12)))) - expect_equivalent(b_t1[, 8], tibble(ord_layer_1 = as.integer(rep(c(1, 2), each = 6)))) - expect_equivalent(b_t1[, 9], tibble(ord_layer_2 = as.integer(rep(c(1, 1, 1, 2, 2, 2), 2)))) - expect_equivalent(b_t1[, 10], tibble(ord_layer_3 = as.numeric(rep(c(4, 6, 8), 4)))) + expect_equal(b_t1[, 1], tibble(row_label1 = as.character(rep(c(0, 1), each = 6))), ignore_attr = TRUE) + expect_equal(b_t1[, 2], tibble(row_label2 = as.character(rep(c(0, 0, 0, 1, 1, 1), 2))), ignore_attr = TRUE) + expect_equal(b_t1[, 3], tibble(row_label3 = as.character(rep(c(4, 6, 8), 4))), ignore_attr = TRUE) + expect_equal(b_t1[, 7], tibble(ord_layer_index = as.integer(rep(1, 12))), ignore_attr = TRUE) + expect_equal(b_t1[, 8], tibble(ord_layer_1 = as.integer(rep(c(1, 2), each = 6))), ignore_attr = TRUE) + expect_equal(b_t1[, 9], tibble(ord_layer_2 = as.integer(rep(c(1, 1, 1, 2, 2, 2), 2))), ignore_attr = TRUE) + expect_equal(b_t1[, 10], tibble(ord_layer_3 = as.numeric(rep(c(4, 6, 8), 4))), ignore_attr = TRUE) }) test_that("A nested group_count layer can be ordered properly", { @@ -120,9 +120,9 @@ test_that("A nested group_count layer can be ordered properly", { ) b_t3 <- build(t3) - expect_equivalent(b_t[, 6], tibble(ord_layer_1 = as.integer(rep(c( 1, 2, 3), each = 3)))) - expect_equivalent(b_t2[, 6], tibble(ord_layer_1 = rep(c(25.1, 25.2, 25.3), each = 3))) - expect_equivalent(b_t3[, 6], tibble(ord_layer_1 = rep(c(25.3, 25.2, 25.1), each = 3))) + expect_equal(b_t[, 6], tibble(ord_layer_1 = as.integer(rep(c( 1, 2, 3), each = 3))), ignore_attr = TRUE) + expect_equal(b_t2[, 6], tibble(ord_layer_1 = rep(c(25.1, 25.2, 25.3), each = 3)), ignore_attr = TRUE) + expect_equal(b_t3[, 6], tibble(ord_layer_1 = rep(c(25.3, 25.2, 25.1), each = 3)), ignore_attr = TRUE) }) test_that("A group_desc layer can be ordered properly", { @@ -137,10 +137,10 @@ test_that("A group_desc layer can be ordered properly", { b_t <- build(t) %>% arrange(ord_layer_1, ord_layer_2) - expect_equivalent(b_t[, 1], tibble(row_label1 = rep(c("4", "6", "8"), each = 2))) - expect_equivalent(b_t[, 2], tibble(row_label2 = rep(c("n", "Mean (SD)"), 3))) - expect_equivalent(b_t[, 7], tibble(ord_layer_1 = as.integer(rep(c(1, 2, 3), each = 2)))) - expect_equivalent(b_t[, 8], tibble(ord_layer_2 = as.integer(rep(c(1, 2), 3)))) + expect_equal(b_t[, 1], tibble(row_label1 = rep(c("4", "6", "8"), each = 2)), ignore_attr = TRUE) + expect_equal(b_t[, 2], tibble(row_label2 = rep(c("n", "Mean (SD)"), 3)), ignore_attr = TRUE) + expect_equal(b_t[, 7], tibble(ord_layer_1 = as.integer(rep(c(1, 2, 3), each = 2))), ignore_attr = TRUE) + expect_equal(b_t[, 8], tibble(ord_layer_2 = as.integer(rep(c(1, 2), 3))), ignore_attr = TRUE) }) @@ -201,12 +201,12 @@ byfactor_in <- c(Inf, 1, Inf, 1, test_that("Nested count layers are ordered properly", { - expect_equivalent(adsl_1$ord_layer_1, byvarn_out) - expect_equivalent(adsl_1$ord_layer_2, byvarn_in) - expect_equivalent(adsl_2$ord_layer_1, bycount_out) - expect_equivalent(adsl_2$ord_layer_2, bycount_in) - expect_equivalent(adsl_3$ord_layer_1, byfactor_out) - expect_equivalent(adsl_3$ord_layer_2, byfactor_in) + expect_equal(adsl_1$ord_layer_1, byvarn_out, ignore_attr = TRUE) + expect_equal(adsl_1$ord_layer_2, byvarn_in, ignore_attr = TRUE) + expect_equal(adsl_2$ord_layer_1, bycount_out, ignore_attr = TRUE) + expect_equal(adsl_2$ord_layer_2, bycount_in, ignore_attr = TRUE) + expect_equal(adsl_3$ord_layer_1, byfactor_out, ignore_attr = TRUE) + expect_equal(adsl_3$ord_layer_2, byfactor_in, ignore_attr = TRUE) }) diff --git a/tests/testthat/test-table.R b/tests/testthat/test-table.R index d35b22ab..0ad6340b 100644 --- a/tests/testthat/test-table.R +++ b/tests/testthat/test-table.R @@ -21,7 +21,7 @@ test_that("tplyr_table comes with empty list binded on 'layers'", { ### Errors ### test_that("tplyr_table throws error when passed a bad table argument", { - expect_error(tplyr_table(matrix(a = 1:10, b = 11:20), a)) + expect_snapshot_error(tplyr_table(matrix(a = 1:10, b = 11:20), a)) expect_silent(tplyr_table(data.frame(a = 1:10, b = 11:20), a)) }) @@ -31,7 +31,7 @@ test_that("Table level where clauses with invalid syntax give informative error" group_desc(drat) ) - expect_error(build(t), "tplyr_table `where` condition `bad == code` is invalid.") + expect_snapshot_error(build(t)) }) test_that("Population data where clauses with invalid syntax give informative error", { @@ -42,5 +42,5 @@ test_that("Population data where clauses with invalid syntax give informative er group_desc(drat) ) - expect_error(build(t), "Population data `pop_where` condition `bad == code` is invalid.") + expect_snapshot_error(build(t)) }) diff --git a/tests/testthat/test-table_bindings.R b/tests/testthat/test-table_bindings.R index 1dc314ae..d9a77603 100644 --- a/tests/testthat/test-table_bindings.R +++ b/tests/testthat/test-table_bindings.R @@ -7,22 +7,22 @@ test_that("pop_data binding attaches pop_data properly", { tab <- tplyr_table(df, a) # Changed to equivalent due to attribute change in constructor. - expect_equivalent(pop_data(tab), df) + expect_equal(pop_data(tab), df, ignore_attr = TRUE) pop_data(tab) <- iris - expect_equivalent(pop_data(tab), iris) + expect_equal(pop_data(tab), iris, ignore_attr = TRUE) tab <- set_pop_data(tab , mtcars) - expect_equivalent(pop_data(tab), mtcars) + expect_equal(pop_data(tab), mtcars, ignore_attr = TRUE) }) test_that("pop_data binding throws expected errors", { tab <- tplyr_table(data.frame(a = 1:10, b = 11:20), a) - expect_error(pop_data(tab) <- "a", "'pop_data' argument passed") - expect_error(pop_data(tab) <- iris3, "'pop_data' argument passed") - expect_error(pop_data(tab) <- NA, "'pop_data' argument passed") - expect_error(pop_data(tab) <- NULL, "'pop_data' argument passed") + expect_snapshot_error(pop_data(tab) <- "a") + expect_snapshot_error(pop_data(tab) <- iris3) + expect_snapshot_error(pop_data(tab) <- NA) + expect_snapshot_error(pop_data(tab) <- NULL) expect_silent(pop_data(tab) <- iris) }) @@ -39,9 +39,9 @@ test_that("treat_var binding attaches treat_var properly", { test_that("treat_var throws errors as expected", { tab <- tplyr_table(data.frame(a = 1:10, b = 11:20), a) - expect_error(set_treat_var(tab, c),"treat_var column not found in target dataset") - expect_error(set_treat_var(tab, A), "treat_var column not found in target dataset") - expect_error(set_treat_var(tab), "A treat_var argument must be supplied") + expect_snapshot_error(set_treat_var(tab, c)) + expect_snapshot_error(set_treat_var(tab, A)) + expect_snapshot_error(set_treat_var(tab)) expect_silent(set_treat_var(tab, b)) }) @@ -60,9 +60,9 @@ test_that("pop_treat_var throws errors as expected", { tab <- tplyr_table(data.frame(a = 1:10, b = 11:20), a) %>% set_pop_data(data.frame(d = 21:30)) - expect_error(set_pop_treat_var(tab, a), "pop_treat_var passed to tplyr_table is not a column of pop_data") - expect_error(set_pop_treat_var(tab, A), "pop_treat_var passed to tplyr_table is not a column of pop_data") - expect_error(set_pop_treat_var(tab), "pop_treat_var passed to tplyr_table is not a column of pop_data") + expect_snapshot_error(set_pop_treat_var(tab, a)) + expect_snapshot_error(set_pop_treat_var(tab, A)) + expect_snapshot_error(set_pop_treat_var(tab)) expect_silent(set_pop_treat_var(tab, d)) }) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 8d531af2..79a97d53 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -1,8 +1,7 @@ -context('utils.R') ## modify_nested_call ---- test_that("Call must be quoted", { - expect_error(Tplyr:::modify_nested_call(mean(c(1,2,3))), "`call` must be a quoted call") + expect_snapshot_error(Tplyr:::modify_nested_call(mean(c(1,2,3)))) c <- quo(tplyr_table(treat_var = Species)) expect_silent(Tplyr:::modify_nested_call(c)) }) @@ -16,7 +15,7 @@ test_that("With no additional parameters, a call returns unchanged", { test_that("By default, only `Tplyr` exported functions are allowed", { # Non-tplyr function c <- quo(mean(c(1,2,3))) - expect_error(Tplyr:::modify_nested_call(c), "Functions called within `add_layer` must be part of `Tplyr`") + expect_snapshot_error(Tplyr:::modify_nested_call(c)) # Non-exported Tplyr function # c <- quo(Tplyr:::modify_nested_call(quo(x %>% y))) @@ -74,14 +73,14 @@ test_that("Apply row masks errors trigger properly", { build() # Non-variable names - expect_error(apply_row_masks(t, row_breaks=TRUE, x+y), "All parameters submitted through") - expect_error(apply_row_masks(t, row_breaks=TRUE, "hello"), "All parameters submitted through") + expect_snapshot_error(apply_row_masks(t, row_breaks=TRUE, x+y)) + expect_snapshot_error(apply_row_masks(t, row_breaks=TRUE, "hello")) # Variable not included - expect_error(apply_row_masks(t, row_breaks=TRUE, ord_bad_name), "If \\`row_breaks\\` is specified, variables submitted") - expect_error(apply_row_masks(t, row_breaks=TRUE, ord_bad_name, ord_other_bad_name), "If \\`row_breaks\\` is specified, variables submitted") + expect_snapshot_error(apply_row_masks(t, row_breaks=TRUE, ord_bad_name)) + expect_snapshot_error(apply_row_masks(t, row_breaks=TRUE, ord_bad_name, ord_other_bad_name)) # Variables submitted must be ord variables in the build dataset - expect_error(apply_row_masks(t, row_breaks=TRUE, row_label1), "Break-by variables submitted via") - expect_error(apply_row_masks(t, row_breaks=TRUE, row_label1, var1_3), "Break-by variables submitted via") + expect_snapshot_error(apply_row_masks(t, row_breaks=TRUE, row_label1)) + expect_snapshot_error(apply_row_masks(t, row_breaks=TRUE, row_label1, var1_3)) }) From 174aeed5c03c1dad6be8484da4ed02af83176a18 Mon Sep 17 00:00:00 2001 From: elimillera Date: Thu, 27 Jan 2022 14:04:12 +0000 Subject: [PATCH 2/3] Update snapshots for packages updates --- tests/testthat/_snaps/count.md | 3 +-- tests/testthat/_snaps/desc.md | 3 +-- tests/testthat/_snaps/format.md | 2 +- tests/testthat/_snaps/functional.md | 2 -- tests/testthat/_snaps/pop_data.md | 2 +- tests/testthat/_snaps/shift.md | 3 +-- tests/testthat/_snaps/table.md | 16 ++++++++++++++ tests/testthat/_snaps/utils.md | 34 +++++++++++++++++++++++++++++ 8 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 tests/testthat/_snaps/utils.md diff --git a/tests/testthat/_snaps/count.md b/tests/testthat/_snaps/count.md index 3bfc719f..1c7b4b24 100644 --- a/tests/testthat/_snaps/count.md +++ b/tests/testthat/_snaps/count.md @@ -1,8 +1,7 @@ # Count layer clauses with invalid syntax give informative error group_count `where` condition `bad == code` is invalid. Filter error: - Error in `h()`: - ! Problem with `filter()` input `..1`. + Error: Problem with `filter()` input `..1`. i Input `..1` is `bad == code`. x object 'bad' not found diff --git a/tests/testthat/_snaps/desc.md b/tests/testthat/_snaps/desc.md index ffd5558a..fa76d0c6 100644 --- a/tests/testthat/_snaps/desc.md +++ b/tests/testthat/_snaps/desc.md @@ -1,8 +1,7 @@ # Desc layer clauses with invalid syntax give informative error group_desc `where` condition `bad == code` is invalid. Filter error: - Error in `h()`: - ! Problem with `filter()` input `..1`. + Error: Problem with `filter()` input `..1`. i Input `..1` is `bad == code`. x object 'bad' not found diff --git a/tests/testthat/_snaps/format.md b/tests/testthat/_snaps/format.md index fdb9f303..ac3d4208 100644 --- a/tests/testthat/_snaps/format.md +++ b/tests/testthat/_snaps/format.md @@ -1,6 +1,6 @@ # Format string must be character - Argument `format_string` must be character. Instead a class of "numeric" was passed. + Argument `format_string` in function `f_str` must be character. Instead a class of "numeric" was passed. # Error is thrown when format doesn't match variables diff --git a/tests/testthat/_snaps/functional.md b/tests/testthat/_snaps/functional.md index 0b6afe18..f457ddb5 100644 --- a/tests/testthat/_snaps/functional.md +++ b/tests/testthat/_snaps/functional.md @@ -3,6 +3,4 @@ Problem with `mutate()` column `col_i`. i `col_i = fct_expand(...)`. x object 'col_i' not found - Caused by error: - ! object 'col_i' not found diff --git a/tests/testthat/_snaps/pop_data.md b/tests/testthat/_snaps/pop_data.md index ed89efa6..85a13369 100644 --- a/tests/testthat/_snaps/pop_data.md +++ b/tests/testthat/_snaps/pop_data.md @@ -8,5 +8,5 @@ # add_total_group errors function properly - Argument `group_name` must be character. Instead a class of "numeric" was passed. + Argument `group_name` in function `add_total_group` must be character. Instead a class of "numeric" was passed. diff --git a/tests/testthat/_snaps/shift.md b/tests/testthat/_snaps/shift.md index 7ff62c37..0364ae52 100644 --- a/tests/testthat/_snaps/shift.md +++ b/tests/testthat/_snaps/shift.md @@ -1,8 +1,7 @@ # Shift layer clauses with invalid syntax give informative error group_shift `where` condition `bad == code` is invalid. Filter error: - Error in `h()`: - ! Problem with `filter()` input `..1`. + Error: Problem with `filter()` input `..1`. i Input `..1` is `bad == code`. x object 'bad' not found diff --git a/tests/testthat/_snaps/table.md b/tests/testthat/_snaps/table.md index fc50f6aa..175c0d57 100644 --- a/tests/testthat/_snaps/table.md +++ b/tests/testthat/_snaps/table.md @@ -2,3 +2,19 @@ unused argument (a = 1:10) +# Table level where clauses with invalid syntax give informative error + + tplyr_table `where` condition `bad == code` is invalid. Filter error: + Error: Problem with `filter()` input `..1`. + i Input `..1` is `bad == code`. + x object 'bad' not found + + +# Population data where clauses with invalid syntax give informative error + + Population data `pop_where` condition `bad == code` is invalid. Filter error: + Error: Problem with `filter()` input `..1`. + i Input `..1` is `bad == code`. + x object 'bad' not found + If the population data and target data subsets should be different, use `set_pop_where`. + diff --git a/tests/testthat/_snaps/utils.md b/tests/testthat/_snaps/utils.md new file mode 100644 index 00000000..d1bfae74 --- /dev/null +++ b/tests/testthat/_snaps/utils.md @@ -0,0 +1,34 @@ +# Call must be quoted + + `call` must be a quoted call + +# By default, only `Tplyr` exported functions are allowed + + Functions called within `add_layer` must be part of `Tplyr` + +# Apply row masks errors trigger properly + + All parameters submitted through `...` must be variable names + +--- + + All parameters submitted through `...` must be variable names + +--- + + If `row_breaks` is specified, variables submitted via `...` must be `ord` variables included in the input data frame. + Remember to sort prior to using `apply_row_masks`. + +--- + + If `row_breaks` is specified, variables submitted via `...` must be `ord` variables included in the input data frame. + Remember to sort prior to using `apply_row_masks`. + +--- + + Break-by variables submitted via `...` must be 'Tplyr' order variables that start with `ord` + +--- + + Break-by variables submitted via `...` must be 'Tplyr' order variables that start with `ord` + From c298bc62d6ec487111cdfd19769805a96e927a54 Mon Sep 17 00:00:00 2001 From: elimillera Date: Thu, 27 Jan 2022 14:18:17 +0000 Subject: [PATCH 3/3] Wrong version of Rlang used. Updated --- tests/testthat/_snaps/count.md | 3 ++- tests/testthat/_snaps/desc.md | 3 ++- tests/testthat/_snaps/format.md | 2 +- tests/testthat/_snaps/functional.md | 2 ++ tests/testthat/_snaps/pop_data.md | 2 +- tests/testthat/_snaps/shift.md | 3 ++- tests/testthat/_snaps/table.md | 6 ++++-- tests/testthat/_snaps/utils.md | 2 +- 8 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/testthat/_snaps/count.md b/tests/testthat/_snaps/count.md index 1c7b4b24..3bfc719f 100644 --- a/tests/testthat/_snaps/count.md +++ b/tests/testthat/_snaps/count.md @@ -1,7 +1,8 @@ # Count layer clauses with invalid syntax give informative error group_count `where` condition `bad == code` is invalid. Filter error: - Error: Problem with `filter()` input `..1`. + Error in `h()`: + ! Problem with `filter()` input `..1`. i Input `..1` is `bad == code`. x object 'bad' not found diff --git a/tests/testthat/_snaps/desc.md b/tests/testthat/_snaps/desc.md index fa76d0c6..ffd5558a 100644 --- a/tests/testthat/_snaps/desc.md +++ b/tests/testthat/_snaps/desc.md @@ -1,7 +1,8 @@ # Desc layer clauses with invalid syntax give informative error group_desc `where` condition `bad == code` is invalid. Filter error: - Error: Problem with `filter()` input `..1`. + Error in `h()`: + ! Problem with `filter()` input `..1`. i Input `..1` is `bad == code`. x object 'bad' not found diff --git a/tests/testthat/_snaps/format.md b/tests/testthat/_snaps/format.md index ac3d4208..fdb9f303 100644 --- a/tests/testthat/_snaps/format.md +++ b/tests/testthat/_snaps/format.md @@ -1,6 +1,6 @@ # Format string must be character - Argument `format_string` in function `f_str` must be character. Instead a class of "numeric" was passed. + Argument `format_string` must be character. Instead a class of "numeric" was passed. # Error is thrown when format doesn't match variables diff --git a/tests/testthat/_snaps/functional.md b/tests/testthat/_snaps/functional.md index f457ddb5..0b6afe18 100644 --- a/tests/testthat/_snaps/functional.md +++ b/tests/testthat/_snaps/functional.md @@ -3,4 +3,6 @@ Problem with `mutate()` column `col_i`. i `col_i = fct_expand(...)`. x object 'col_i' not found + Caused by error: + ! object 'col_i' not found diff --git a/tests/testthat/_snaps/pop_data.md b/tests/testthat/_snaps/pop_data.md index 85a13369..ed89efa6 100644 --- a/tests/testthat/_snaps/pop_data.md +++ b/tests/testthat/_snaps/pop_data.md @@ -8,5 +8,5 @@ # add_total_group errors function properly - Argument `group_name` in function `add_total_group` must be character. Instead a class of "numeric" was passed. + Argument `group_name` must be character. Instead a class of "numeric" was passed. diff --git a/tests/testthat/_snaps/shift.md b/tests/testthat/_snaps/shift.md index 0364ae52..7ff62c37 100644 --- a/tests/testthat/_snaps/shift.md +++ b/tests/testthat/_snaps/shift.md @@ -1,7 +1,8 @@ # Shift layer clauses with invalid syntax give informative error group_shift `where` condition `bad == code` is invalid. Filter error: - Error: Problem with `filter()` input `..1`. + Error in `h()`: + ! Problem with `filter()` input `..1`. i Input `..1` is `bad == code`. x object 'bad' not found diff --git a/tests/testthat/_snaps/table.md b/tests/testthat/_snaps/table.md index 175c0d57..1340c97a 100644 --- a/tests/testthat/_snaps/table.md +++ b/tests/testthat/_snaps/table.md @@ -5,7 +5,8 @@ # Table level where clauses with invalid syntax give informative error tplyr_table `where` condition `bad == code` is invalid. Filter error: - Error: Problem with `filter()` input `..1`. + Error in `h()`: + ! Problem with `filter()` input `..1`. i Input `..1` is `bad == code`. x object 'bad' not found @@ -13,7 +14,8 @@ # Population data where clauses with invalid syntax give informative error Population data `pop_where` condition `bad == code` is invalid. Filter error: - Error: Problem with `filter()` input `..1`. + Error in `h()`: + ! Problem with `filter()` input `..1`. i Input `..1` is `bad == code`. x object 'bad' not found If the population data and target data subsets should be different, use `set_pop_where`. diff --git a/tests/testthat/_snaps/utils.md b/tests/testthat/_snaps/utils.md index d1bfae74..cedc4256 100644 --- a/tests/testthat/_snaps/utils.md +++ b/tests/testthat/_snaps/utils.md @@ -1,6 +1,6 @@ # Call must be quoted - `call` must be a quoted call + `call` must be a defused call, not a number. # By default, only `Tplyr` exported functions are allowed