Skip to content

Commit

Permalink
Add test that confirms config files with 1 target_keys key value pair…
Browse files Browse the repository at this point in the history
… do not pass validation. Resolves #89
  • Loading branch information
annakrystalli committed Dec 18, 2024
1 parent ac8f7bc commit fec895a
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/testthat/test-validate_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,22 @@ test_that("v4 validation works", {
)
)
})

test_that("target keys with 2 properties throws error", {
skip_if_offline()
config_path <- testthat::test_path("testdata", "v4.0.1-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"
)
)
expect_false(out)

expect_equal(
unique(attr(out, "errors")$message),
"must NOT have more than 1 items"
)
expect_equal(nrow(attr(out, "errors")), 2L)
})
164 changes: 164 additions & 0 deletions tests/testthat/testdata/v4.0.1-tasks-2-target_keys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
{
"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": {
"target": "wk ahead inc",
"target_metric": "flu hosp"
},
"target_type": "discrete",
"description": "This target represents the counts of new hospitalizations per horizon week.",
"is_step_ahead": true,
"time_unit": "week"
}]
}, {
"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 flu hosp"]
},
"target_metric": {
"required": null,
"optional": ["rate change"]
},
"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": {
"pmf": {
"output_type_id": {
"required": ["large_decrease", "decrease", "stable", "increase", "large_increase"]
},
"is_required": false,
"value": {
"type": "double",
"minimum": 0,
"maximum": 1
}
}
},
"target_metadata": [{
"target_id": "wk flu hosp rate change",
"target_name": "weekly influenza hospitalization rate change",
"target_units": "rate per 100,000 population",
"target_keys": {
"target": "wk flu hosp",
"target_metric": "rate change"
},
"target_type": "nominal",
"description": "This target represents the change in the rate of new hospitalizations per week comparing the week ending two days prior to the forecast_date to the week ending h weeks after the forecast_date.",
"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 fec895a

Please sign in to comment.