更好的文本差异比较
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 30
- Forks
- 7
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 1
Description
目前的nonebug在测试时遇到和期望不相符的文本时,只会显示这样的格式:
f"Application got api call {api} with data {data} but expected {model.data}"
这经常会造成如下对人眼检查不友好的输出:
Application got api call ... with data {'foo': 1, 'bar': {'hello': 'world'}} but expected {'foo': 1, 'bar': {'hello': 'nonebug'}}
希望可以加入对 期望输出 和 实际输出 的比较,类似这样的格式:
{
"foo": 1,
"bar": {
- "hello": "world"
? ^ ^^^
+ "hello": "nonebot"
? ^ ^^^^^
}
}
这样的输出可以通过标准库difflib实现,大体类似于:
from difflib import ndiff
from json import dumps
print(
"\n".join(
ndiff(
dumps(data, indent=4).splitlines(),
dumps(model.data, indent=4).splitlines()
)
)
)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the assertion or error-formatting path that currently emits the API call message with actual and expected data. Read how the existing pytest output is assembled, then use the issue's difflib example as the target format and run the relevant test suite to verify readable differences for nested data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100