Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
9522dfa
1
Parent(s): b2e733d
Make sure tests are atomic
Browse files
tests/utilities/openapi/test_openapi.py
CHANGED
|
@@ -1105,65 +1105,101 @@ def test_consistent_output_across_versions(
|
|
| 1105 |
assert set(schema_30.keys()) == set(schema_31.keys())
|
| 1106 |
|
| 1107 |
|
| 1108 |
-
|
| 1109 |
-
|
| 1110 |
-
|
| 1111 |
-
|
| 1112 |
-
|
| 1113 |
-
|
| 1114 |
-
|
| 1115 |
-
|
| 1116 |
-
|
| 1117 |
-
|
| 1118 |
-
|
| 1119 |
-
|
| 1120 |
-
|
| 1121 |
-
|
| 1122 |
-
|
| 1123 |
-
|
| 1124 |
-
|
| 1125 |
-
|
| 1126 |
-
|
| 1127 |
-
|
| 1128 |
-
|
| 1129 |
-
|
| 1130 |
-
|
| 1131 |
-
|
| 1132 |
-
|
| 1133 |
-
|
| 1134 |
-
|
| 1135 |
-
|
| 1136 |
-
|
| 1137 |
-
"properties": {
|
| 1138 |
-
"pets": {
|
| 1139 |
"oneOf": [
|
| 1140 |
-
{"$ref": "#/components/schemas/
|
| 1141 |
-
{"$ref": "#/components/schemas/
|
| 1142 |
]
|
| 1143 |
},
|
| 1144 |
-
|
| 1145 |
-
|
| 1146 |
-
|
| 1147 |
-
|
| 1148 |
-
|
| 1149 |
-
|
| 1150 |
-
|
| 1151 |
-
|
| 1152 |
-
|
| 1153 |
-
|
| 1154 |
-
|
| 1155 |
-
|
| 1156 |
-
|
| 1157 |
-
|
| 1158 |
-
|
| 1159 |
-
|
| 1160 |
-
|
| 1161 |
-
|
| 1162 |
-
|
| 1163 |
-
|
| 1164 |
-
|
| 1165 |
-
|
| 1166 |
-
|
| 1167 |
-
"
|
| 1168 |
-
}
|
| 1169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1105 |
assert set(schema_30.keys()) == set(schema_31.keys())
|
| 1106 |
|
| 1107 |
|
| 1108 |
+
class TestReplaceRefWithDefs:
|
| 1109 |
+
@pytest.fixture(scope="class")
|
| 1110 |
+
def schemas(self):
|
| 1111 |
+
"""Provide test schemas for _replace_ref_with_defs function."""
|
| 1112 |
+
return {
|
| 1113 |
+
"ref_type": {
|
| 1114 |
+
"$ref": "#/components/schemas/RefFoo",
|
| 1115 |
+
},
|
| 1116 |
+
"object_type": {
|
| 1117 |
+
"type": "object",
|
| 1118 |
+
"properties": {"$ref": "#/components/schemas/ObjectFoo"},
|
| 1119 |
+
},
|
| 1120 |
+
"array_type": {
|
| 1121 |
+
"type": "array",
|
| 1122 |
+
"items": {"$ref": "#/components/schemas/ArrayFoo"},
|
| 1123 |
+
},
|
| 1124 |
+
"any_of_type": {
|
| 1125 |
+
"anyOf": [
|
| 1126 |
+
{"$ref": "#/components/schemas/AnyOfFoo"},
|
| 1127 |
+
{"$ref": "#/components/schemas/AnyOfBar"},
|
| 1128 |
+
]
|
| 1129 |
+
},
|
| 1130 |
+
"all_of_type": {
|
| 1131 |
+
"allOf": [
|
| 1132 |
+
{"$ref": "#/components/schemas/AllOfFoo"},
|
| 1133 |
+
{"$ref": "#/components/schemas/AllOfBar"},
|
| 1134 |
+
]
|
| 1135 |
+
},
|
| 1136 |
+
"one_of_type": {
|
|
|
|
|
|
|
| 1137 |
"oneOf": [
|
| 1138 |
+
{"$ref": "#/components/schemas/OneOfFoo"},
|
| 1139 |
+
{"$ref": "#/components/schemas/OneOfBar"},
|
| 1140 |
]
|
| 1141 |
},
|
| 1142 |
+
"nested_type": {
|
| 1143 |
+
"type": "object",
|
| 1144 |
+
"properties": {
|
| 1145 |
+
"pets": {
|
| 1146 |
+
"oneOf": [
|
| 1147 |
+
{"$ref": "#/components/schemas/Cat"},
|
| 1148 |
+
{"$ref": "#/components/schemas/Dog"},
|
| 1149 |
+
]
|
| 1150 |
+
},
|
| 1151 |
+
},
|
| 1152 |
+
},
|
| 1153 |
+
}
|
| 1154 |
+
|
| 1155 |
+
def test_replace_direct_ref(self, schemas):
|
| 1156 |
+
"""Test replacing direct $ref references."""
|
| 1157 |
+
result = _replace_ref_with_defs(schemas["ref_type"])
|
| 1158 |
+
assert result == {"$ref": "#/$defs/RefFoo"}
|
| 1159 |
+
|
| 1160 |
+
def test_replace_object_property_ref(self, schemas):
|
| 1161 |
+
"""Test replacing $ref in object properties."""
|
| 1162 |
+
result = _replace_ref_with_defs(schemas["object_type"])
|
| 1163 |
+
assert result == {
|
| 1164 |
+
"type": "object",
|
| 1165 |
+
"properties": {"$ref": "#/$defs/ObjectFoo"},
|
| 1166 |
+
}
|
| 1167 |
+
|
| 1168 |
+
def test_replace_array_items_ref(self, schemas):
|
| 1169 |
+
"""Test replacing $ref in array items."""
|
| 1170 |
+
result = _replace_ref_with_defs(schemas["array_type"])
|
| 1171 |
+
assert result == {
|
| 1172 |
+
"type": "array",
|
| 1173 |
+
"items": {"$ref": "#/$defs/ArrayFoo"},
|
| 1174 |
+
}
|
| 1175 |
+
|
| 1176 |
+
def test_replace_any_of_refs(self, schemas):
|
| 1177 |
+
"""Test replacing $ref in anyOf schemas."""
|
| 1178 |
+
result = _replace_ref_with_defs(schemas["any_of_type"])
|
| 1179 |
+
assert result == {
|
| 1180 |
+
"anyOf": [{"$ref": "#/$defs/AnyOfFoo"}, {"$ref": "#/$defs/AnyOfBar"}]
|
| 1181 |
+
}
|
| 1182 |
+
|
| 1183 |
+
def test_replace_all_of_refs(self, schemas):
|
| 1184 |
+
"""Test replacing $ref in allOf schemas."""
|
| 1185 |
+
result = _replace_ref_with_defs(schemas["all_of_type"])
|
| 1186 |
+
assert result == {
|
| 1187 |
+
"allOf": [{"$ref": "#/$defs/AllOfFoo"}, {"$ref": "#/$defs/AllOfBar"}]
|
| 1188 |
+
}
|
| 1189 |
+
|
| 1190 |
+
def test_replace_one_of_refs(self, schemas):
|
| 1191 |
+
"""Test replacing $ref in oneOf schemas."""
|
| 1192 |
+
result = _replace_ref_with_defs(schemas["one_of_type"])
|
| 1193 |
+
assert result == {
|
| 1194 |
+
"oneOf": [{"$ref": "#/$defs/OneOfFoo"}, {"$ref": "#/$defs/OneOfBar"}]
|
| 1195 |
+
}
|
| 1196 |
+
|
| 1197 |
+
def test_replace_nested_refs(self, schemas):
|
| 1198 |
+
"""Test replacing $ref in deeply nested schema structures."""
|
| 1199 |
+
result = _replace_ref_with_defs(schemas["nested_type"])
|
| 1200 |
+
assert result == {
|
| 1201 |
+
"type": "object",
|
| 1202 |
+
"properties": {
|
| 1203 |
+
"pets": {"oneOf": [{"$ref": "#/$defs/Cat"}, {"$ref": "#/$defs/Dog"}]}
|
| 1204 |
+
},
|
| 1205 |
+
}
|