Skip to content

Commit

Permalink
#10343 - run tests w/ python 3.11 (#11734)
Browse files Browse the repository at this point in the history
Add support for running tests w/ Python 3.11 on Windows, MacOS, and Linux.
  • Loading branch information
glyph committed Nov 5, 2022
2 parents 8e7857d + 4c9bd3c commit a604afd
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 8 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/test.yaml
Expand Up @@ -122,8 +122,11 @@ jobs:
# Just Python 3.9 with default settings.
- python-version: '3.9'

# Just Python 3.11 with default settings.
- python-version: '3.11'

# Newest macOS and newest Python supported versions.
- python-version: '3.10'
- python-version: '3.11'
runs-on: 'macos-12'
job-name: 'macos-12-default-tests'

Expand All @@ -138,7 +141,7 @@ jobs:
trial-args: '--reactor=select'

# Windows, newest Python supported version with iocp reactor.
- python-version: '3.10'
- python-version: '3.11'
runs-on: 'windows-2022'
tox-env: 'alldeps-withcov-windows'
job-name: 'win-default-tests-iocp'
Expand Down
1 change: 1 addition & 0 deletions src/twisted/newsfragments/10343.feature
@@ -0,0 +1 @@
Twisted now officially supports Python 3.11.
4 changes: 3 additions & 1 deletion src/twisted/persisted/aot.py
Expand Up @@ -399,8 +399,10 @@ def unjellyAO(self, ao):
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:
Expand Down
2 changes: 2 additions & 0 deletions src/twisted/spread/flavors.py
Expand Up @@ -398,6 +398,8 @@ def setCopyableState(self, state):
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()
}
Expand Down
3 changes: 2 additions & 1 deletion src/twisted/spread/jelly.py
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/twisted/test/test_persisted.py
Expand Up @@ -378,6 +378,10 @@ class UnknownType:
def __dict__(self):
raise AttributeError()

@property
def __getstate__(self):
raise AttributeError()

self.assertRaises(TypeError, aot.jellyToSource, UnknownType())

def test_basicIdentity(self):
Expand Down
4 changes: 3 additions & 1 deletion src/twisted/trial/test/test_pyunitcompat.py
Expand Up @@ -218,8 +218,10 @@ def test_tracebackFromCleanFailure(self):
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):
Expand Down
6 changes: 3 additions & 3 deletions src/twisted/web/test/test_flatten.py
Expand Up @@ -706,15 +706,15 @@ def render(self, request: Optional[IRequest]) -> Flattenable:
Exception while flattening:
\\[<unrenderable>\\]
<unrenderable>
.*
<Deferred at .* current result: <twisted.python.failure.Failure builtins.RuntimeError: example>>
File ".*", line \\d*, in _flattenTree
element = await element
RuntimeError: example
element = await element.*
"""
),
flags=re.MULTILINE,
),
)
self.assertIn("RuntimeError: example", str(failure.value))
# The original exception is unmodified and will be logged separately if
# unhandled.
self.failureResultOf(failing, RuntimeError)
Expand Down

0 comments on commit a604afd

Please sign in to comment.