コード例 #1
0
 def test_instant_return(self):
     """ Test if wait_for_output returns instantly if the buffer
         already contains the match-string
     """
     with patch('subprocess.Popen.__init__') as mock:
         mon = ProcessMonitor('abc')
         mon._buffer = 'aaa ZZZ ccc'
         mon.wait_for_output('ZZZ', timeout=0, count=1)
         mock.assert_called_once()
コード例 #2
0
 def test_instant_return_two_times_in_buffer(self):
     """ Test if wait_for_output returns instantly if the buffer
         contains the match-string two times and a one-time match
         is requested
     """
     with patch('subprocess.Popen.__init__') as mock:
         mon = ProcessMonitor('abc')
         mon._buffer = 'aaa ZZZ ccc ZZZ ddd'
         mon.wait_for_output('ZZZ', timeout=0, count=1)
         mock.assert_called_once()
コード例 #3
0
 def test_fail_not_a_timeout(self):
     """ Test if wait_for_output fails if select.select returns without
         no readable pipe and the timeout is not reached yet
     """
     with patch('select.select') as selectmock:
         selectmock.return_value = ([], [], [])
         with patch('subprocess.Popen.__init__') as mock:
             mon = ProcessMonitor('abc')
             mon.stdout = 123
             mon._buffer = 'aaa bbb ccc'
             with pytest.raises(SelectError):
                 mon.wait_for_output('ZZZ', timeout=500, count=1)
                 mock.assert_called_once()
コード例 #4
0
 def test_instant_fail_two_times(self):
     """ Test if wait_for_output fails instantly if the buffer
         contains the match-string only one times and a two-times
         match is requested
     """
     with patch('select.select') as selectmock:
         selectmock.return_value = ([], [], [])
         with patch('subprocess.Popen.__init__'):
             mon = ProcessMonitor('abc')
             mon.stdout = 123
             mon._buffer = 'aaa ZZZ bbb ccc'
             with pytest.raises(MatchTimeoutError):
                 mon.wait_for_output('ZZZ', timeout=0, count=2)
         selectmock.assert_called_once()
コード例 #5
0
 def test_instant_fail(self):
     """ Test if wait_for_output fails instantly if the buffer
         does not contain the match-string and timeout is 0
         (mocking select.select to return instantly with no
         readable buffer when timeout is 0)
     """
     with patch('select.select') as selectmock:
         selectmock.return_value = ([], [], [])
         with patch('subprocess.Popen.__init__') as mock:
             mon = ProcessMonitor('abc')
             mon.stdout = None
             mon._buffer = 'aaa bbb ccc'
             with pytest.raises(MatchTimeoutError):
                 mon.wait_for_output('ZZZ', timeout=0, count=1)
             mock.assert_called_once()