From be5306627d01ee129604094fc20c791fc6cf387f Mon Sep 17 00:00:00 2001 From: Anna Krystalli Date: Tue, 19 Sep 2023 11:12:25 +0300 Subject: [PATCH] add additional test --- tests/testthat/_snaps/validate_submission.md | 69 ++++++++++++++++++++ tests/testthat/test-validate_submission.R | 19 +++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/validate_submission.md b/tests/testthat/_snaps/validate_submission.md index 205f707c..9b275130 100644 --- a/tests/testthat/_snaps/validate_submission.md +++ b/tests/testthat/_snaps/validate_submission.md @@ -131,6 +131,75 @@ ..$ use_cli_format: logi TRUE ..- attr(*, "class")= chr [1:5] "check_error" "hub_check" "rlang_error" "error" ... +--- + + Code + str(validate_submission(hub_path, file_path = "team1-goodmodel/2022-10-15-hub-baseline.csv")) + Output + Classes 'hub_validations', 'list' hidden list of 10 + $ file_exists :List of 4 + ..$ message : chr "File exists at path 'model-output/team1-goodmodel/2022-10-15-hub-baseline.csv'. \n " + ..$ where : chr "team1-goodmodel/2022-10-15-hub-baseline.csv" + ..$ call : chr "check_file_exists" + ..$ use_cli_format: logi TRUE + ..- attr(*, "class")= chr [1:5] "check_success" "hub_check" "rlang_message" "message" ... + $ file_name :List of 4 + ..$ message : chr "File name \"2022-10-15-hub-baseline.csv\" is valid. \n " + ..$ where : chr "team1-goodmodel/2022-10-15-hub-baseline.csv" + ..$ call : chr "check_file_name" + ..$ use_cli_format: logi TRUE + ..- attr(*, "class")= chr [1:5] "check_success" "hub_check" "rlang_message" "message" ... + $ file_location :List of 4 + ..$ message : chr "File directory name must match `model_id`\n metadata in file name. \n"| __truncated__ + ..$ where : chr "team1-goodmodel/2022-10-15-hub-baseline.csv" + ..$ call : chr "check_file_location" + ..$ use_cli_format: logi TRUE + ..- attr(*, "class")= chr [1:5] "check_failure" "hub_check" "rlang_warning" "warning" ... + $ round_id_valid :List of 4 + ..$ message : chr "`round_id` is valid. \n " + ..$ where : chr "team1-goodmodel/2022-10-15-hub-baseline.csv" + ..$ call : chr "check_valid_round_id" + ..$ use_cli_format: logi TRUE + ..- attr(*, "class")= chr [1:5] "check_success" "hub_check" "rlang_message" "message" ... + $ file_format :List of 4 + ..$ message : chr "File is accepted hub format. \n " + ..$ where : chr "team1-goodmodel/2022-10-15-hub-baseline.csv" + ..$ call : chr "check_file_format" + ..$ use_cli_format: logi TRUE + ..- attr(*, "class")= chr [1:5] "check_success" "hub_check" "rlang_message" "message" ... + $ metadata_exists :List of 4 + ..$ message : chr "Metadata file exists at path 'model-metadata/hub-baseline.yml'. \n " + ..$ where : chr "team1-goodmodel/2022-10-15-hub-baseline.csv" + ..$ call : chr "check_submission_metadata_file_exists" + ..$ use_cli_format: logi TRUE + ..- attr(*, "class")= chr [1:5] "check_success" "hub_check" "rlang_message" "message" ... + $ file_read :List of 4 + ..$ message : chr "File could be read successfully. \n " + ..$ where : chr "team1-goodmodel/2022-10-15-hub-baseline.csv" + ..$ call : chr "check_file_read" + ..$ use_cli_format: logi TRUE + ..- attr(*, "class")= chr [1:5] "check_success" "hub_check" "rlang_message" "message" ... + $ valid_round_id_col:List of 4 + ..$ message : chr "`round_id_col` name is valid. \n " + ..$ where : chr "team1-goodmodel/2022-10-15-hub-baseline.csv" + ..$ call : chr "check_valid_round_id_col" + ..$ use_cli_format: logi TRUE + ..- attr(*, "class")= chr [1:5] "check_success" "hub_check" "rlang_message" "message" ... + $ unique_round_id :List of 4 + ..$ message : chr "`round_id` column \"origin_date\" contains a single, unique round ID value. \n " + ..$ where : chr "team1-goodmodel/2022-10-15-hub-baseline.csv" + ..$ call : chr "check_tbl_unique_round_id" + ..$ use_cli_format: logi TRUE + ..- attr(*, "class")= chr [1:5] "check_success" "hub_check" "rlang_message" "message" ... + $ colnames :List of 6 + ..$ message : chr "Column names must be consistent with expected round task IDs and std column names. \n Expected column \"age_gro"| __truncated__ + ..$ trace : NULL + ..$ parent : NULL + ..$ where : chr "team1-goodmodel/2022-10-15-hub-baseline.csv" + ..$ call : chr "check_tbl_colnames" + ..$ use_cli_format: logi TRUE + ..- attr(*, "class")= chr [1:5] "check_error" "hub_check" "rlang_error" "error" ... + --- Code diff --git a/tests/testthat/test-validate_submission.R b/tests/testthat/test-validate_submission.R index 4c4fb5b1..ada14320 100644 --- a/tests/testthat/test-validate_submission.R +++ b/tests/testthat/test-validate_submission.R @@ -16,7 +16,8 @@ test_that("validate_submission works", { c("hub_validations", "list") ) - # File with validation error + # File with validation error ---- + # Missing file expect_snapshot( str( validate_submission(hub_path, @@ -31,6 +32,22 @@ test_that("validate_submission works", { c("hub_validations", "list") ) + # Wrong submission location & missing data column (age_group) + expect_snapshot( + str( + validate_submission(hub_path, + file_path = "team1-goodmodel/2022-10-15-hub-baseline.csv" + ) + ) + ) + expect_s3_class( + validate_submission(hub_path, + file_path = "team1-goodmodel/2022-10-15-hub-baseline.csv" + ), + c("hub_validations", "list") + ) + + expect_snapshot( str( validate_submission(