|
1 | 1 | # SPDX-License-Identifier: Apache-2.0 |
2 | | -# |
3 | | -# Copyright (c) 2024 Christophe Dufaza |
| 2 | +# Copyright (c) 2024, Christophe Dufaza |
4 | 3 |
|
5 | 4 | """Unit tests dedicated to edtlib.Binding objects initialization. |
6 | 5 |
|
@@ -1007,6 +1006,135 @@ def test_bindings_propspecs_consistency() -> None: |
1007 | 1006 | binding = load_binding("test-bindings-init/diamond.yaml") |
1008 | 1007 | verify_binding_propspecs_consistency(binding) |
1009 | 1008 |
|
| 1009 | +def test_binding_propspecs_last_modified() -> None: |
| 1010 | + """Verify the Last Modified Here semantic of PropertySpec.path. |
| 1011 | + This test verifies the binding level. |
| 1012 | + """ |
| 1013 | + binding = load_binding("test-bindings-init/base_inherit.yaml") |
| 1014 | + # All properties are inherited without modifications. |
| 1015 | + assert all( |
| 1016 | + "base.yaml" == _basename(propspec.path) |
| 1017 | + for propspec in binding.prop2specs.values() |
| 1018 | + ) |
| 1019 | + |
| 1020 | + binding = load_binding("test-bindings-init/base_amend.yaml") |
| 1021 | + assert all( |
| 1022 | + "base.yaml" == _basename(binding.prop2specs[prop].path) |
| 1023 | + for prop in ( |
| 1024 | + "prop-default", |
| 1025 | + "prop-const", |
| 1026 | + "prop-req", |
| 1027 | + ) |
| 1028 | + ) |
| 1029 | + assert all( |
| 1030 | + "base_amend.yaml" == _basename(binding.prop2specs[prop].path) |
| 1031 | + for prop in ( |
| 1032 | + # Amended. |
| 1033 | + "prop-1", |
| 1034 | + "prop-2", |
| 1035 | + "prop-enum", |
| 1036 | + # New. |
| 1037 | + "prop-new", |
| 1038 | + ) |
| 1039 | + ) |
| 1040 | + |
| 1041 | + binding = load_binding("test-bindings-init/diamond.yaml") |
| 1042 | + assert "base.yaml" == _basename(binding.prop2specs["prop-default"].path) |
| 1043 | + assert all( |
| 1044 | + "thing.yaml" == _basename(binding.prop2specs[prop].path) |
| 1045 | + for prop in ("prop-1", "prop-thing") |
| 1046 | + ) |
| 1047 | + assert all( |
| 1048 | + "diamond.yaml" == _basename(binding.prop2specs[prop].path) |
| 1049 | + for prop in ("prop-enum", "prop-diamond") |
| 1050 | + ) |
| 1051 | + |
| 1052 | +def test_child_binding_propspecs_last_modified() -> None: |
| 1053 | + """Verify the Last Modified Here semantic of PropertySpec.path. |
| 1054 | + This test verifies the child-binding level. |
| 1055 | + """ |
| 1056 | + binding = child_binding_of("test-bindings-init/base_inherit.yaml") |
| 1057 | + # All properties are inherited without modifications. |
| 1058 | + assert all( |
| 1059 | + _basename(propspec.path) == "base.yaml" |
| 1060 | + for propspec in binding.prop2specs.values() |
| 1061 | + ) |
| 1062 | + |
| 1063 | + binding = child_binding_of("test-bindings-init/base_amend.yaml") |
| 1064 | + assert all( |
| 1065 | + _basename(binding.prop2specs[prop].path) == "base.yaml" |
| 1066 | + for prop in ( |
| 1067 | + "child-prop-default", |
| 1068 | + "child-prop-const", |
| 1069 | + "child-prop-req", |
| 1070 | + ) |
| 1071 | + ) |
| 1072 | + assert all( |
| 1073 | + _basename(binding.prop2specs[prop].path) == "base_amend.yaml" |
| 1074 | + for prop in ( |
| 1075 | + "child-prop-1", |
| 1076 | + "child-prop-2", |
| 1077 | + "child-prop-enum", |
| 1078 | + "child-prop-new", |
| 1079 | + ) |
| 1080 | + ) |
| 1081 | + |
| 1082 | + binding = child_binding_of("test-bindings-init/diamond.yaml") |
| 1083 | + assert "base.yaml" == _basename( |
| 1084 | + binding.prop2specs["child-prop-default"].path |
| 1085 | + ) |
| 1086 | + assert all( |
| 1087 | + "thing.yaml" == _basename(binding.prop2specs[prop].path) |
| 1088 | + for prop in ("child-prop-1", "child-prop-thing") |
| 1089 | + ) |
| 1090 | + assert all( |
| 1091 | + "diamond.yaml" == _basename(binding.prop2specs[prop].path) |
| 1092 | + for prop in ("child-prop-enum", "child-prop-diamond") |
| 1093 | + ) |
| 1094 | + |
| 1095 | +def test_grandchild_binding_propspecs_last_modified() -> None: |
| 1096 | + """Verify the Last Modified Here semantic of PropertySpec.path. |
| 1097 | + This test verifies the grandchild-binding level. |
| 1098 | + """ |
| 1099 | + binding = grandchild_binding_of("test-bindings-init/base_inherit.yaml") |
| 1100 | + # All properties are inherited without modifications. |
| 1101 | + assert all( |
| 1102 | + _basename(propspec.path) == "base.yaml" |
| 1103 | + for propspec in binding.prop2specs.values() |
| 1104 | + ) |
| 1105 | + |
| 1106 | + binding = grandchild_binding_of("test-bindings-init/base_amend.yaml") |
| 1107 | + assert all( |
| 1108 | + _basename(binding.prop2specs[prop].path) == "base.yaml" |
| 1109 | + for prop in ( |
| 1110 | + "grandchild-prop-default", |
| 1111 | + "grandchild-prop-const", |
| 1112 | + "grandchild-prop-req", |
| 1113 | + ) |
| 1114 | + ) |
| 1115 | + assert all( |
| 1116 | + _basename(binding.prop2specs[prop].path) == "base_amend.yaml" |
| 1117 | + for prop in ( |
| 1118 | + "grandchild-prop-1", |
| 1119 | + "grandchild-prop-2", |
| 1120 | + "grandchild-prop-enum", |
| 1121 | + "grandchild-prop-new", |
| 1122 | + ) |
| 1123 | + ) |
| 1124 | + |
| 1125 | + binding = grandchild_binding_of("test-bindings-init/diamond.yaml") |
| 1126 | + assert "base.yaml" == _basename( |
| 1127 | + binding.prop2specs["grandchild-prop-default"].path |
| 1128 | + ) |
| 1129 | + assert all( |
| 1130 | + "thing.yaml" == _basename(binding.prop2specs[prop].path) |
| 1131 | + for prop in ("grandchild-prop-1", "grandchild-prop-thing") |
| 1132 | + ) |
| 1133 | + assert all( |
| 1134 | + "diamond.yaml" == _basename(binding.prop2specs[prop].path) |
| 1135 | + for prop in ("grandchild-prop-enum", "grandchild-prop-diamond") |
| 1136 | + ) |
| 1137 | + |
1010 | 1138 |
|
1011 | 1139 | # Borrowed from test_edtlib.py. |
1012 | 1140 | @contextlib.contextmanager |
|
0 commit comments