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

upgrade schema version to v5.0.0 #92

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

* Use options to set `schema_version` and `branch` arguments in `download_tasks_schema()` and the `create_*()` family of functions for creating config files programmatically. This allows for setting the schema version and branch globally for the session (#85).
* Make validation of `round_id` patterns explicit. This ties in with schema version v4.0.1 where the pattern the `round_id` property must match if `round_id_from_variable` is `false` is now specified as a regular expression in the schema. This check is also now implemented dynamically on values of the `round_id` variable if `round_id_from_variable` is `true` when validating tasks.json config files. Checks on `round_id` patterns are also now implemented in `create_round()` when creating rounds programmatically.
* As of schema version v4.0.1, only a single `target_keys` element is allowed when creating target metadata items programmatically (#89).
* As of schema version v5.0.0, only a single `target_keys` element is allowed when creating target metadata items programmatically (#89).

# hubAdmin 1.4.0

Expand Down
17 changes: 9 additions & 8 deletions R/create_target_metadata_item.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
#' @param target_units character string. Unit of observation of the target.
#' @param target_keys named list or `NULL`. The `target_keys` value defines a
#' single target.
#' Should be `NULL` in the case where the target is not specified as a task_id
#' Should be a named list containing a single character string element.
#' The name of the element should match a `task_id` variable name within the same
#' `model_tasks` object and the value should match a single value of that variable
#' as described in
#' [target metadata section of the official hubverse documentation](https://hubverse.io/en/latest/user-guide/tasks.html#target-metadata). # nolint: line_length_linter
#' Otherwise, `NULL` in the case where the target is not specified as a task_id
#' but is specified solely through the `target_id` argument.
#' Otherwise, should be a named list containing a single character string element.
#' The name of the element should match a `task_id`
#' variable name within the same `model_tasks` object and the value should match
#' a single value of that variable as described in [target metadata section of the official hubverse documentation](https://hubverse.io/en/latest/user-guide/tasks.html#target-metadata).
#' @param description character string (optional). An optional verbose description
#' of the target that might include information such as definitions of a 'rate' or similar.
#' @param target_type character string. Target statistical data type. Consult the
Expand Down Expand Up @@ -154,12 +155,12 @@ check_target_keys <- function(target_keys, schema_version,
call = call
)
}
is_gte_v4_0_1 <- hubUtils::version_gte(
"v4.0.1",
is_gte_v5_0_0 <- hubUtils::version_gte(
"v5.0.0",
schema_version = schema_version
)
target_key_n <- length(target_keys)
if (is_gte_v4_0_1 && target_key_n > 1L) {
if (is_gte_v5_0_0 && target_key_n > 1L) {
cli::cli_abort(
c(
"!" = "{.arg target_keys} must be a named {.cls list} of
Expand Down
1 change: 1 addition & 0 deletions hubAdmin.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: a853e49a-e7e8-463b-96b8-8c69e98c0382

RestoreWorkspace: No
SaveWorkspace: No
Expand Down
13 changes: 7 additions & 6 deletions man/create_target_metadata_item.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/create_target_metadata_item.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
- "https://raw.githubusercontent.com/hubverse-org/schemas/main/v3.0.1/tasks-schema.json"
+ "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.0/tasks-schema.json"

# Target_keys of length more than 1 are not allowed post v4.0.1
# Target_keys of length more than 1 are not allowed post v5.0.0

Code
create_target_metadata_item(target_id = "flu inc hosp", target_name = "Weekly incident influenza hospitalizations",
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-create_round.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ test_that("validating round_id patterns when round_id_from_var = TRUE works", {
skip_if_offline()
withr::with_options(
list(
hubAdmin.schema_version = "v4.0.1",
hubAdmin.branch = "br-v4.0.1"
hubAdmin.schema_version = "v5.0.0",
hubAdmin.branch = "br-v5.0.0"
),
{
output_types <- create_output_type(
Expand Down Expand Up @@ -372,8 +372,8 @@ test_that("validating round_id pattern when round_id_from_var = FALSE works", {
skip_if_offline()
withr::with_options(
list(
hubAdmin.schema_version = "v4.0.1",
hubAdmin.branch = "br-v4.0.1"
hubAdmin.schema_version = "v5.0.0",
hubAdmin.branch = "br-v5.0.0"
),
{
output_types <- create_output_type(
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-create_target_metadata_item.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,16 @@ test_that("schema version option works for create_target_metadata_item", {
expect_snapshot(waldo::compare(opt_version, version_default))
})

test_that("Target_keys of length more than 1 are not allowed post v4.0.1", {
test_that("Target_keys of length more than 1 are not allowed post v5.0.0", {
skip_if_offline()
withr::with_options(
list(
hubAdmin.schema_version = "v4.0.1",
# TDOD: remove branch argument when v4.0.1 is released.
hubAdmin.branch = "ak/v4.0.1/restrict-target-key-value-pair-n/117"
hubAdmin.schema_version = "v5.0.0",
# TDOD: remove branch argument when v5.0.0 is released.
hubAdmin.branch = "br-v5.0.0"
),
{
# One target_key is allowed in v4.0.1 and later versions.
# One target_key is allowed in v5.0.0 and later versions.
target_keys_n1 <- create_target_metadata_item(
target_id = "inc hosp",
target_name = "Weekly incident influenza hospitalizations",
Expand All @@ -171,7 +171,7 @@ test_that("Target_keys of length more than 1 are not allowed post v4.0.1", {
expect_s3_class(target_keys_n1, "target_metadata_item")
expect_length(target_keys_n1$target_keys, 1L)

# More than one target_key is NOT allowed in v4.0.1 and later versions
# More than one target_key is NOT allowed in v5.0.0 and later versions
# and throws error.
expect_snapshot(
create_target_metadata_item(
Expand Down
30 changes: 15 additions & 15 deletions tests/testthat/test-validate_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,14 @@ test_that("v4 validation works", {
})


test_that("v4.0.1 target keys with 2 properties throws error", {
test_that("v5.0.0 target keys with 2 properties throws error", {
skip_if_offline()
config_path <- testthat::test_path("testdata", "v4.0.1-tasks-2-target_keys.json")
config_path <- testthat::test_path("testdata", "v5.0.0-tasks-2-target_keys.json")
out <- suppressMessages(
validate_config(
config_path = config_path,
# TDOD: remove branch argument when v4.0.1 is released.
branch = "ak/v4.0.1/restrict-target-key-value-pair-n/117"
# TDOD: remove branch argument when v5.0.0 is released.
branch = "br-v5.0.0"
)
)
expect_false(out)
Expand All @@ -272,23 +272,23 @@ test_that("v4.0.1 target keys with 2 properties throws error", {
expect_equal(nrow(attr(out, "errors")), 2L)
})

test_that("v4.0.1 target keys with NULL properties passes", {
test_that("v5.0.0 target keys with NULL properties passes", {
# Ensure NULL target keys are still allowed.
config_path <- testthat::test_path("testdata", "v4.0.1-tasks-null-target_keys.json")
config_path <- testthat::test_path("testdata", "v5.0.0-tasks-null-target_keys.json")
out <- suppressMessages(
validate_config(
config_path = config_path,
# TDOD: remove branch argument when v4.0.1 is released.
branch = "ak/v4.0.1/restrict-target-key-value-pair-n/117"
# TDOD: remove branch argument when v5.0.0 is released.
branch = "br-v5.0.0"
)
)
expect_true(out)
})

test_that("v4.0.1 round_id pattern validation works", {
test_that("v5.0.0 round_id pattern validation works", {
skip_if_offline()
# TODO: remove branch argument when v4.0.1 is released.
schema <- download_tasks_schema("v4.0.1", branch = "br-v4.0.1")
# TODO: remove branch argument when v5.0.0 is released.
schema <- download_tasks_schema("v5.0.0", branch = "br-v5.0.0")

# Test that regex pattern matching for round_id properties in jsonvalidate
# identifies expected errors (when round_id_from_variable: false).
Expand All @@ -297,9 +297,9 @@ test_that("v4.0.1 round_id pattern validation works", {
validate_config(
config_path = testthat::test_path(
"testdata",
"v4.0.1-tasks-fail-round-id-pattern.json"
"v5.0.0-tasks-fail-round-id-pattern.json"
),
branch = "br-v4.0.1"
branch = "br-v5.0.0"
)
)
)
Expand All @@ -325,9 +325,9 @@ test_that("v4.0.1 round_id pattern validation works", {
validate_config(
config_path = testthat::test_path(
"testdata",
"v4.0.1-tasks-fail-round-id-val-pattern.json"
"v5.0.0-tasks-fail-round-id-val-pattern.json"
),
branch = "br-v4.0.1"
branch = "br-v5.0.0"
)
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.1/tasks-schema.json",
"schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v5.0.0/tasks-schema.json",
"rounds": [{
"round_id_from_variable": true,
"round_id": "forecast_date",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.1/tasks-schema.json",
"schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v5.0.0/tasks-schema.json",
"rounds": [{
"round_id_from_variable": true,
"round_id": "round_id_var",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.1/tasks-schema.json",
"schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v5.0.0/tasks-schema.json",
"rounds": [{
"round_id_from_variable": true,
"round_id": "round_id_var",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.1/tasks-schema.json",
"schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v5.0.0/tasks-schema.json",
"rounds": [{
"round_id_from_variable": true,
"round_id": "forecast_date",
Expand Down
Loading