【Hackathon 9th No.76】supplementary unit test for XGrammarChecker by Echo-Nie · Pull Request #4075 · PaddlePaddle/FastDeploy (original) (raw)
Objective
- guided_json: Verify whether the JSON schema is compatible with XGrammar.
- guided_grammar: Verify the validity of custom grammar strings.
- guided_json_object: Verify that the simplified JSON object pattern { "type": "object" } can be correctly generated.
- guided_choice: Verify whether a list of choices can be correctly transformed into grammar rules.
- structural_tag: Verify that structured tags can be correctly parsed.
- regex: Verify that regular expressions are passed through without validation errors.
Test Results
/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/utils/cpp_extension/extension_utils.py:717: UserWarning: No ccache found. Please be aware that recompiling all source files may be required. You can download and install ccache from: https://github.com/ccache/ccache/blob/master/doc/INSTALL.md
warnings.warn(warning_message)
/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/_distutils_hack/__init__.py:30: UserWarning: Setuptools is replacing distutils. Support for replacing an already imported distutils is deprecated. In the future, this condition will fail. Register concerns at https://github.com/pypa/setuptools/issues/new?template=distutils-deprecation.yml
warnings.warn(
test_guided_choice_invalid (__main__.TestXGrammarChecker) ... ok
test_guided_choice_valid (__main__.TestXGrammarChecker) ... ok
test_guided_grammar_invalid (__main__.TestXGrammarChecker) ... ok
test_guided_grammar_valid (__main__.TestXGrammarChecker) ... ok
test_guided_json_invalid (__main__.TestXGrammarChecker) ... ok
test_guided_json_object (__main__.TestXGrammarChecker) ... ok
test_guided_json_valid (__main__.TestXGrammarChecker) ... ok
test_regex_passthrough (__main__.TestXGrammarChecker) ... ok
test_structural_tag_invalid (__main__.TestXGrammarChecker) ... ok
test_structural_tag_valid (__main__.TestXGrammarChecker) ... ok
----------------------------------------------------------------------
Ran 10 tests in 0.002s
OK
Analysis
guided_json: Valid schemas pass correctly. Invalid schemas correctly return an error.
guided_grammar: Valid grammar strings generate the corresponding Grammar object. Invalid grammar strings return errors as expected.
guided_json_object: Simplified JSON object patterns are generated correctly.
guided_choice: Valid choice lists are correctly converted into grammar rules. Invalid choices (e.g., containing None) trigger exceptions.
structural_tag: Correct structured tags are parsed successfully. Missing trigger fields trigger a KeyError.
regex: Regular expressions are passed through directly without validation errors.