def _spawn(script, outputFD): """ Start a script that is a peer of this test as a subprocess. @param script: the module name of the script in this directory (no package prefix, no '.py') @type script: C{str} @rtype: L{StartStopProcessProtocol} """ pyExe = FilePath(sys.executable).asBytesMode().path env = bytesEnviron() env[b"PYTHONPATH"] = FilePath(pathsep.join(sys.path)).asBytesMode().path sspp = StartStopProcessProtocol() reactor.spawnProcess( sspp, pyExe, [ pyExe, FilePath(__file__).sibling(script + ".py").asBytesMode().path, intToBytes(outputFD), ], env=env, childFDs={ 0: "w", 1: "r", 2: "r", outputFD: outputFD }) return sspp
def _spawn(script, outputFD): """ Start a script that is a peer of this test as a subprocess. @param script: the module name of the script in this directory (no package prefix, no '.py') @type script: C{str} @rtype: L{StartStopProcessProtocol} """ pyExe = FilePath(sys.executable).asBytesMode().path env = bytesEnviron() env[b"PYTHONPATH"] = FilePath( pathsep.join(sys.path)).asBytesMode().path sspp = StartStopProcessProtocol() reactor.spawnProcess( sspp, pyExe, [ pyExe, FilePath(__file__).sibling(script + ".py").asBytesMode().path, intToBytes(outputFD), ], env=env, childFDs={0: "w", 1: "r", 2: "r", outputFD: outputFD} ) return sspp
def test_alwaysBytes(self): """ The output of L{BytesEnviron} should always be a L{dict} with L{bytes} values and L{bytes} keys. """ result = bytesEnviron() types = set() for key, val in iteritems(result): types.add(type(key)) types.add(type(val)) self.assertEqual(list(types), [bytes])
_uidgidSkip = None if platform.isWindows(): resource = None process = None _uidgidSkip = "Cannot change UID/GID on Windows" properEnv = dict(os.environ) properEnv["PYTHONPATH"] = os.pathsep.join(sys.path) else: import resource from twisted.internet import process if os.getuid() != 0: _uidgidSkip = "Cannot change UID/GID except as root" properEnv = bytesEnviron() properEnv[b"PYTHONPATH"] = os.pathsep.join(sys.path).encode( sys.getfilesystemencoding()) def onlyOnPOSIX(testMethod): """ Only run this test on POSIX platforms. @param testMethod: A test function, being decorated. @return: the C{testMethod} argument. """ if resource is None: testMethod.skip = "Test only applies to POSIX platforms." return testMethod
from twisted.conch.insults import insults from twisted.conch import recvline from twisted.python import reflect, components, filepath from twisted.python.compat import iterbytes, bytesEnviron from twisted.python.runtime import platform from twisted.internet import defer, error from twisted.trial import unittest from twisted.cred import portal from twisted.test.proto_helpers import StringTransport if platform.isWindows(): properEnv = dict(os.environ) properEnv["PYTHONPATH"] = os.pathsep.join(sys.path) else: properEnv = bytesEnviron() properEnv[b"PYTHONPATH"] = os.pathsep.join(sys.path).encode( sys.getfilesystemencoding()) class ArrowsTests(unittest.TestCase): def setUp(self): self.underlyingTransport = StringTransport() self.pt = insults.ServerProtocol() self.p = recvline.HistoricRecvLine() self.pt.protocolFactory = lambda: self.p self.pt.factory = self self.pt.makeConnection(self.underlyingTransport)