From 25ae631e1f841ab77208c7defc23c88570438bdb Mon Sep 17 00:00:00 2001 From: caodongxia <315816521@qq.com> Date: Fri, 1 Apr 2022 18:03:53 +0800 Subject: [PATCH] fixtest_monkeypatch failed --- fix-test_monkeypatch-failed.patch | 137 ++++++++++++++++++++++++++++++ python-fixtures.spec | 11 ++- 2 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 fix-test_monkeypatch-failed.patch diff --git a/fix-test_monkeypatch-failed.patch b/fix-test_monkeypatch-failed.patch new file mode 100644 index 0000000..c555a17 --- /dev/null +++ b/fix-test_monkeypatch-failed.patch @@ -0,0 +1,137 @@ +From fe830674abd4926d96d38f9992f3e31b00cd891a Mon Sep 17 00:00:00 2001 +From: Stephen Finucane +Date: Thu, 25 Feb 2021 11:37:42 +0000 +Subject: [PATCH] Fix tests on Python 3.9 + +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 +--- + fixtures/_fixtures/monkeypatch.py | 9 +++- + fixtures/tests/_fixtures/test_monkeypatch.py | 48 ++++++++++++++------ + 2 files changed, 42 insertions(+), 15 deletions(-) + +diff --git a/fixtures/_fixtures/monkeypatch.py b/fixtures/_fixtures/monkeypatch.py +index b5e8564..710a79c 100644 +--- a/fixtures/_fixtures/monkeypatch.py ++++ b/fixtures/_fixtures/monkeypatch.py +@@ -83,9 +83,11 @@ def _coerce_values(obj, name, new_value, sentinel): + # bound state rather than having it bound to the new object + # it has been patched onto. + captured_method = new_value ++ + @functools.wraps(old_value) + def avoid_get(*args, **kwargs): + return captured_method(*args, **kwargs) ++ + new_value = avoid_get + + return (new_value, old_value) +@@ -138,18 +140,21 @@ def _setUp(self): + __import__(location, {}, {}) + except ImportError: + pass ++ + components = location.split('.') + current = __import__(components[0], {}, {}) + for component in components[1:]: + current = getattr(current, component) + sentinel = object() +- new_value, old_value = _coerce_values(current, attribute, +- self.new_value, sentinel) ++ new_value, old_value = _coerce_values( ++ current, attribute, self.new_value, sentinel) ++ + if self.new_value is self.delete: + if old_value is not sentinel: + delattr(current, attribute) + else: + setattr(current, attribute, new_value) ++ + if old_value is sentinel: + self.addCleanup(self._safe_delete, current, attribute) + else: +diff --git a/fixtures/tests/_fixtures/test_monkeypatch.py b/fixtures/tests/_fixtures/test_monkeypatch.py +index 6f11fab..746f6dd 100644 +--- a/fixtures/tests/_fixtures/test_monkeypatch.py ++++ b/fixtures/tests/_fixtures/test_monkeypatch.py +@@ -14,6 +14,7 @@ + # limitations under that license. + + import functools ++import sys + + import testtools + from testtools.matchers import Is +@@ -32,7 +33,7 @@ def foo_cls(cls): pass + + class D(object): + def bar(self): pass +- def bar_two_args(self, arg): ++ def bar_two_args(self, arg=None): + return (self, arg) + @classmethod + def bar_cls(cls): +@@ -188,14 +189,27 @@ def test_patch_classmethod_with_classmethod(self): + 'fixtures.tests._fixtures.test_monkeypatch.C.foo_cls', + D.bar_cls_args) + with fixture: +- cls, target_class = C.foo_cls() +- self.expectThat(cls, Is(D)) +- self.expectThat(target_class, Is(C)) +- cls, target_class = C().foo_cls() +- self.expectThat(cls, Is(D)) +- self.expectThat(target_class, Is(C)) +- self._check_restored_static_or_class_method(oldmethod, oldmethod_inst, +- C, 'foo_cls') ++ # Python 3.9 changes the behavior of the classmethod decorator so ++ # that it now honours the descriptor binding protocol [1]. ++ # This means we're now going to call the monkeypatched classmethod ++ # the way we would have if it hadn't been monkeypatched: simply ++ # with the class ++ # ++ # https://bugs.python.org/issue19072 ++ if sys.version_info >= (3, 9): ++ cls, = C.foo_cls() ++ self.expectThat(cls, Is(D)) ++ cls, = C().foo_cls() ++ self.expectThat(cls, Is(D)) ++ else: ++ cls, target_class = C.foo_cls() ++ self.expectThat(cls, Is(D)) ++ self.expectThat(target_class, Is(C)) ++ cls, target_class = C().foo_cls() ++ self.expectThat(cls, Is(D)) ++ self.expectThat(target_class, Is(C)) ++ self._check_restored_static_or_class_method( ++ oldmethod, oldmethod_inst, C, 'foo_cls') + + def test_patch_classmethod_with_function(self): + oldmethod = C.foo_cls +@@ -222,12 +236,20 @@ def test_patch_classmethod_with_boundmethod(self): + with fixture: + slf, cls = C.foo_cls() + self.expectThat(slf, Is(d)) +- self.expectThat(cls, Is(C)) ++ # See note in test_patch_classmethod_with_classmethod on changes in ++ # Python 3.9 ++ if sys.version_info >= (3, 9): ++ self.expectThat(cls, Is(None)) ++ else: ++ self.expectThat(cls, Is(C)) + slf, cls = C().foo_cls() + self.expectThat(slf, Is(d)) +- self.expectThat(cls, Is(C)) +- self._check_restored_static_or_class_method(oldmethod, oldmethod_inst, +- C, 'foo_cls') ++ if sys.version_info >= (3, 9): ++ self.expectThat(cls, Is(None)) ++ else: ++ self.expectThat(cls, Is(C)) ++ self._check_restored_static_or_class_method( ++ oldmethod, oldmethod_inst, C, 'foo_cls') + + def test_patch_function_with_staticmethod(self): + oldmethod = fake_no_args + \ No newline at end of file diff --git a/python-fixtures.spec b/python-fixtures.spec index 4800586..bbe0fa6 100644 --- a/python-fixtures.spec +++ b/python-fixtures.spec @@ -1,10 +1,12 @@ Name: python-fixtures Version: 3.0.0 -Release: 14 +Release: 15 Summary: A python contract for writing reusable state / support logic tests License: ASL 2.0 or BSD URL: https://launchpad.net/python-fixtures Source0: https://pypi.python.org/packages/source/f/fixtures/fixtures-%{version}.tar.gz +#Refer: https://github.com/testing-cabal/fixtures/commit/fe830674abd4926d96d38f9992f3e31b00cd891a +Patch0000: fix-test_monkeypatch-failed.patch BuildArch: noarch %description @@ -25,7 +27,7 @@ for unit testing. It includes some helper and adaptation logic to write your own fixtures using the fixtures contract. %prep -%autosetup -n fixtures-%{version} +%autosetup -n fixtures-%{version} -p1 %build %py3_build @@ -39,9 +41,12 @@ own fixtures using the fixtures contract. %files -n python3-fixtures %doc README GOALS NEWS Apache-2.0 BSD COPYING %{python3_sitelib}/fixtures -%{python3_sitelib}/fixtures-%{version}-py?.?.egg-info +%{python3_sitelib}/fixtures-%{version}-py%{python3_version}.egg-info %changelog +* Fri Apr 1 2022 caodongxia - 3.0.0-15 +- Fix test_monkeypatch failed due to python3.10 + * Tue Sep 29 2020 liuweibo - 3.0.0-14 - Fix Source0