예제 #1
0
 def test_recv_raises_timeout_if_nothing_read(self, select, os_read, Popen):
     stdout = Popen.return_value.stdout
     select.return_value = [stdout], None, None
     fileno = stdout.fileno.return_value
     os_read.side_effect = socket.timeout
     proxy = ProxyCommand("hi")
     with raises(socket.timeout):
         proxy.recv(5)
     assert os_read.call_args[0] == (fileno, 5)
예제 #2
0
 def test_timeout_affects_whether_timeout_is_raised(self, select, os_read,
                                                    Popen, time):
     stdout = Popen.return_value.stdout
     select.return_value = [stdout], None, None
     # Base case: None timeout means no timing out
     os_read.return_value = b"meh"
     proxy = ProxyCommand("yello")
     assert proxy.timeout is None
     # Implicit 'no raise' check
     assert proxy.recv(3) == b"meh"
     # Use settimeout to set timeout, and it is honored
     time.side_effect = [0, 10]  # elapsed > 7
     proxy = ProxyCommand("ohnoz")
     proxy.settimeout(7)
     assert proxy.timeout == 7
     with raises(socket.timeout):
         proxy.recv(3)
예제 #3
0
 def test_recv_returns_buffer_on_timeout_if_any_read(
         self, select, os_read, Popen):
     stdout = Popen.return_value.stdout
     select.return_value = [stdout], None, None
     fileno = stdout.fileno.return_value
     os_read.side_effect = [b"was", socket.timeout]
     proxy = ProxyCommand("hi")
     data = proxy.recv(5)
     assert data == b"was"  # not b"waste"
     assert os_read.call_args[0] == (fileno, 2)
예제 #4
0
 def test_recv_reads_from_process_stdout_returning_bytes(
         self, select, os_read, Popen):
     stdout = Popen.return_value.stdout
     select.return_value = [stdout], None, None
     fileno = stdout.fileno.return_value
     # Intentionally returning <5 at a time sometimes
     os_read.side_effect = [b"was", b"te", b"of ti", b"me"]
     proxy = ProxyCommand("hi")
     data = proxy.recv(5)
     assert data == b"waste"
     assert [x[0] for x in os_read.call_args_list] == [
         (fileno, 5),
         (fileno, 2),
     ]