def test_input_splitter(self): m_sbuf = self._make_mock() m_lbuf = self._make_mock() splitter = InputSplitter(m_sbuf, m_lbuf) splitter.write_data('foo') self._assertCallsEqual( m_sbuf, [call.enqueue_data('foo')]) self._assertCallsEqual( m_lbuf, [call.write_data('foo')]) self._reset_mocks() splitter.finish() self._assertCallsEqual( m_sbuf, []) self._assertCallsEqual( m_lbuf, [call.finish()])
def _subtest_start_subprocess_twice(self): m_Popen = self._patch('subprocess.Popen') m_close = self._patch('os.close') m_Popen.side_effect = [self.m_proc1, self.m_proc2] self.pm.start_subprocess(self.argv1) self.pm.start_subprocess(self.argv2) self._assertCallsEqual( m_Popen, [call(self.argv1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE), call(self.argv2, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)]) self._assertCallsEqual( self.m_proc1, [call.stdin.fileno(), call.stdout.fileno(), call.stderr.fileno()]) self._assertCallsEqual( self.m_proc2, [call.stdout.fileno(), call.stderr.fileno()]) self._assertCallsEqual( m_close, []) self._assertCallsEqual( self.m_iom, [call.add_sink(sentinel.proc1_stdin, self.m_stdinsink), call.add_source(sentinel.proc1_stdout, ArgIsInstance(LineBuffer), permanent=False), call.add_source(sentinel.proc1_stderr, ArgIsInstance(LineBuffer), permanent=False), call.add_source(sentinel.proc2_stdout, ArgIsInstance(LineBuffer), permanent=False), call.add_source(sentinel.proc2_stderr, ArgIsInstance(LineBuffer), permanent=False)]) self._assertCallsEqual( self.m_stdoutwriter, [call.enqueue_data("1970-01-01 00:00:00+0000 1001 * Launched ['echo', 'hello', 'world']\n"), call.enqueue_data("1970-01-01 00:00:01+0000 1002 * Launched ['date']\n")])
def test_format_writer(self): def counter(): counter.c += 1 return counter.c counter.c = 0 m_sinkbuf = self._make_mock() fw = MessageFormatter( m_sinkbuf, '{const} {counter} {message}', const=lambda : '<A constant>', counter=counter) fw.write_message('foo') fw.write_message('bar') self._assertCallsEqual( m_sinkbuf, [call.enqueue_data('<A constant> 1 foo\n'), call.enqueue_data('<A constant> 2 bar\n')])