Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-117225: doctest: only print "and X failed" when non-zero, don't pluralise "1 items"#117228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
6 commits Select commit Hold shift + click to select a range
3e1f57f Only print 'and X failed' when non-zero
hugovk 699b33d Do not pluralise 1 item
hugovk cb4d8d2 Refactor summarize()
hugovk a684423 Update docs
hugovk 266081e Add blurb
hugovk 4c1efb6 Update test: '1 failures' -> '1 failure'
hugovk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1191,9 +1191,9 @@ class DocTestRunner: | ||
| 2 tests in _TestClass | ||
| 2 tests in _TestClass.__init__ | ||
| 2 tests in _TestClass.get | ||
| 1 tests in _TestClass.square | ||
| 1 test in _TestClass.square | ||
| 7 tests in 4 items. | ||
| 7 passed and 0 failed. | ||
| 7 passed. | ||
| Test passed. | ||
| TestResults(failed=0, attempted=7) | ||
| @@ -1568,49 +1568,59 @@ def summarize(self, verbose=None): | ||
| """ | ||
| if verbose is None: | ||
| verbose = self._verbose | ||
| notests = [] | ||
| passed = [] | ||
| failed = [] | ||
| notests, passed, failed = [], [], [] | ||
| total_tries = total_failures = total_skips = 0 | ||
| for item in self._stats.items(): | ||
| name, (failures, tries, skips) = item | ||
| for name, (failures, tries, skips) in self._stats.items(): | ||
| assert failures <= tries | ||
| total_tries += tries | ||
| total_failures += failures | ||
| total_skips += skips | ||
| if tries == 0: | ||
| notests.append(name) | ||
| elif failures == 0: | ||
| passed.append((name, tries)) | ||
| else: | ||
| failed.append(item) | ||
| failed.append((name, (failures, tries, skips))) | ||
| if verbose: | ||
| if notests: | ||
| print(f"{len(notests)} items had no tests:") | ||
| print(f"{_n_items(notests)} had no tests:") | ||
| notests.sort() | ||
| for name in notests: | ||
| print(f"{name}") | ||
| if passed: | ||
| print(f"{len(passed)} items passed all tests:") | ||
| passed.sort() | ||
| for name, count in passed: | ||
| print(f"{count:3d} tests in{name}") | ||
| print(f"{_n_items(passed)} passed all tests:") | ||
| for name, count in sorted(passed): | ||
| s = "" if count == 1 else "s" | ||
| print(f"{count:3d} test{s} in{name}") | ||
| if failed: | ||
| print(self.DIVIDER) | ||
| print(f"{len(failed)} items had failures:") | ||
| failed.sort() | ||
| for name, (failures, tries, skips) in failed: | ||
| print(f"{_n_items(failed)} had failures:") | ||
| for name, (failures, tries, skips) in sorted(failed): | ||
| print(f"{failures:3d} of{tries:3d} in{name}") | ||
| if verbose: | ||
| print(f"{total_tries} tests in{len(self._stats)} items.") | ||
| print(f"{total_tries - total_failures} passed and{total_failures} failed.") | ||
| s = "" if total_tries == 1 else "s" | ||
| print(f"{total_tries} test{s} in{_n_items(self._stats)}.") | ||
| and_f = f" and{total_failures} failed" if total_failures else "" | ||
| print(f"{total_tries - total_failures} passed{and_f}.") | ||
| if total_failures: | ||
| msg = f"***Test Failed***{total_failures} failures" | ||
| s = "" if total_failures == 1 else "s" | ||
| msg = f"***Test Failed***{total_failures} failure{s}" | ||
| if total_skips: | ||
| msg = f"{msg} and{total_skips} skipped tests" | ||
| s = "" if total_skips == 1 else "s" | ||
| msg = f"{msg} and{total_skips} skipped test{s}" | ||
| print(f"{msg}.") | ||
| elif verbose: | ||
| print("Test passed.") | ||
| return TestResults(total_failures, total_tries, skipped=total_skips) | ||
| #///////////////////////////////////////////////////////////////// | ||
| @@ -1627,6 +1637,15 @@ def merge(self, other): | ||
| d[name] = (failures, tries, skips) | ||
| def _n_items(items: list) -> str: | ||
| """ | ||
| Helper to pluralise the number of items in a list. | ||
| """ | ||
| n = len(items) | ||
| s = "" if n == 1 else "s" | ||
| return f"{n} item{s}" | ||
hugovk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| class OutputChecker: | ||
| """ | ||
| A class used to check the whether the actual output from a doctest | ||
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
2 changes: 2 additions & 0 deletions 2 Misc/NEWS.d/next/Library/2024-03-25-21-15-56.gh-issue-117225.oOaZXb.rst
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| doctest: only print "and X failed" when non-zero, don't pluralise "1 items". | ||
| Patch by Hugo van Kemenade. |
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.
Uh oh!
There was an error while loading. Please reload this page.