class documentation

Base class for IReactorProcess tests which defines some tests which can be applied to PTY or non-PTY uses of spawnProcess.

Subclasses are expected to set the usePTY attribute to True or False.

Method test_changeGID If a value is passed for IReactorProcess.spawnProcess's gid, the child process is run with that GID.
Method test_changeUID If a value is passed for IReactorProcess.spawnProcess's uid, the child process is run with that UID.
Method test_errorDuringExec When os.execvpe raises an exception, it will format that exception on stderr as UTF-8, regardless of system encoding information.
Method test_openFileDescriptors Processes spawned with spawnProcess() close all extraneous file descriptors in the parent. They do have a stdin, stdout, and stderr open.
Method test_processExitedRaises If IProcessProtocol.processExited raises an exception, it is logged.
Method test_processExitedWithSignal The reason argument passed to IProcessProtocol.processExited is a ProcessTerminated instance if the child process exits with a signal.
Method test_processTransportInterface IReactorProcess.spawnProcess connects the protocol passed to it to a transport which provides IProcessTransport.
Method test_spawnProcessEarlyIsReaped If, before the reactor is started with IReactorCore.run, a process is started with IReactorProcess.spawnProcess and terminates, the process is reaped once the reactor is started.
Method test_systemCallUninterruptedByChildExit If a child process exits while a system call is in progress, the system call should not be interfered with. In particular, it should not fail with EINTR.
Method test_timelyProcessExited If a spawned process exits, processExited will be called in a timely manner.
Method test_write IProcessTransport.write writes the specified bytes to the standard input of the child process.
Method test_writeSequence IProcessTransport.writeSequence writes the specified list of bytes to the standard input of the child process.
Method test_writeToChild IProcessTransport.writeToChild writes the specified bytes to the specified file descriptor of the child process.
Method test_writeToChildBadFileDescriptor IProcessTransport.writeToChild raises KeyError if passed a file descriptor which is was not set up by IReactorProcess.spawnProcess.
Class Variable requiredInterfaces Undocumented
Method _changeIDTest Launch a child process, using either the uid or gid argument to IReactorProcess.spawnProcess to change either its UID or GID to a different value. If the child process reports this hasn't happened, raise an exception to fail the test.
Method _writeTest Helper for testing IProcessTransport write functionality. This method spawns a child process and gives write a chance to write some bytes to it. It then verifies that the bytes were actually written to it (by relying on the child process to echo them back).

Inherited from ReactorBuilder:

Class Method makeTestCaseClasses Create a SynchronousTestCase subclass which mixes in cls for each known reactor and return a dict mapping their names to them.
Method buildReactor Create and return a reactor using self.reactorFactory.
Method getTimeout Determine how long to run the test before considering it failed.
Method runReactor Run the reactor for at most the given amount of time.
Method setUp Clear the SIGCHLD handler, if there is one, to ensure an environment like the one which exists prior to a call to reactor.run.
Method tearDown Restore the original SIGCHLD handler and reap processes as long as there seem to be any remaining.
Method unbuildReactor Clean up any resources which may have been allocated for the given reactor by its creation or by a test which used it.
Class Variable skippedReactors A dict mapping FQPN strings of reactors for which the tests defined by this class will be skipped to strings giving the skip message.
Instance Variable originalHandler The SIGCHLD handler which was installed when setUp ran and which will be re-installed when tearDown runs.
Instance Variable reactorFactory A no-argument callable which returns the reactor to use for testing.
Instance Variable _reactors A list of FQPN strings giving the reactors for which SynchronousTestCases will be created.

If a value is passed for IReactorProcess.spawnProcess's gid, the child process is run with that GID.

If a value is passed for IReactorProcess.spawnProcess's uid, the child process is run with that UID.

@onlyOnPOSIX
def test_errorDuringExec(self): (source)

When os.execvpe raises an exception, it will format that exception on stderr as UTF-8, regardless of system encoding information.

@skipIf(platform.isWindows(), 'Test only applies to POSIX platforms.')
@skipIf(platform.isMacOSX() and (os.environ.get('CI', '').lower() == 'true'), 'Skipped on macOS CI env.')
def test_openFileDescriptors(self): (source)

Processes spawned with spawnProcess() close all extraneous file descriptors in the parent. They do have a stdin, stdout, and stderr open.

def test_processExitedRaises(self): (source)

If IProcessProtocol.processExited raises an exception, it is logged.

def test_processExitedWithSignal(self): (source)

The reason argument passed to IProcessProtocol.processExited is a ProcessTerminated instance if the child process exits with a signal.

def test_processTransportInterface(self): (source)

IReactorProcess.spawnProcess connects the protocol passed to it to a transport which provides IProcessTransport.

@skipIf((getattr(signal, 'SIGCHLD', None) is None), 'Platform lacks SIGCHLD, early-spawnProcess test can\'t work.')
def test_spawnProcessEarlyIsReaped(self): (source)

If, before the reactor is started with IReactorCore.run, a process is started with IReactorProcess.spawnProcess and terminates, the process is reaped once the reactor is started.

def test_systemCallUninterruptedByChildExit(self): (source)

If a child process exits while a system call is in progress, the system call should not be interfered with. In particular, it should not fail with EINTR.

Older versions of Twisted installed a SIGCHLD handler on POSIX without using the feature exposed by the SA_RESTART flag to sigaction(2). The most noticeable problem this caused was for blocking reads and writes to sometimes fail with EINTR.

def test_timelyProcessExited(self): (source)

If a spawned process exits, processExited will be called in a timely manner.

def test_write(self): (source)

IProcessTransport.write writes the specified bytes to the standard input of the child process.

def test_writeSequence(self): (source)

IProcessTransport.writeSequence writes the specified list of bytes to the standard input of the child process.

def test_writeToChild(self): (source)

IProcessTransport.writeToChild writes the specified bytes to the specified file descriptor of the child process.

def test_writeToChildBadFileDescriptor(self): (source)

IProcessTransport.writeToChild raises KeyError if passed a file descriptor which is was not set up by IReactorProcess.spawnProcess.

def _changeIDTest(self, which): (source)

Launch a child process, using either the uid or gid argument to IReactorProcess.spawnProcess to change either its UID or GID to a different value. If the child process reports this hasn't happened, raise an exception to fail the test.

Parameters
whichEither b"uid" or b"gid".
def _writeTest(self, write): (source)

Helper for testing IProcessTransport write functionality. This method spawns a child process and gives write a chance to write some bytes to it. It then verifies that the bytes were actually written to it (by relying on the child process to echo them back).

Parameters
writeA two-argument callable. This is invoked with a process transport and some bytes to write to it.