feat(validation): name a keyed collection as such when a list is given
This commit is contained in:
@@ -78,7 +78,8 @@ class _Validator:
|
||||
self.errors.append(f"{path}: expected bool or dict, got {_kind(value)}")
|
||||
return
|
||||
if not TYPES[kind](value):
|
||||
self.errors.append(f"{path}: expected {kind}, got {_kind(value)}")
|
||||
keyed = len(spec.get("options", {})) == 1 and next(iter(spec["options"])).startswith("<")
|
||||
self.errors.append(f"{path}: expected {'dict keyed by name' if keyed else kind}, got {_kind(value)}")
|
||||
return
|
||||
if "choices" in spec and value not in spec["choices"]:
|
||||
shown = "" if spec.get("no_log") else f", got {value!r}"
|
||||
|
||||
@@ -21,7 +21,7 @@ inputs_fixtures:
|
||||
name: web01
|
||||
users:
|
||||
- name: alice
|
||||
expect: ["fixture.users: expected dict, got list"]
|
||||
expect: ["fixture.users: expected dict keyed by name, got list"]
|
||||
|
||||
- name: comma-string-for-list
|
||||
value:
|
||||
|
||||
@@ -52,7 +52,7 @@ users_fixtures:
|
||||
- name: ops
|
||||
password: pw
|
||||
expect:
|
||||
fail: "system.users: expected dict, got list"
|
||||
fail: "system.users: expected dict keyed by name, got list"
|
||||
|
||||
- name: list-rejected-precomputed
|
||||
precomputed: true
|
||||
@@ -61,7 +61,7 @@ users_fixtures:
|
||||
- name: ops
|
||||
password: pw
|
||||
expect:
|
||||
fail: "system.users: expected dict, got list"
|
||||
fail: "system.users: expected dict keyed by name, got list"
|
||||
|
||||
- name: scalar-entry-rejected
|
||||
system:
|
||||
|
||||
Reference in New Issue
Block a user