Skip to content

Commit

Permalink
add test for NULL target keys in v4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
annakrystalli committed Dec 18, 2024
1 parent d5b8201 commit 3feb79b
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/testthat/test-validate_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,15 @@ test_that("target keys with 2 properties throws error", {
"must NOT have more than 1 items"
)
expect_equal(nrow(attr(out, "errors")), 2L)

# Ensure NULL target keys are still allowed.
config_path <- testthat::test_path("testdata", "v4.0.1-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"
)
)
expect_true(out)
})
93 changes: 93 additions & 0 deletions tests/testthat/testdata/v4.0.1-tasks-null-target_keys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"schema_version": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v4.0.1/tasks-schema.json",
"rounds": [{
"round_id_from_variable": true,
"round_id": "forecast_date",
"model_tasks": [{
"task_ids": {
"forecast_date": {
"required": null,
"optional": [
"2022-12-12", "2022-12-19", "2022-12-26", "2023-01-02", "2023-01-09",
"2023-01-16", "2023-01-23", "2023-01-30", "2023-02-06", "2023-02-13",
"2023-02-20", "2023-02-27", "2023-03-06", "2023-03-13", "2023-03-20",
"2023-03-27", "2023-04-03", "2023-04-10", "2023-04-17", "2023-04-24",
"2023-05-01"
]
},
"target": {
"required": null,
"optional": ["wk ahead inc"]
},
"target_metric": {
"required": null,
"optional": ["flu hosp"]
},
"horizon": {
"required": [2],
"optional": [1]
},
"location": {
"required": ["US"],
"optional": [
"01",
"02"
]
},
"target_date": {
"required": null,
"optional": [
"2022-12-19", "2022-12-26", "2023-01-02", "2023-01-09",
"2023-01-16", "2023-01-23", "2023-01-30", "2023-02-06", "2023-02-13",
"2023-02-20", "2023-02-27", "2023-03-06", "2023-03-13", "2023-03-20",
"2023-03-27", "2023-04-03", "2023-04-10", "2023-04-17", "2023-04-24",
"2023-05-01", "2023-05-08", "2023-05-15"
]
}
},
"output_type": {
"sample": {
"output_type_id_params": {
"type": "character",
"min_samples_per_task": 50,
"max_samples_per_task": 100,
"max_length": 10
},
"is_required": true,
"value": {
"type": "integer",
"minimum": 0
}
},
"mean": {
"output_type_id": {
"required": null
},
"is_required": true,
"value": {
"type": "double",
"minimum": 0
}
}
},
"target_metadata": [{
"target_id": "wk ahead inc flu hosp",
"target_name": "weekly influenza hospitalization incidence",
"target_units": "rate per 100,000 population",
"target_keys": null,
"target_type": "discrete",
"description": "This target represents the counts of new hospitalizations per horizon week.",
"is_step_ahead": true,
"time_unit": "week"
}]
}],
"submissions_due": {
"relative_to": "forecast_date",
"start": -6,
"end": 2
},
"derived_task_ids": ["target_date"]
}

]
}

0 comments on commit 3feb79b

Please sign in to comment.