summaryrefslogtreecommitdiff
path: root/fixtures/_fixtures/monkeypatch.py
Commit message (Collapse)AuthorAgeFilesLines
* Remove six and other Python 2 handling codeStephen Finucane2021-02-251-4/+1
| | | | Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
* Fix tests on Python 3.9Stephen Finucane2021-02-251-2/+7
| | | | | | | I'm not entirely sure this is correct, but it's the only thing I can find related to changes in classmethod in Python 3.9. Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
* Remove unused imports and variableshugovk2018-06-041-6/+5
|
* Fixup the MonkeyPatch patch.Robert Collins2016-05-201-27/+68
| | | | | | | | - docs. - cleanup patches of boundmethods to not leave cruft behind. - NEWS entry. Sem-Ver: api-break
* Update the semantics on _fixtures.MonkeyPatchAndrew Laski2016-05-191-11/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A previous change added some logic so that when monkeypatching a staticmethod the old_value was restored as a staticmethod. There was an issue where the determination of whether or not a method should be static was incorrectly checking the new function not the one to be replaced. That caused an unintended side-effect that in order to patch an instance method of a class the new function needed to be an instance method of a class. This change now reworks the semantics of MonkeyPatch to address that issue and at the same time be explicit about how it should work in a large number of different cases. The rule is simple and provides great flexibility. Given a callable bar to be patched on to foo bar will be called with any bound arguments first and then arguments of foo appended. This is easier to visualize. Given: class C(object): @classmethod def foo(cls, arg): pass class D(object): @classmethod def bar(cls, tgtcls, arg): pass def baz(cls, arg): pass MonkeyPatch('...C.foo', D.bar) will result in C.foo(1) calling bar like bar(D, C, 1) because cls on bar was already bound to D when patching. And MonkeyPatch('...C.foo', baz) will result in baz being called with baz(C, 1).
* MonkeyPatch staticmethodAndrew Laski2016-04-071-7/+19
| | | | | | | | | | | | | | | | | | | | | | | In Python setattr(Class, name, func) automatically converts a function into an instancemethod. To keep type(Class.func) as function, staticmethod(func) must be applied explicitly. This was previously fixed for Python 2 when cleaning up the patched function but Python 3 needs the same handling. When patching a function it was being converted to an instancemethod for both Python 2 and 3 and this has now been fixed. This is a breaking change as it was previously acceptable to patch a staticmethod with an instancemethod. The test for this case was updated to correctly check both cases. The patched function is called as both Class.function() and Class().function(), and then called again after the cleanup has occurred resetting the function to its original state. The Class().function() check is important because the method does not become bound until the class it is defined on is instantiated. Sem-Ver: api-break
* Deal with resource leaks during setUp.Robert Collins2015-06-291-2/+1
| | | | | | | | Fixture.setUp should no longer be overridden in subclasses. Instead override _setUp. This permits the Fixture base class to detect failures during _setUp and trigger any registered cleanups, attach any details to the failure exception and propogate that to callers. (Robert Collins, #1456361, #1456353)
* Migrate to git and pbr.Robert Collins2014-09-251-0/+79
No functional changes.