Repository navigation
Fix comparison false negatives and ignore added fields - #2
Merged
Merged
Conversation
Reject bare-string ignore lists, non-finite numbers that cannot be serialized, and lone surrogates that made HTML reports unwritable. Accept a leading UTF-8 BOM on stdin. Optionally ignore keys and array tails that exist only in the second file. Co-authored-by: Master-626 <Master-626@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
English
Improves day-to-day use of this JSON response checker without changing default comparison results, except where the old result was wrong.
Bugs fixed
ignore_fields="id"was iterated as characters, so keysianddwere ignored andidwas not.ignore_paths="//"was treated as two copies of the empty-key pointer/, which could hide a difference at that key. Both arguments must now be lists of strings.load_json_stream(and thereforecompare expected.json -) rejected\ufeffat the start of the text. One leading BOM is now skipped. A BOM after other characters is still invalid, and a BOM character inside a JSON string is kept.NaNand infinities were not rejected during comparison.NaNis not equal to itself, so two identicalNaNvalues were reported as a change. Infinities compared equal. Either result can fail later when the diff is serialized. Non-finite floats andDecimalvalues that would be compared or included in a result now raiseValueError. Ignored fields are not inspected.\uD800in keys, and--json-outputalready escaped it, but the report inserted the raw character and UTF-8 encoding failed (exit 2). Those characters are now written as\uXXXX. Ordinary text, including non-ASCII keys, is unchanged and still HTML-escaped.Feature
--ignore-added/ignore_added=Truedoes not report object keys or array elements that exist only in the second file. Removals, edited values, and type changes are still reported. Arrays stay index-based: inserting an element in the middle still changes later indexes. The flag is off by default and is available on bothcompareandreport.Also in this change
README.zh-CN.mdmentions the new flag and BOM handling.0.2.1.175tests passed here, including coverage above the 90% gate.ruff checkandruff format --checkpassed. The installed-wheel smoke test passed.Suggested GitHub repository description:
Compare saved JSON API responses in CI, with scoped ignores, exact decimals, and offline HTML reports.中文
这次改动让仓库更好用,默认比较结果不变;只有原先结果错误的情况被修正。
发现并修复的问题
ignore_fields="id"会按字符遍历,于是键i和d被忽略,而id本身不会。ignore_paths="//"会被当成两个空键指针/,从而藏掉该位置的真实差异。现在这两个参数都必须是字符串列表。NaN和无穷大。NaN不等于自身,所以两个相同的NaN会被报成“已改变”;无穷大则会被当成相等。这两种结果都无法稳定序列化。现在,真正参与比较或写入结果的非有限float/Decimal会抛出ValueError。被忽略的字段不会检查。\uD800,--json-output能转义它,但报告把原字符写进 HTML,UTF-8 编码失败并返回退出码 2。现在这些字符写成\uXXXX。普通非 ASCII 文本保持不变,并且仍然会做 HTML 转义。新功能
--ignore-added(Python API 为ignore_added=True)不报告只存在于第二个文件中的对象键和数组元素。删除、改值和类型变化仍会报告。数组仍按下标比较,在中间插入元素时,后面的下标仍会变化。默认关闭,compare和report都支持。其他
README.md顶部增加简短中文说明,并补充选项表。README.zh-CN.md同步了新选项和 BOM 行为。0.2.1。175项测试通过,覆盖率高于 90% 门槛;ruff check与ruff format --check通过;安装 wheel 后的冒烟测试通过。建议的 GitHub 仓库一句话描述:
Compare saved JSON API responses in CI, with scoped ignores, exact decimals, and offline HTML reports.