summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test/testmock/testhelpers.py
Commit message (Collapse)AuthorAgeFilesLines
* bpo-37555: Update _CallList.__contains__ to respect ANY (#14700)Elizabeth Uselton2019-09-131-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Flip equality to use mock calls' __eq__ * bpo-37555: Regression test demonstrating assert_has_calls not working with ANY and spec_set Co-authored-by: Neal Finne <neal@nealfinne.com> * Revert "Flip equality to use mock calls' __eq__" This reverts commit 94ddf54c5a8aab7d00d9ab93e1cc5695c28d73e7. * bpo-37555: Add regression tests for mock ANY ordering issues Add regression tests for whether __eq__ is order agnostic on _Call and _CallList, which is useful for comparisons involving ANY, especially if the ANY comparison is to a class not defaulting __eq__ to NotImplemented. Co-authored-by: Neal Finne <neal@nealfinne.com> * bpo-37555: Fix _CallList and _Call order sensitivity _Call and _CallList depend on ordering to correctly process that an object being compared to ANY with __eq__ should return True. This fix updates the comparison to check both a == b and b == a and return True if either condition is met, fixing situations from the tests in the previous two commits where assertEqual would not be commutative if checking _Call or _CallList objects. This seems like a reasonable fix considering that the Python data model specifies that if an object doesn't know how to compare itself to another object it should return NotImplemented, and that on getting NotImplemented from a == b, it should try b == a, implying that good behavior for __eq__ is commutative. This also flips the order of comparison in _CallList's __contains__ method, guaranteeing ANY will be on the left and have it's __eq__ called for equality checking, fixing the interaction between assert_has_calls and ANY. Co-author: Neal Finne <neal@neal.finne.com> * bpo-37555: Ensure _call_matcher returns _Call object * Adding ACK and news entry * bpo-37555: Replacing __eq__ with == to sidestep NotImplemented bool(NotImplemented) returns True, so it's necessary to use == instead of __eq__ in this comparison. * bpo-37555: cleaning up changes unnecessary to the final product * bpo-37555: Fixed call on bound arguments to respect args and kwargs * Revert "bpo-37555: Add regression tests for mock ANY ordering issues" This reverts commit 49c5310ad493c4356dd3bc58c03653cd9466c4fa. * Revert "bpo-37555: cleaning up changes unnecessary to the final product" This reverts commit 18e964ba0126d8964d89842cb95534b63c2d326e. * Revert "bpo-37555: Replacing __eq__ with == to sidestep NotImplemented" This reverts commit f295eaca5bceac6636c0e2b10e6c7d9a8ee8296a. * Revert "bpo-37555: Fix _CallList and _Call order sensitivity" This reverts commit 874fb697b8376fcea130116e56189061f944fde6. * Updated NEWS.d * bpo-37555: Add tests checking every function using _call_matcher both with and without spec * bpo-37555: Ensure all assert methods using _call_matcher are actually passing calls * Remove AnyCompare and use call objects everywhere. * Revert "Remove AnyCompare and use call objects everywhere." This reverts commit 24973c0b32ce7d796a7f4eeaf259832222aae0f5. * Check for exception in assert_any_await
* bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ ↵blhsing2019-09-111-0/+20
| | | | | | | | | | | | | | | | chaining so that call() can be subscriptable (GH-15565) * bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable * 📜🤖 Added by blurb_it. * Update 2019-08-28-21-40-12.bpo-37972.kP-n4L.rst added name of the contributor * bpo-37972: made all dunder methods chainable for _Call * bpo-37972: delegate only attributes of tuple instead to __getattr__
* Mock 100% coverage (GH-13045)Chris Withers2019-05-011-81/+114
| | | | | | | | | | | This was achieved by: * moving many pass statements in tests onto their own lines, so they pass line coverage and can match an easy ignore pattern if branch coverage is added later. * removing code that cannot be reached. * removing long-disabled tests. * removing unused code. * adding tests for uncovered code It turned out that removing `if __name__ == '__main__'` blocks that run unittest.main() at the bottom of test files was surprisingly contentious, so they remain and can be filtered out with an appropriate .coveragerc.
* bpo-36751: Deprecate getfullargspec and report positional-only args as ↵Pablo Galindo2019-04-301-2/+2
| | | | | | | | regular args (GH-13016) * bpo-36751: Deprecate getfullargspec and report positional-only args as regular args * Use inspect.signature in testhelpers
* bpo-23078: Add support for {class,static}method to mock.create_autospec() ↵Xtreak2019-04-221-1/+39
| | | | | (GH-11613) Co-authored-by: Felipe <felipe.nospam.ochoa@gmail.com>
* bpo-21269: Provide args and kwargs attributes on mock call objects GH11807Kumar Akshay2019-03-221-0/+9
|
* bpo-17185: Add __signature__ to mock that can be used by inspect for ↵Xtreak2018-12-121-0/+30
| | | | | | | | | | | | | | | | signature (GH11048) * Fix partial and partial method signatures in mock * Add more calls * Add NEWS entry * Use assertEquals and fix markup in NEWS * Refactor branching and add markup reference for functools * Revert partial object related changes and fix pr comments
* bpo-35226: Fix equality for nested unittest.mock.call objects. (#10555)Chris Withers2018-12-031-0/+16
| | | | Also refactor the call recording imolementation and add some notes about its limitations.
* bpo-32153: Add unit test for create_autospec with partial function returned ↵Xtreak2018-12-031-0/+14
| | | | | | | | | | in getattr (#10398) * Add create_autospec with partial function returned in getattr * Use self.assertFalse instead of assert * Use different names and remove object
* bpo-29403: Fix mock's broken autospec behavior on method-bound builtin ↵Aaron Gallagher2017-07-201-0/+15
| | | | | | | | | | | | | | | | | | | functions (GH-3) Cython will, in the right circumstances, offer a MethodType instance where im_func is a builtin function. Any instance of MethodType is automatically assumed to be a Python-defined function (more specifically, a function that has an inspectable signature), but _set_signature was still conservative in its assumptions. As a result _set_signature would return early with None instead of a mock since the im_func had no inspectable signature. This causes problems deeper inside mock, as _set_signature is assumed to _always_ return a mock, and nothing checked its return value. In similar corner cases, autospec will simply not check the spec of the function, so _set_signature is amended to now return early with the original, not-wrapped mock object. Patch by Aaron Gallagher.
* bpo-28961: Address my comments from earlier code review (#305)Berker Peksag2017-02-261-12/+3
|
* Fix unittest.mock._Call: don't ignore nameVictor Stinner2017-01-061-0/+14
| | | | | | | Issue #28961: Fix unittest.mock._Call helper: don't ignore the name parameter anymore. Patch written by Jiajun Huang.
* Issue #26750: unittest.mock.create_autospec() now works properlyGregory P. Smith2016-08-071-21/+39
| | | | for subclasses of property() and other data descriptors.
* Issue #19594: Use specific asserts in unittest tests.Serhiy Storchaka2013-11-161-9/+9
|\
| * Issue #19594: Use specific asserts in unittest tests.Serhiy Storchaka2013-11-161-9/+9
| |
* | Issue #17015: When it has a spec, a Mock object now inspects its signature ↵Antoine Pitrou2013-02-021-20/+39
|/ | | | when matching calls, so that arguments can be matched positionally or by name.
* Fix exception when calling reset_mock on a mock created with autospecMichael Foord2012-06-091-0/+7
|
* Closes issue 14634. unittest.mock.create_autospec now supports keyword only ↵Michael Foord2012-04-211-1/+14
| | | | arguments.
* Make unittest.mock.create_autospec resilient against AttributeError on ↵Michael Foord2012-04-131-0/+23
| | | | original object
* unittest.mock.PropertyMock return value and attributes are now standard ↵Michael Foord2012-04-131-0/+11
| | | | MagicMocks
* PEP 417: Adding unittest.mockMichael Foord2012-03-141-0/+835