Skip to content

Commit

Permalink
Error if no contexts (#154)
Browse files Browse the repository at this point in the history
Fixing two small tests errors:

    - error is no contexts
    - test for unit_in in unit_conversions.csv isn't correct - we don't expect this behaviour always. (Remove check for units in unit_conversions - this isn't expected. The `unit_in` field can also be a data.csv column. Or there can be units that are used, but happen to not be in the unit_conversions because there aren't any instances where they require converting.)


solves issue #150, noted in issue #146

This branch was mistakenly never merged in and is the reason for issue #179 emerging.
  • Loading branch information
ehwenk authored Dec 5, 2024
1 parent c5014dc commit 129dcf5
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions R/testdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,14 @@ dataset_test_worker <-
)

# Check that there are no duplicate `var_in` or `context_property` fields
context_properties <- sapply(metadata[["contexts"]], "[[", "context_property")
context_vars_in <- sapply(metadata[["contexts"]], "[[", "var_in")

if(is.na(metadata[["contexts"]][1])) {
context_properties <- metadata[["contexts"]]
context_vars_in <- metadata[["contexts"]]
} else {
context_properties <- sapply(metadata[["contexts"]], "[[", "context_property")
context_vars_in <- sapply(metadata[["contexts"]], "[[", "var_in")
}

expect_equal(
context_properties |> duplicated() |> sum(),
Expand Down Expand Up @@ -731,12 +737,15 @@ dataset_test_worker <-
)

# Check units are found in `unit_conversions.csv`
units <- read_csv("config/unit_conversions.csv")
expect_is_in(
traits$unit_in, units$unit_from,
info = paste0(red(f), "\ttraits"),
label = "`unit_in`'s"
)
# This test is being commented out, because fails anytime columns are read in
# or anytime there are units not in unit_conversions because they are never converted.

#units <- read_csv("config/unit_conversions.csv")
#expect_is_in(
# traits$unit_in, units$unit_from,
# info = paste0(red(f), "\ttraits"),
# label = "`unit_in`'s"
#)

# Check no duplicate `var_in`'s

Expand Down

0 comments on commit 129dcf5

Please sign in to comment.