Skip to content

Commit

Permalink
Make unbuildReactor private
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonspeed committed Oct 12, 2023
1 parent 255823c commit d6f72ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
15 changes: 7 additions & 8 deletions src/twisted/internet/test/reactormixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def tearDown(self):
% (process.reapProcessHandlers,)
)

def unbuildReactor(self, reactor, globalReactorWasMunged=True):
def _unbuildReactor(self, reactor):
"""
Clean up any resources which may have been allocated for the given
reactor by its creation or by a test which used it.
Expand Down Expand Up @@ -247,12 +247,11 @@ def unbuildReactor(self, reactor, globalReactorWasMunged=True):
for c in calls:
c.cancel()

if globalReactorWasMunged:
# Restore the original reactor state:
from twisted.internet import reactor as globalReactor
# Restore the original reactor state:
from twisted.internet import reactor as globalReactor

globalReactor.__dict__ = reactor._originalReactorDict
globalReactor.__class__ = reactor._originalReactorClass
globalReactor.__dict__ = reactor._originalReactorDict
globalReactor.__class__ = reactor._originalReactorClass

def buildReactor(self):
"""
Expand Down Expand Up @@ -299,15 +298,15 @@ def buildReactor(self):
if not required.providedBy(reactor)
]
if missing:
self.unbuildReactor(reactor)
self._unbuildReactor(reactor)
raise SkipTest(
"%s does not provide %s"
% (
fullyQualifiedName(reactor.__class__),
",".join([fullyQualifiedName(x) for x in missing]),
)
)
self.addCleanup(self.unbuildReactor, reactor)
self.addCleanup(self._unbuildReactor, reactor)
return reactor

def getTimeout(self):
Expand Down
15 changes: 5 additions & 10 deletions src/twisted/internet/test/test_stdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ def test_removeReader(self):
no longer polled.
"""
reactor = self.buildReactor()
self.addCleanup(self.unbuildReactor, reactor)


path = self.mktemp()
open(path, "wb").close()

Expand All @@ -122,8 +121,7 @@ def test_removeWriter(self):
no longer polled.
"""
reactor = self.buildReactor()
self.addCleanup(self.unbuildReactor, reactor)


# Cleanup might fail if file is GCed too soon:
self.f = f = open(self.mktemp(), "wb")

Expand All @@ -143,8 +141,7 @@ def test_removeAll(self):
filesystem files.
"""
reactor = self.buildReactor()
self.addCleanup(self.unbuildReactor, reactor)


path = self.mktemp()
open(path, "wb").close()

Expand All @@ -168,8 +165,7 @@ def test_getReaders(self):
C{reactor.getReaders} includes descriptors that are filesystem files.
"""
reactor = self.buildReactor()
self.addCleanup(self.unbuildReactor, reactor)


path = self.mktemp()
open(path, "wb").close()

Expand All @@ -189,8 +185,7 @@ def test_getWriters(self):
C{reactor.getWriters} includes descriptors that are filesystem files.
"""
reactor = self.buildReactor()
self.addCleanup(self.unbuildReactor, reactor)


# Cleanup might fail if file is GCed too soon:
self.f = f = open(self.mktemp(), "wb")

Expand Down

0 comments on commit d6f72ae

Please sign in to comment.