Repository navigation
Backport the six further assertions Python 3.14 added to unittest - #653
Merged
Merged
Conversation
Patrick: backport them. 'Testcase' provided only 'assertHasAttr' and 'assertNotHasAttr' on Python 3.11 to 3.13, so a test using 'assertIsSubclass', 'assertStartsWith' or 'assertEndsWith' passed on 3.14 and failed on the older interpreters (pyEDAA.OutputFilter's application test, #108). 'Testcase' defines 'assertIsSubclass', 'assertNotIsSubclass', 'assertStartsWith', 'assertNotStartsWith', 'assertEndsWith' and 'assertNotEndsWith' under 'if version_info < (3, 14):', following CPython's implementations: a tuple of classes, prefixes or suffixes, Python 3.14's messages, a wrong type of string ('Expected str, not bytes'), and 'msg' added as 'longMessage' says. The type check is written out in each method rather than in a shared helper, so a failure ends in the assertion that failed. 'assertHasAttr' and 'assertNotHasAttr' write 3.14's messages for a module and a class now, and add 'msg' instead of replacing the message. The module's imports share one column again ('unittest.util' was the widest). Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 77 |
| Duplication | 8 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Merged
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.
Testcaseprovided only two of the eight assertions Python 3.14 added tounittest.TestCase. A test using one of the other six passed on 3.14 and failed on 3.11 to 3.13 - pyEDAA.OutputFilter's application test hit it (edaa-org/pyEDAA.OutputFilter#108).New Features
pyTooling.Testing:TestcaseprovidesassertIsSubclass,assertNotIsSubclass,assertStartsWith,assertNotStartsWith,assertEndsWithandassertNotEndsWithon Python 3.11 to 3.13. They follow CPython's implementations: a tuple of classes, prefixes or suffixes, Python 3.14's messages,Expected str, not bytesfor a mismatched string type, and amsgadded to the message aslongMessagesays. On 3.14 and newer the class defines nothing, so the standard library's implementations are used.Changes
pyTooling.Testing:assertHasAttrandassertNotHasAttrwrite Python 3.14's messages for a module (module 'json' has no attribute ...) and a class (type object 'int' has ...), and add a givenmsginstead of replacing the message - as on 3.14.Documentation
doc/Testing.rst, Assertions: a table of the eight assertions.doc/News.rstlists the six new ones.Unit Tests
tests/unit/Testing/__init__.py: a new classBackportedAssertionsasserts each assertion's success and its full failure messages, including tuples, the wrong string type and an addedmsg. The same tests run against unittest on 3.14+ and against the backports on 3.11 to 3.13 (run locally with Python 3.13: 40 passed).Related Issues and Pull-Requests