Skip to content

Commit

Permalink
Fixed a bug where if "allowempty: True" was set inside a mapping insi…
Browse files Browse the repository at this point in the history
…de a sequence it would not validate properly if no mapping keyword is set.
  • Loading branch information
Grokzen committed Dec 21, 2016
1 parent 94f326c commit cd012c9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Release Notes
- This feature is NEW and EXPERIMENTAL in this release.
It is now possible to specify a default rule when using a mapping.
The rule will be used whenever no other key could be found.
- Fixed a bug where if allowempty was specefied in a mapping type inside a sequence type then it would not properly validate.


1.5.2 (Nov 12, 2016)
Expand Down
4 changes: 4 additions & 0 deletions pykwalify/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ def _validate_sequence(self, value, rule, path, done=None):
log.debug(u" * Found map inside sequence")
unique_keys = []

if r.mapping is None:
log.debug(u" + No rule to apply, prolly because of allowempty: True")
return

for k, _rule in r.mapping.items():
log.debug(u" * Key: %s", k)
log.debug(u" * Rule: %s", _rule)
Expand Down
16 changes: 16 additions & 0 deletions tests/files/success/40s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
data:
rally:
plugins:
- netcreate-boot: rally/rally-plugins/netcreate-boot
schema:
type: map
mapping:
rally:
type: map
allowempty: True
mapping:
plugins:
type: seq
sequence:
- type: map
allowempty: True
2 changes: 2 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ def test_core_files(self):
"38s.yaml",
# Test that default mapping keyword works out of the box in a good case
"39s.yaml",
# Test that allowempty works without specifying mapping keyword when used inside a sequence block
"40s.yaml",
]

_fail_tests = [
Expand Down

0 comments on commit cd012c9

Please sign in to comment.