https://src.fedoraproject.org/rpms/python-twisted/blob/rawhide/f/0003-Fix-tests-for-Python-3.11.patch From b0574816f622bc187389df2183e2bef0492fe5f5 Mon Sep 17 00:00:00 2001 From: eevel Date: Wed, 2 Nov 2022 20:35:55 -0500 Subject: [PATCH 3/6] Fix tests for Python 3.11 This is based on a subset of commits from this pull request. https://github.com/twisted/twisted/pull/11734 - fix twisted.persisted tests (cherry picked from commit 4f6d7fb0749429b092fe7538a7d2b11fe58319a6) - fix tests for twisted.spread (cherry picked from commit 525377178adfa987ed56be753aec0fce35d721dc) - fix test for twisted.web (cherry picked from commit afcc224a02f72e5d12fa35d223bd753e8086b135) - fix persisted tests in twisted.test (cherry picked from commit 4b5ab38b09b326cec7967e04bd4cae8a84bb6784) - fix twisted.trial tests (cherry picked from commit f8f56d45113e5f2467a5e8375186e5db6309dfc6) - make test_flatten backwards-compatible (cherry picked from commit d91675ac5ffe907fcdbb3d1cedb1240008d81fd1) --- a/src/twisted/persisted/aot.py +++ b/src/twisted/persisted/aot.py @@ -399,8 +399,10 @@ class AOTUnjellier: inst = klass.__new__(klass) if hasattr(klass, "__setstate__"): self.callAfter(inst.__setstate__, state) - else: + elif isinstance(state, dict): inst.__dict__ = state + else: + inst.__dict__ = state.__getstate__() return inst elif c is Ref: --- a/src/twisted/spread/flavors.py +++ b/src/twisted/spread/flavors.py @@ -398,6 +398,8 @@ class RemoteCopy(Unjellyable): object's dictionary (or a filtered approximation of it depending on my peer's perspective). """ + if not state: + state = {} state = { x.decode("utf8") if isinstance(x, bytes) else x: y for x, y in state.items() } --- a/src/twisted/spread/jelly.py +++ b/src/twisted/spread/jelly.py @@ -154,7 +154,8 @@ def _newInstance(cls, state): instance = _createBlank(cls) def defaultSetter(state): - instance.__dict__ = state + if isinstance(state, dict): + instance.__dict__ = state or {} setter = getattr(instance, "__setstate__", defaultSetter) setter(state) --- a/src/twisted/test/test_persisted.py +++ b/src/twisted/test/test_persisted.py @@ -378,6 +378,10 @@ class AOTTests(TestCase): def __dict__(self): raise AttributeError() + @property + def __getstate__(self): + raise AttributeError() + self.assertRaises(TypeError, aot.jellyToSource, UnknownType()) def test_basicIdentity(self): --- a/src/twisted/trial/test/test_pyunitcompat.py +++ b/src/twisted/trial/test/test_pyunitcompat.py @@ -218,8 +218,10 @@ class PyUnitResultTests(SynchronousTestCase): pyresult = pyunit.TestResult() result = PyUnitResultAdapter(pyresult) result.addError(self, f) + tback = "".join(traceback.format_exception(*exc_info)) self.assertEqual( - pyresult.errors[0][1], "".join(traceback.format_exception(*exc_info)) + pyresult.errors[0][1].endswith("ZeroDivisionError: division by zero\n"), + tback.endswith("ZeroDivisionError: division by zero\n"), ) def test_trialSkip(self): --- a/src/twisted/web/test/test_flatten.py +++ b/src/twisted/web/test/test_flatten.py @@ -706,10 +706,9 @@ class FlattenerErrorTests(SynchronousTestCase): Exception while flattening: \\[\\] - .* + > File ".*", line \\d*, in _flattenTree - element = await element - RuntimeError: example + element = await element.* """ ), flags=re.MULTILINE, -- 2.39.2