コード例 #1
0
ファイル: test_process.py プロジェクト: zendesk/ampoule
    def test_failing_deferToProcess(self):
        """
        Test failing subprocesses and the way they terminate and preserve
        failing information.
        """
        s = sio()
        a = FakeAMP(s)
        STRING = b"ciao"
        BOOT = """\
import sys
def main(arg):
    raise Exception(arg)
main(sys.argv[1])
"""
        starter = main.ProcessStarter(bootstrap=BOOT, args=(STRING,), packages=("twisted", "ampoule"))
        ready, finished = starter.startPythonProcess(main.AMPConnector(a), "I'll be ignored")

        self.assertFailure(finished, error.ProcessTerminated)
        finished.addErrback(lambda reason: self.assertEquals(reason.getMessage(), STRING))
        return finished
コード例 #2
0
ファイル: test_process.py プロジェクト: zendesk/ampoule
    def test_env_setting(self):
        """
        Test that and environment variable passed to the process starter
        is correctly passed to the child process.
        """
        s = sio()
        a = FakeAMP(s)
        STRING = b"ciao"
        BOOT = """\
import sys, io, os
def main():
    with io.open(4, 'w' + ('b' if bytes is str else '')) as f:
        f.write(os.environ['FOOBAR'])
main()
"""
        starter = main.ProcessStarter(bootstrap=BOOT,
                                      packages=("twisted", "ampoule"),
                                      env={"FOOBAR": STRING})
        amp, finished = starter.startPythonProcess(main.AMPConnector(a), "I'll be ignored")
        return finished.addCallback(lambda _: self.assertEquals(s.getvalue(), STRING))
コード例 #3
0
ファイル: test_process.py プロジェクト: zendesk/ampoule
    def test_startProcess(self):
        """
        Test that startProcess actually starts a subprocess and that
        it receives data back from the process through AMP.
        """
        s = sio()
        a = FakeAMP(s)
        STRING = b"ciao"
        BOOT = """\
import sys, os
def main(arg):
    os.write(4, arg.encode("utf-8"))
main(sys.argv[1])
"""
        starter = main.ProcessStarter(bootstrap=BOOT,
                                      args=(STRING,),
                                      packages=("twisted", "ampoule"))

        amp, finished = starter.startPythonProcess(main.AMPConnector(a))
        return finished.addCallback(lambda _: self.assertEquals(s.getvalue(), STRING))