예제 #1
0
def test_connection_batch_start_fail():
    with mock.patch('socket.socket'), mock.patch('select.select'):
        select.select.return_value = [False]
        conn = Connection('myhost', 1234)
        with pytest.raises(BatchStarted):
            conn.batch_start()
            conn.batch_start()
예제 #2
0
def test_connection_batch_start_fail():
    with mock.patch('socket.socket'), mock.patch('select.select'):
        select.select.return_value = [False]
        conn = Connection('myhost', 1234)
        with pytest.raises(BatchStarted):
            conn.batch_start()
            conn.batch_start()
예제 #3
0
def test_connection_batch_forget():
    with mock.patch('socket.socket'), mock.patch('select.select'):
        select.select.return_value = [False]
        conn = Connection('myhost', 1234)
        conn._wfile.write.reset_mock()
        conn.batch_start()
        conn.send('foo()')
        conn.send('bar()')
        conn.send('baz()')
        conn.batch_forget()
        assert not conn._wfile.write.called
예제 #4
0
def test_connection_batch_forget():
    with mock.patch('socket.socket'), mock.patch('select.select'):
        select.select.return_value = [False]
        conn = Connection('myhost', 1234)
        conn._wfile.write.reset_mock()
        conn.batch_start()
        conn.send('foo()')
        conn.send('bar()')
        conn.send('baz()')
        conn.batch_forget()
        assert not conn._wfile.write.called
예제 #5
0
def test_connection_batch_send():
    with mock.patch('socket.socket'), mock.patch('select.select'):
        select.select.return_value = [False]
        conn = Connection('myhost', 1234)
        conn._wfile.write.reset_mock()
        with conn.batch_start():
            conn.send('foo()')
            conn.send('bar()')
            conn.send('baz()')
        conn._wfile.write.assert_called_once_with(b'foo()\nbar()\nbaz()\n')
예제 #6
0
def test_connection_batch_send():
    with mock.patch('socket.socket'), mock.patch('select.select'):
        select.select.return_value = [False]
        conn = Connection('myhost', 1234)
        conn._wfile.write.reset_mock()
        with conn.batch_start():
            conn.send('foo()')
            conn.send('bar()')
            conn.send('baz()')
        conn._wfile.write.assert_called_once_with(b'foo()\nbar()\nbaz()\n')
예제 #7
0
def test_connection_batch_exception():
    with mock.patch('socket.socket'), mock.patch('select.select'):
        select.select.return_value = [False]
        conn = Connection('myhost', 1234)
        conn._wfile.write.reset_mock()
        try:
            with conn.batch_start():
                conn.send('foo()')
                conn.send('bar()')
                conn.send('baz()')
                raise Exception('boo')
        except Exception:
            pass
        assert not conn._wfile.write.called
예제 #8
0
def test_connection_batch_exception():
    with mock.patch('socket.socket'), mock.patch('select.select'):
        select.select.return_value = [False]
        conn = Connection('myhost', 1234)
        conn._wfile.write.reset_mock()
        try:
            with conn.batch_start():
                conn.send('foo()')
                conn.send('bar()')
                conn.send('baz()')
                raise Exception('boo')
        except Exception:
            pass
        assert not conn._wfile.write.called