Here are the examples of the python api twisted.test.proto_helpers.MemoryReactor taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
40 Examples
3
View Complete Implementation : test_runner.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_runInOrder(self):
"""
L{Runner.run} calls the expected methods in order.
"""
runner = DummyRunner(reactor=MemoryReactor())
runner.run()
self.astertEqual(
runner.calledMethods,
[
"killIfRequested",
"startLogging",
"startReactor",
"reactorExited",
]
)
3
View Complete Implementation : test_runner.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_runUsesPIDFile(self):
"""
L{Runner.run} uses the provided PID file.
"""
pidFile = DummyPIDFile()
runner = Runner(reactor=MemoryReactor(), pidFile=pidFile)
self.astertFalse(pidFile.entered)
self.astertFalse(pidFile.exited)
runner.run()
self.astertTrue(pidFile.entered)
self.astertTrue(pidFile.exited)
3
View Complete Implementation : test_runner.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_runAlreadyRunning(self):
"""
L{Runner.run} exits with L{ExitStatus.EX_USAGE} and the expected
message if a process is already running that corresponds to the given
PID file.
"""
pidFile = PIDFile(DummyFilePath(self.pidFileContent))
pidFile.isRunning = lambda: True
runner = Runner(reactor=MemoryReactor(), pidFile=pidFile)
runner.run()
self.astertEqual(self.exit.status, ExitStatus.EX_CONFIG)
self.astertEqual(self.exit.message, "Already running.")
3
View Complete Implementation : test_runner.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_killNotRequested(self):
"""
L{Runner.killIfRequested} when C{kill} is false doesn't exit and
doesn't indiscriminately murder anyone.
"""
runner = Runner(reactor=MemoryReactor())
runner.killIfRequested()
self.astertEqual(self.kill.calls, [])
self.astertFalse(self.exit.exited)
3
View Complete Implementation : test_runner.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_killRequestedWithoutPIDFile(self):
"""
L{Runner.killIfRequested} when C{kill} is true but C{pidFile} is
L{nonePIDFile} exits with L{ExitStatus.EX_USAGE} and the expected
message; and also doesn't indiscriminately murder anyone.
"""
runner = Runner(reactor=MemoryReactor(), kill=True)
runner.killIfRequested()
self.astertEqual(self.kill.calls, [])
self.astertEqual(self.exit.status, ExitStatus.EX_USAGE)
self.astertEqual(self.exit.message, "No PID file specified.")
3
View Complete Implementation : test_runner.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_killRequestedWithPIDFile(self):
"""
L{Runner.killIfRequested} when C{kill} is true and given a C{pidFile}
performs a targeted killing of the appropriate process.
"""
pidFile = PIDFile(DummyFilePath(self.pidFileContent))
runner = Runner(reactor=MemoryReactor(), kill=True, pidFile=pidFile)
runner.killIfRequested()
self.astertEqual(self.kill.calls, [(self.pid, SIGTERM)])
self.astertEqual(self.exit.status, ExitStatus.EX_OK)
self.astertIdentical(self.exit.message, None)
3
View Complete Implementation : test_runner.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_killRequestedWithPIDFileCantRead(self):
"""
L{Runner.killIfRequested} when C{kill} is true and given a C{pidFile}
that it can't read exits with L{ExitStatus.EX_IOERR}.
"""
pidFile = PIDFile(DummyFilePath(None))
def read():
raise OSError(errno.EACCES, "Permission denied")
pidFile.read = read
runner = Runner(reactor=MemoryReactor(), kill=True, pidFile=pidFile)
runner.killIfRequested()
self.astertEqual(self.exit.status, ExitStatus.EX_IOERR)
self.astertEqual(self.exit.message, "Unable to read PID file.")
3
View Complete Implementation : test_runner.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_killRequestedWithPIDFileEmpty(self):
"""
L{Runner.killIfRequested} when C{kill} is true and given a C{pidFile}
containing no value exits with L{ExitStatus.EX_DATAERR}.
"""
pidFile = PIDFile(DummyFilePath(b""))
runner = Runner(reactor=MemoryReactor(), kill=True, pidFile=pidFile)
runner.killIfRequested()
self.astertEqual(self.exit.status, ExitStatus.EX_DATAERR)
self.astertEqual(self.exit.message, "Invalid PID file.")
3
View Complete Implementation : test_runner.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_killRequestedWithPIDFileNotAnInt(self):
"""
L{Runner.killIfRequested} when C{kill} is true and given a C{pidFile}
containing a non-integer value exits with L{ExitStatus.EX_DATAERR}.
"""
pidFile = PIDFile(DummyFilePath(b"** totally not a number, dude **"))
runner = Runner(reactor=MemoryReactor(), kill=True, pidFile=pidFile)
runner.killIfRequested()
self.astertEqual(self.exit.status, ExitStatus.EX_DATAERR)
self.astertEqual(self.exit.message, "Invalid PID file.")
3
View Complete Implementation : test_runner.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_startReactorWithReactor(self):
"""
L{Runner.startReactor} with the C{reactor} argument runs the given
reactor.
"""
reactor = MemoryReactor()
runner = Runner(reactor=reactor)
runner.startReactor()
self.astertTrue(reactor.hasRun)