Commit Graph

110 Commits

Author SHA1 Message Date
Pablo Galindo 222d303ade bpo-20239: Allow repeated deletion of unittest.mock.Mock attributes (#11057)
* Allow repeated deletion of unittest.mock.Mock attributes

* fixup! Allow repeated deletion of unittest.mock.Mock attributes

* fixup! fixup! Allow repeated deletion of unittest.mock.Mock attributes
2019-01-21 08:57:46 +00:00
Xtreak 71f82a2f20 Fix mock_open docstring to use readline (#11176) 2018-12-20 16:00:21 +00:00
Xtreak f7fa62ef44 bpo-17185: Add __signature__ to mock that can be used by inspect for 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
2018-12-12 07:54:54 +00:00
Mario Corchero f05df0a4b6 bpo-35330: Don't call the wrapped object if `side_effect` is set (GH10973)
* tests: Further validate `wraps` functionality in `unittest.mock.Mock`

Add more tests to validate how `wraps` interacts with other features of
mocks.

* Don't call the wrapped object if `side_effect` is set

When a object is wrapped using `Mock(wraps=...)`, if an user sets a
`side_effect` in one of their methods, return the value of `side_effect`
and don't call the original object.

* Refactor what to be called on `mock_call`

When a `Mock` is called, it should return looking up in the following
order: `side_effect`, `return_value`, `wraps`. If any of the first two
return `mock.DEFAULT`, lookup in the next option.

It makes no sense to check for `wraps` returning default, as it is
supposed to be the original implementation and there is nothing to
fallback to.
2018-12-08 11:25:02 +00:00
Andrew Dunai e63e617ebb bpo-35357: Add _mock_ prefix to name/parent/from_kall attributes of _Call/_MagicProxy. (#10873)
Fix minor typo in test function name.
2018-12-04 09:08:45 +00:00
Chris Withers 8ca0fa9d2f
bpo-35226: Fix equality for nested unittest.mock.call objects. (#10555)
Also refactor the call recording imolementation and add some notes
about its limitations.
2018-12-03 21:31:37 +00:00
Xtreak edeca92c84 bpo-31177: Skip deleted attributes while calling reset_mock (GH-9302) 2018-12-01 11:03:54 +01:00
Serhiy Storchaka 34fd4c2019
bpo-35133: Fix mistakes when concatenate string literals on different lines. (GH-10284)
Two kind of mistakes:

1. Missed space. After concatenating there is no space between words.

2. Missed comma. Causes unintentional concatenating in a list of strings.
2018-11-05 16:20:25 +02:00
Petter Strandmark 47d94241a3 bpo-35047, unittest.mock: Better error messages on assert_called_xxx failures (GH-10090)
unittest.mock now includes mock calls in exception messages if
assert_not_called, assert_called_once, or assert_called_once_with
fails.
2018-10-28 21:37:10 +01:00
Max Bélanger 6c83d9f4a7 bpo-35022: unittest.mock.MagicMock now also supports __fspath__ (GH-9960)
The MagicMock class supports many magic methods, but not __fspath__. To ease
testing with modules such as os.path, this function is now supported by default.
2018-10-25 23:48:58 +02:00
Mario Corchero 96200eb2ff unittest.mock doc: Fix references to recursive seal of Mocks (GH-9028)
The docs in `library/unittest.mock` have been updated to remove
confusing terms about submock and be explicit about the behavior
expected.
2018-10-19 23:57:37 +02:00
Tony Flury 2087023fde bpo-32933: Implement __iter__ method on mock_open() (GH-5974) 2018-09-13 01:21:16 +03:00
davidair 2b32da2fea Improve error message when mock.assert_has_calls fails (GH-8205)
This makes the assertion error message more useful, aiding debugging.

Thanks @davidair!
2018-08-17 12:09:58 -07:00
Ned Deily 9d6d06e806
pypi.python.org -> pypi.org (GH-7613) 2018-06-11 00:45:50 -04:00
John Reese 6c4fab0f4b bpo-33516: Add support for __round__ in MagicMock (GH-6880)
unittest.mock.MagicMock now supports the __round__() magic method.
2018-05-22 22:01:10 +02:00
Mario Corchero 552be9d7e6 bpo-30541: Add new method to seal mocks (GH61923)
The new method allows the developer to control when to stop the
feature of mocks that automagically creates new mocks when accessing
an attribute that was not declared before

Signed-off-by: Mario Corchero <mariocj89@gmail.com>
2017-10-17 04:35:11 -07:00
Aaron Gallagher 856cbcc12f bpo-29403: Fix mock's broken autospec behavior on method-bound builtin 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.
2017-07-20 03:01:14 +03:00
Arne de Laat 324c5d8ca6 bpo-28911: Clarify the behaviour of assert_called_once_with. (#251) 2017-02-23 15:57:25 +01:00
Serhiy Storchaka 19dea2c726 Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY. 2017-01-21 23:17:25 +02:00
Serhiy Storchaka a203360836 Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY. 2017-01-21 23:15:18 +02:00
Serhiy Storchaka 362f058a89 Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY. 2017-01-21 23:12:58 +02:00
Serhiy Storchaka d9c956fb23 Issue #20804: The unittest.mock.sentinel attributes now preserve their
identity when they are copied or pickled.
2017-01-11 20:13:03 +02:00
Victor Stinner cd992bbe73 Merge 3.6 2017-01-06 18:16:07 +01:00
Victor Stinner 84b6fb0eea Fix unittest.mock._Call: don't ignore name
Issue #28961: Fix unittest.mock._Call helper: don't ignore the name parameter
anymore.

Patch written by Jiajun Huang.
2017-01-06 18:15:51 +01:00
Berker Peksag 161a4dd495 Issue #28919: Simplify _copy_func_details() in unittest.mock
Patch by Jiajun Huang.
2016-12-15 05:21:44 +03:00
Gregory P. Smith ac5084b6c7 Fixes issue28380: unittest.mock Mock autospec functions now properly support
assert_called, assert_not_called, and assert_called_once.
2016-10-06 14:31:23 -07:00
Gregory P. Smith c35a32fe85 Issue #26750: use inspect.isdatadescriptor instead of our own
_is_data_descriptor().
2016-08-15 23:56:32 -07:00
Gregory P. Smith d4583d7fea Issue #26750: use inspect.isdatadescriptor instead of our own
_is_data_descriptor().
2016-08-15 23:23:40 -07:00
Gregory P. Smith d0d24fd1ae Issue #26750: unittest.mock.create_autospec() now works properly for
subclasses of property() and other data descriptors.  Removes the never
publicly used, never documented unittest.mock.DescriptorTypes tuple.
2016-08-07 09:06:27 -07:00
Gregory P. Smith 9854789efe Issue #26750: unittest.mock.create_autospec() now works properly
for subclasses of property() and other data descriptors.
2016-08-07 08:52:26 -07:00
Martin Panter 702f4f5d6f Issue #23804: Merge spelling and NEWS fixes from 3.5 2016-07-11 12:54:44 +00:00
Martin Panter 204bf0b9ae English spelling and grammar fixes 2016-07-11 07:51:37 +00:00
Serhiy Storchaka 6c85091b5b Issue #23641: Added __getnewargs_ex__ to the list of special mock attributes. 2016-06-19 18:32:07 +03:00
Serhiy Storchaka 5943ea76d5 Issue #23641: Added __getnewargs_ex__ to the list of special mock attributes. 2016-06-19 18:30:43 +03:00
Kushal Das 9cd39a170b Issue #21271: Adds new keyword only parameters in reset_mock call
We now have two keyword only parameters in the reset_mock function to
selectively reset the return_value or the side_effects, or both.
2016-06-02 10:20:16 -07:00
Robert Collins c85dd85f1a Issue #26807: mock_open 'files' no longer error on readline at end of file.
Patch from Yolanda Robla.
2016-05-16 15:22:45 +12:00
Robert Collins 9549a3e3d4 Issue #26807: mock_open 'files' no longer error on readline at end of file.
Patch from Yolanda Robla.
2016-05-16 15:22:01 +12:00
Berker Peksag 5a6c018b57 Issue #25195: Fix a regression in mock.MagicMock
_Call is a subclass of tuple (changeset 3603bae63c13 only works
for classes) so we need to implement __ne__ ourselves.

Patch by Andrew Plummer.
2016-03-28 00:30:40 +03:00
Berker Peksag ce913877e4 Issue #25195: Fix a regression in mock.MagicMock
_Call is a subclass of tuple (changeset 3603bae63c13 only works
for classes) so we need to implement __ne__ ourselves.

Patch by Andrew Plummer.
2016-03-28 00:30:02 +03:00
Victor Stinner 2c2a4e63d7 Add Mock.assert_called()
Issue #26323: Add assert_called() and assert_called_once() methods to
unittest.mock.Mock.
2016-03-11 22:17:48 +01:00
Senthil Kumaran 121edbf7e2 Issue25347 - Format the error message output of mock's assert_has_calls method.
Patch contributed by Robert Zimmerman.
2016-01-12 06:18:32 -08:00
Senthil Kumaran 81bc927da7 Issue #22138: Fix mock.patch behavior when patching descriptors. Restore
original values after patching.

Patch contributed by Sean McCully.
2016-01-08 23:43:29 -08:00
Berker Peksag 29bf4d403d Issue #24857: Comparing call_args to a long sequence now correctly returns a
boolean result instead of raising an exception.

Patch by A Kaptur.
2015-09-09 23:39:45 +03:00
Berker Peksag 3fc536f1c9 Issue #24857: Comparing call_args to a long sequence now correctly returns a
boolean result instead of raising an exception.

Patch by A Kaptur.
2015-09-09 23:35:25 +03:00
Berker Peksag 86b34da5ef Issue #23004: mock_open() now reads binary data correctly when the type of read_data is bytes.
Initial patch by Aaron Hill.
2015-08-06 13:15:51 +03:00
Robert Collins ca647ef60a Issue #21750: Further fixup to be styled like other mock APIs. 2015-07-24 03:48:20 +12:00
Robert Collins 92b3e06517 Typo fix in mock.patch.
Patch from https://github.com/testing-cabal/mock/issues/215
2015-07-17 21:58:36 +12:00
Robert Collins 5329aaa74b Issue #21750: mock_open.read_data can now be read from each instance, as it
could in Python 3.3.
2015-07-17 20:08:45 +12:00
Robert Collins b37f43f94b - Issue #18622: unittest.mock.mock_open().reset_mock would recurse infinitely.
Patch from Nicola Palumbo and Laurent De Buyst.
2015-07-15 11:42:28 +12:00
Berker Peksag abfaecdfdd Issue #23004: mock_open() now reads binary data correctly when the type of read_data is bytes.
Initial patch by Aaron Hill.
2015-08-06 13:16:52 +03:00