[Test] Organize structured output utility tests (#57545)
Signed-off-by: john <6712432+CaiJohn@users.noreply.github.com> Co-authored-by: john <6712432+CaiJohn@users.noreply.github.com>
CaiJohn committed
Sep 21, 2026 at 18:56 UTC
15859bb3a1d81a709b64eff2a1d1f38a958a362b
1 file changed
+44
-45
tests/v1/structured_output/test_utils.py
+44
-45
@@ -190,41 +190,39 @@ def pattern_properties_schema():
190
}
191
192
193
-@pytest.mark.parametrize(
194
- "schema_type",
195
- [
196
- "unsupported_string_schemas",
197
- "unsupported_integer_schemas",
198
- "unsupported_number_schemas",
199
- "unsupported_array_schemas",
200
- "unsupported_property_names_combinations",
201
- "unsupported_pattern_properties_combinations",
202
- ],
203
-)
204
-def test_unsupported_json_features_by_type(schema_type, request):
205
- schemas = request.getfixturevalue(schema_type)
206
- for schema in schemas:
207
- assert has_xgrammar_unsupported_json_features(schema), (
208
- f"Schema should be unsupported: {schema}"
209
- )
210
-
211
-
212
-@pytest.mark.parametrize(
213
- "schema_type",
214
- [
215
- "supported_frankenstein_schema",
216
- "pattern_properties_schema",
217
- "property_names_schema",
218
- ],
219
-)
220
-def test_supported_json_features(schema_type, request):
221
- schema = request.getfixturevalue(schema_type)
222
- assert not has_xgrammar_unsupported_json_features(schema), (
223
- f"Schema should be supported: {schema}"
193
+class TestHasXGrammarUnsupportedJsonFeatures:
194
+ @pytest.mark.parametrize(
195
+ "schema_type",
196
+ [
197
+ "unsupported_string_schemas",
198
+ "unsupported_integer_schemas",
199
+ "unsupported_number_schemas",
200
+ "unsupported_array_schemas",
201
+ "unsupported_property_names_combinations",
202
+ "unsupported_pattern_properties_combinations",
203
+ ],
204
)
205
+ def test_unsupported_json_features_by_type(self, schema_type, request):
206
+ schemas = request.getfixturevalue(schema_type)
207
+ for schema in schemas:
208
+ assert has_xgrammar_unsupported_json_features(schema), (
209
+ f"Schema should be unsupported: {schema}"
210
+ )
211
212
+ @pytest.mark.parametrize(
213
+ "schema_type",
214
+ [
215
+ "supported_frankenstein_schema",
216
+ "pattern_properties_schema",
217
+ "property_names_schema",
218
+ ],
219
+ )
220
+ def test_supported_json_features(self, schema_type, request):
221
+ schema = request.getfixturevalue(schema_type)
222
+ assert not has_xgrammar_unsupported_json_features(schema), (
223
+ f"Schema should be supported: {schema}"
224
+ )
225
227
-class TestHasXGrammarUnsupportedJsonFeatures:
226
class TestPR48416Regressions:
227
@pytest.mark.parametrize(
228
"schema",
@@ -270,20 +268,21 @@ class TestHasXGrammarUnsupportedJsonFeatures:
268
assert not has_xgrammar_unsupported_json_features(schema)
269
270
273
-def test_property_names_constrains_keys(property_names_schema):
274
- assert grammar_accepts(property_names_schema, '{"score": 5}')
275
- assert grammar_accepts(property_names_schema, '{"score": "seven"}')
276
- assert not grammar_accepts(property_names_schema, '{"Score": 5}')
277
- assert not grammar_accepts(property_names_schema, '{"score_1": 5}')
278
-
279
-
280
-def test_pattern_properties_constrains_keys_and_values(pattern_properties_schema):
281
- assert grammar_accepts(pattern_properties_schema, '{"grade_1": 5}')
282
- assert not grammar_accepts(pattern_properties_schema, '{"other": 5}')
283
- assert not grammar_accepts(pattern_properties_schema, '{"grade_1": "five"}')
284
-
285
-
271
class TestIsGrammarAcceptString:
272
+ class TestPR42904Support:
273
+ def test_property_names_constrains_keys(self, property_names_schema):
274
+ assert grammar_accepts(property_names_schema, '{"score": 5}')
275
+ assert grammar_accepts(property_names_schema, '{"score": "seven"}')
276
+ assert not grammar_accepts(property_names_schema, '{"Score": 5}')
277
+ assert not grammar_accepts(property_names_schema, '{"score_1": 5}')
278
+
279
+ def test_pattern_properties_constrains_keys_and_values(
280
+ self, pattern_properties_schema
281
+ ):
282
+ assert grammar_accepts(pattern_properties_schema, '{"grade_1": 5}')
283
+ assert not grammar_accepts(pattern_properties_schema, '{"other": 5}')
284
+ assert not grammar_accepts(pattern_properties_schema, '{"grade_1": "five"}')
285
+
286
class TestPR48115Regressions:
287
@pytest.mark.parametrize("codepoint", [*range(0x20), 0x7F])
288
def test_choice_as_grammar_preserves_control_characters(self, codepoint):