Lines Matching full:binding
4 """Unit tests dedicated to edtlib.Binding objects initialization.
6 Running the assumption that any (valid) YAML binding file is
7 something we can make a Binding instance with:
8 - check which properties are defined at which level (binding, child-binding,
9 grandchild-binding, etc) and their specifications once the binding
13 - check the rules applied when overwriting a binding's description
14 or compatible string (at the binding, child-binding, etc, levels)
16 At any level, an including binding is permitted to:
25 times by several included binding files, "include:"ed first "wins"
28 At any level, an including binding is NOT permitted to:
37 by the including binding (despite that "description:" appears before
38 "include:"): this seems consistent, the top-level binding file "wins"
39 - an including binding can overwrite descriptions and compatible strings
40 inherited at the child-binding levels: this seems consistent,
41 the top-level binding file "wins"
43 string inherited at the child-binding levels, order of inclusion matters,
46 For all tests, the entry point is a Binding instance initialized
48 really is what happens when we (recursively) call Binding's constructor,
80 def load_binding(path: str) -> edtlib.Binding:
81 """Load YAML file as Binding instance,
88 binding = edtlib.Binding(
95 return binding
98 def child_binding_of(path: str) -> edtlib.Binding:
99 """Load YAML file as Binding instance, and returns its child-binding.
100 The child-binding must exist.
105 binding = load_binding(path)
106 assert binding.child_binding
107 return binding.child_binding
110 def grandchild_binding_of(path: str) -> edtlib.Binding:
111 """Load YAML file as Binding instance, and returns its grandchild-binding.
112 The grandchild-binding must exist.
156 def verify_binding_propspecs_consistency(binding: edtlib.Binding) -> None: argument
157 """Verify consistency between what's in Binding.prop2specs
158 and Binding.raw.
161 Binding.raw["properties"][prop] == Binding.prop2specs[prop]._raw
163 If the binding has a child-binding, also recursively verify child-bindings.
165 NOTE: do not confuse with binding.prop2specs[prop].binding == binding,
168 if binding.prop2specs:
169 assert set(binding.raw["properties"].keys()) == set(binding.prop2specs.keys())
171 binding.raw["properties"][prop] == propspec._raw
172 for prop, propspec in binding.prop2specs.items()
174 if binding.child_binding:
175 verify_binding_propspecs_consistency(binding.child_binding)
182 up to the grandchild-binding level.
186 binding = load_binding("test-bindings-init/base_inherit.yaml")
188 # Binding level.
196 } == set(binding.prop2specs.keys())
197 propspec = binding.prop2specs["prop-1"]
199 propspec = binding.prop2specs["prop-2"]
201 propspec = binding.prop2specs["prop-enum"]
203 propspec = binding.prop2specs["prop-const"]
205 propspec = binding.prop2specs["prop-req"]
207 propspec = binding.prop2specs["prop-default"]
210 # Child-Binding level.
211 assert binding.child_binding
212 child_binding = binding.child_binding
234 # GrandChild-Binding level.
266 Base specifications are included once at the binding level:
271 child-binding:
274 child-binding:
279 up to the grandchild-binding level.
281 binding = load_binding("test-bindings-init/base_amend.yaml")
283 # Binding level.
293 } == set(binding.prop2specs.keys())
294 propspec = binding.prop2specs["prop-1"]
301 propspec = binding.prop2specs["prop-2"]
310 propspec = binding.prop2specs["prop-enum"]
319 propspec = binding.prop2specs["prop-const"]
321 propspec = binding.prop2specs["prop-req"]
323 propspec = binding.prop2specs["prop-default"]
327 propspec = binding.prop2specs["prop-new"]
330 # Child-Binding level.
332 assert binding.child_binding
333 child_binding = binding.child_binding
379 # GrandChild-Binding level.
432 Base specifications are included at the binding, child-binding
433 and child-binding levels:
436 child-binding:
438 child-binding:
442 at the child-binding level.
444 binding = child_binding_of("test-bindings-init/base_multi.yaml")
451 # From "child-binding: include:" element.
455 } == set(binding.prop2specs.keys())
458 propspec = binding.prop2specs["child-prop-2"]
460 propspec = binding.prop2specs["child-prop-enum"]
463 propspec = binding.prop2specs["child-prop-1"]
470 propspec = binding.prop2specs["prop-1"]
477 propspec = binding.prop2specs["prop-2"]
484 propspec = binding.prop2specs["prop-enum"]
499 at the grandchild-binding level.
503 binding = grandchild_binding_of("test-bindings-init/base_multi.yaml")
510 # From "child-binding: include:" element.
514 # From "child-binding: child-binding: include:" element.
518 } == set(binding.prop2specs.keys())
521 propspec = binding.prop2specs["grandchild-prop-2"]
523 propspec = binding.prop2specs["grandchild-prop-enum"]
529 propspec = binding.prop2specs["child-prop-2"]
531 propspec = binding.prop2specs["child-prop-enum"]
534 propspec = binding.prop2specs["grandchild-prop-1"]
541 propspec = binding.prop2specs["child-prop-1"]
548 propspec = binding.prop2specs["prop-1"]
555 propspec = binding.prop2specs["prop-2"]
562 propspec = binding.prop2specs["prop-enum"]
577 at the grand-grandchild-binding level.
581 binding = grandchild_binding_of("test-bindings-init/base_multi.yaml").child_binding
582 assert binding
585 # From "child-binding: include:" element.
589 # From "child-binding: child-binding: include:" element.
593 } == set(binding.prop2specs.keys())
596 propspec = binding.prop2specs["child-prop-1"]
598 propspec = binding.prop2specs["child-prop-2"]
600 propspec = binding.prop2specs["child-prop-enum"]
602 propspec = binding.prop2specs["grandchild-prop-1"]
604 propspec = binding.prop2specs["grandchild-prop-2"]
606 propspec = binding.prop2specs["grandchild-prop-enum"]
618 at the binding level.
620 binding = load_binding("test-bindings-init/diamond.yaml")
635 } == set(binding.prop2specs.keys())
638 propspec = binding.prop2specs["prop-default"]
641 propspec = binding.prop2specs["prop-thing"]
645 propspec = binding.prop2specs["prop-diamond"]
648 propspec = binding.prop2specs["prop-1"]
658 propspec = binding.prop2specs["prop-enum"]
675 at the child-binding level.
677 binding = child_binding_of("test-bindings-init/diamond.yaml")
692 } == set(binding.prop2specs.keys())
694 propspec = binding.prop2specs["child-prop-1"]
705 propspec = binding.prop2specs["child-prop-enum"]
719 propspec = binding.prop2specs["child-prop-default"]
722 propspec = binding.prop2specs["child-prop-thing"]
723 verify_expected_propspec(propspec, expect_desc="Thing child-binding property.")
726 propspec = binding.prop2specs["child-prop-diamond"]
734 at the grandchild-binding level.
736 binding = grandchild_binding_of("test-bindings-init/diamond.yaml")
751 } == set(binding.prop2specs.keys())
753 propspec = binding.prop2specs["grandchild-prop-1"]
764 propspec = binding.prop2specs["grandchild-prop-enum"]
778 propspec = binding.prop2specs["grandchild-prop-default"]
781 propspec = binding.prop2specs["grandchild-prop-thing"]
782 verify_expected_propspec(propspec, expect_desc="Thing grandchild-binding property.")
785 propspec = binding.prop2specs["grandchild-prop-diamond"]
790 """Test whether we can overwrite a binding's description.
792 Included files can't overwrite the description set by the including binding
795 This seems consistent: the top-level binding file "wins".
797 binding = load_binding("test-bindings-init/compat_desc.yaml")
798 assert binding.description == "Binding description."
800 binding = load_binding("test-bindings-init/compat_desc_multi.yaml")
801 assert binding.description == "Binding description (multi)."
805 """Test whether we can overwrite a binding's compatible string.
808 including binding (despite that "compatible:" appears before "include:").
810 This seems consistent: the top-level binding file "wins".
812 binding = load_binding("test-bindings-init/compat_desc.yaml")
813 assert binding.compatible == "vnd,compat-desc"
815 binding = load_binding("test-bindings-init/compat_desc_multi.yaml")
816 assert binding.compatible == "vnd,compat-desc-multi"
820 """Test whether we can overwrite a child-binding's description.
822 An including binding can overwrite an inherited child-binding's description.
825 at the child-binding level, the first "wins".
829 assert child_binding.description == "Child-binding description."
833 assert child_binding.description == "Child-binding description (base)."
837 """Test whether we can overwrite a child-binding's compatible string.
839 An including binding can overwrite an inherited child-binding's
843 at the child-binding level, the first "wins".
855 """Test whether we can overwrite a grandchild-binding's description.
860 assert grandchild_binding.description == "Grandchild-binding description."
863 assert grandchild_binding.description == "Grandchild-binding description (base)."
867 """Test whether we can overwrite a grandchild-binding's compatible string.
882 binding file.
885 - X is a base binding file, specifying common properties
886 - I is an intermediary binding file, which includes X without modification
891 Checks, up to the grandchild-binding level, that the properties inherited
894 # Binding level.
895 binding = load_binding("test-bindings-init/simple_allowlist.yaml")
897 assert {"prop-1", "prop-2"} == set(binding.prop2specs.keys())
898 binding = load_binding("test-bindings-init/simple_blocklist.yaml")
900 assert {"prop-2", "prop-3"} == set(binding.prop2specs.keys())
902 # Child-binding level.
910 # GrandChild-binding level.
921 binding file.
926 - X is a base binding file, specifying common properties
927 - I is an intermediary binding file, filtering the properties specified
932 Checks, up to the grandchild-binding level, that B inherits the properties
938 binding = load_binding("test-bindings-init/filter_among_allowed.yaml")
939 assert not set(binding.prop2specs.keys())
940 assert binding.child_binding
941 child_binding = binding.child_binding
950 binding file.
955 - X is a base binding file, specifying common properties
956 - I is an intermediary binding file, filtering the properties specified
961 Checks, up to the grandchild-binding level, that B inherits the properties
967 binding = load_binding("test-bindings-init/filter_among_notblocked.yaml")
968 assert not set(binding.prop2specs.keys())
969 assert binding.child_binding
970 child_binding = binding.child_binding
979 binding file.
984 - X is a base binding file, specifying common properties
985 - I is an intermediary binding file, filtering the properties specified
990 Checks, up to the grandchild-binding level, that B inherits the properties
998 binding = load_binding("test-bindings-init/filter_allows_notblocked.yaml")
999 assert {"prop-2"} == set(binding.prop2specs.keys())
1000 assert binding.child_binding
1001 child_binding = binding.child_binding
1009 """An including binding should not try to override the "type:"
1012 Tested up to the grandchild-binding level.
1031 """An including binding should not try to override the "const:" value
1034 Tested up to the grandchild-binding level.
1053 """An including binding should not try to override "required: true"
1056 Tested up to the grandchild-binding level.
1075 """An including binding should not try to override the "default:" value
1078 Tested up to the grandchild-binding level.
1097 """An including binding should not try to override the "enum:" values
1100 Tested up to the grandchild-binding level.
1125 from top-level binding files down to their child bindings.
1128 Binding.raw["properties"][prop] == Binding.prop2specs[prop]._raw
1132 binding = load_binding("test-bindings-init/base_inherit.yaml")
1133 verify_binding_propspecs_consistency(binding)
1135 binding = load_binding("test-bindings-init/base_amend.yaml")
1136 verify_binding_propspecs_consistency(binding)
1138 binding = load_binding("test-bindings-init/base_multi.yaml")
1139 verify_binding_propspecs_consistency(binding)
1141 binding = load_binding("test-bindings-init/thing.yaml")
1142 verify_binding_propspecs_consistency(binding)
1144 binding = load_binding("test-bindings-init/diamond.yaml")
1145 verify_binding_propspecs_consistency(binding)