Testing optional keys only #203
-
As a part of my application i am testing the schema validation. For a specific section of my configuration i have a Map which contains an optional username and password (and other keys). I want to test that both combinations wont raise an error during the validation. I only want to test the optional keys because i already have tests for the other keys, so i dont want to include any of them again. Shouldnt the following test pass? from strictyaml import Map, Str, Optional, load
from ensure import Ensure
schema = Map({Optional("username"): Str(), Optional("password"): Str()})
Ensure(load('', schema)).equals({}) It raises:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
No, it shouldn't. The Map validator implies that there should be at least one key and value, even though both individually are optional. If you wanted it to be possible to have neither, you would need
|
Beta Was this translation helpful? Give feedback.
No, it shouldn't. The Map validator implies that there should be at least one key and value, even though both individually are optional. If you wanted it to be possible to have neither, you would need
EmptyDict() | Map({Optional("username"): Str(), Optional("password"): Str()}).