def test_capture_out(): """ A simple test to see if we can execute a process and get the output. """ s = StringIO() p = PipedProcess('echo 1', out_callback=s.write, ) p.start() p.join() result = s.getvalue().rstrip() assert result == '1'
def test_kill(): """ Check that we can kill a process, and its subprocess. """ s = StringIO() p = PipedProcess(sys.executable + ' -c "a = raw_input();"', out_callback=s.write, ) p.start() while not hasattr(p, 'process'): sleep(0.1) p.process.kill() assert p.process.poll() is not None
def test_io(): """ Checks that we can send characters on stdin to the process. """ s = StringIO() p = PipedProcess(sys.executable + ' -c "a = raw_input(); print a"', out_callback=s.write, ) p.start() test_string = '12345\n' while not hasattr(p, 'process'): sleep(0.1) p.process.stdin.write(test_string) p.join() result = s.getvalue() assert result == test_string
def system_call(self, command_string): self._input_state = 'subprocess' event_loop = wx.EventLoop() def _end_system_call(): self._input_state = 'buffering' self._running_process = False event_loop.Exit() self._running_process = PipedProcess(command_string, out_callback=self.buffered_write, end_callback=_end_system_call) self._running_process.start() # XXX: Running a separate event_loop. Ugly. event_loop.Run() # Be sure to flush the buffer. self._buffer_flush(event=None)