Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change check fail class and print method #114

Merged
merged 19 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: hubValidations
Title: Testing framework for hubverse hub validations
Version: 0.5.1
Version: 0.6.0
Authors@R: c(
person(
given = "Anna",
Expand Down Expand Up @@ -44,7 +44,6 @@ Imports:
jsonvalidate,
lubridate,
magrittr,
octolog,
purrr,
rlang,
stringr,
Expand All @@ -63,13 +62,12 @@ Suggests:
Remotes:
hubverse-org/hubUtils,
hubverse-org/hubData,
hubverse-org/hubAdmin,
assignUser/octolog
hubverse-org/hubAdmin
Config/testthat/edition: 3
Config/Needs/website: pkgdown, hubverse-org/hubStyle
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
URL: https://github.com/hubverse-org/hubValidations,
https://hubverse-org.github.io/hubValidations/
BugReports: https://github.com/hubverse-org/hubValidations/issues
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# hubValidations 0.6.0

* To make clearer that all checks resulting in `check_failure` are required to pass for files to be considered valid, `check_failure` class objects are elevated to errors (#111). Also, to make it easier for users to identify errors from visually scanning the printed output, the following custom bullets have been assigned.
- `✖` : `check_failure` class object. This indicates an error that does not impact the validation process.
- `ⓧ` : `check_error` class object. This also indicates early termination of the validation process.
- `☒` : `check_exec_error` class object. This indicates an error in the execution of a check function.
* `octolog` dependency removed. This removes the annotation of validation results onto GitHub Action workflow logs (#113).

# hubValidations 0.5.1

* Remove dependency on development version of `arrow` package and bump required version to 17.0.0.
Expand Down
6 changes: 3 additions & 3 deletions R/capture_check_cnd.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' the state when validation succeeds, the second element, when validation fails.
#' @param error logical. In the case of validation failure, whether the function
#' should return an object of class `<error/check_error>` (`TRUE`) or
#' `<warning/check_failure>` (`FALSE`, default).
#' `<error/check_failure>` (`FALSE`, default).
#' @param details further details to be appended to the output message.
#' @inheritParams rlang::error_cnd
#'
Expand All @@ -22,7 +22,7 @@
#' @return Depending on whether validation has succeeded and the value
#' of the `error` argument, one of:
#' - `<message/check_success>` condition class object.
#' - `<warning/check_failure>` condition class object.
#' - `<error/check_failure>` condition class object.
#' - `<error/check_error>` condition class object.
#'
#' Returned object also inherits from subclass `<hub_check>`.
Expand Down Expand Up @@ -82,7 +82,7 @@ capture_check_cnd <- function(check, file_path, msg_subject, msg_attribute,
use_cli_format = TRUE
)
} else {
res <- rlang::warning_cnd(
res <- rlang::error_cnd(
c("check_failure", "hub_check"),
where = file_path,
...,
Expand Down
2 changes: 1 addition & 1 deletion R/check_tbl_col_types.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @return
#' Depending on whether validation has succeeded, one of:
#' - `<message/check_success>` condition class object.
#' - `<warning/check_failure>` condition class object.
#' - `<error/check_failure>` condition class object.
#'
#' Returned object also inherits from subclass `<hub_check>`.
#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/check_tbl_unique_round_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @return
#' Depending on whether validation has succeeded, one of:
#' - `<message/check_success>` condition class object.
#' - `<warning/check_error>` condition class object.
#' - `<error/check_error>` condition class object.
#'
#' If `round_id_from_variable: false` and no `round_id_col` name is provided,
#' check is skipped and a `<message/check_info>` condition class object is
Expand Down
29 changes: 24 additions & 5 deletions R/hub_validations_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ print.hub_validations <- function(x, ...) {
),
dplyr::case_when(
purrr::map_lgl(x, ~ rlang::inherits_any(.x, "check_success")) ~ "v",
purrr::map_lgl(x, ~ rlang::inherits_any(.x, "check_failure")) ~ "!",
purrr::map_lgl(x, ~ rlang::inherits_any(.x, "check_failure")) ~ "x",
purrr::map_lgl(x, ~ rlang::inherits_any(.x, "check_exec_warn")) ~ "!",
purrr::map_lgl(x, ~ rlang::inherits_any(.x, "check_error")) ~ "x",
purrr::map_lgl(x, ~ rlang::inherits_any(.x, "check_exec_error")) ~ "x",
purrr::map_lgl(x, ~ rlang::inherits_any(.x, "check_error")) ~ "circle_cross",
purrr::map_lgl(x, ~ rlang::inherits_any(.x, "check_exec_error")) ~ "lower_block_8",
purrr::map_lgl(x, ~ rlang::inherits_any(.x, "check_info")) ~ "i",
TRUE ~ "*"
)
)
}

octolog::octo_inform(msg)
cli::cli_div(class = "hub_validations", theme = hub_validation_theme)
cli::cli_inform(msg)
cli::cli_end()
annakrystalli marked this conversation as resolved.
Show resolved Hide resolved
}


Expand Down Expand Up @@ -85,3 +86,21 @@ validate_internal_class <- function(x, class = c(
print.pr_hub_validations <- function(x, ...) {
purrr::map(x, print)
}


# cli theme for hub_validations objects that add a circle cross to be applied
# to check_error objects
hub_validation_theme <- list(
".bullets .bullet-circle_cross" = list(
"before" = function(x) {
paste0(cli::col_red(cli::symbol$circle_cross), " ")
},
"text-exdent" = 2L
),
".bullets .bullet-checkbox_on" = list(
"before" = function(x) {
paste0(cli::col_red(cli::symbol$checkbox_on), " ")
},
"text-exdent" = 2L
)
)
4 changes: 2 additions & 2 deletions man/capture_check_cnd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_file_location.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_metadata_file_ext.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_metadata_file_location.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_metadata_file_name.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_metadata_matches_schema.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_metadata_schema_exists.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_submission_time.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_tbl_col_types.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_tbl_match_round_id.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_tbl_rows_unique.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_tbl_spl_n.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_tbl_unique_round_id.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_tbl_value_col.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_tbl_value_col_ascending.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_tbl_value_col_sum1.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_tbl_values_required.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/opt_check_metadata_team_max_model_n.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/opt_check_tbl_col_timediff.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/opt_check_tbl_counts_lt_popn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/opt_check_tbl_horizon_timediff.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions tests/testthat/_snaps/capture_check_cnd.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
capture_check_cnd(check = FALSE, file_path = "test/file.csv", msg_subject = "{.var round_id}",
msg_attribute = "valid.", error = FALSE, details = "Must be one of {.val {c('A', 'B')}}, not {.val C}")
Output
<warning/check_failure>
Warning:
`round_id` must be valid. Must be one of "A" and "B", not "C"
<error/check_failure>
Error:
! `round_id` must be valid. Must be one of "A" and "B", not "C"

---

Expand Down Expand Up @@ -46,9 +46,9 @@
msg_attribute = "consistent with expected round task IDs and std column names.",
msg_verbs = c("are", "must always be"))
Output
<warning/check_failure>
Warning:
Column names must always be consistent with expected round task IDs and std column names.
<error/check_failure>
Error:
! Column names must always be consistent with expected round task IDs and std column names.

---

Expand All @@ -57,12 +57,14 @@
msg_attribute = "consistent with expected round task IDs and std column names.",
msg_verbs = c("are", "must always be")))
Output
List of 4
List of 6
$ message : chr "Column names must always be consistent with expected round task IDs and std column names. \n "
$ trace : NULL
$ parent : NULL
$ where : chr "test/file.csv"
$ call : chr "eval"
$ use_cli_format: logi TRUE
- attr(*, "class")= chr [1:5] "check_failure" "hub_check" "rlang_warning" "warning" ...
- attr(*, "class")= chr [1:5] "check_failure" "hub_check" "rlang_error" "error" ...

# capture_check_cnd fails correctly

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/check_file_location.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Code
check_file_location("team1-goodmodel/2022-10-08-team2-goodmodel.csv")
Output
<warning/check_failure>
Warning:
File directory name must match `model_id` metadata in file name. File should be submitted to directory "team2-goodmodel" not "team1-goodmodel"
<error/check_failure>
Error:
! File directory name must match `model_id` metadata in file name. File should be submitted to directory "team2-goodmodel" not "team1-goodmodel"

6 changes: 3 additions & 3 deletions tests/testthat/_snaps/check_metadata_file_location.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Code
check_metadata_file_location("random_folder/hub-baseline.yml")
Output
<warning/check_failure>
Warning:
Metadata file directory name must match "model-metadata". Metadata files should be submitted to directory "model-metadata", not "model-metadata/random_folder".
<error/check_failure>
Error:
! Metadata file directory name must match "model-metadata". Metadata files should be submitted to directory "model-metadata", not "model-metadata/random_folder".

Loading
Loading