Esempio n. 1
0
def test_client_download_timeout():
    def download_server_effect(bind, handler):
        return Mock(**{'socket.getsockname.return_value': bind})
    with patch('compoundpi.client.CompoundPiDownloadServer', side_effect=download_server_effect), \
            patch('compoundpi.client.CompoundPiServerList.transact') as l:
        l.return_value = {
            compoundpi.client.IPv4Address('192.168.0.1'): None,
        }
        client = compoundpi.client.CompoundPiClient()
        client._server.event = Mock()
        client._server.event.wait.return_value = False
        with pytest.raises(CompoundPiSendTimeout):
            client.download('192.168.0.1', 0, io.BytesIO())
Esempio n. 2
0
def test_client_download_ok():
    def download_server_effect(bind, handler):
        return Mock(**{'socket.getsockname.return_value': bind})
    with patch('compoundpi.client.CompoundPiDownloadServer', side_effect=download_server_effect), \
            patch('compoundpi.client.CompoundPiServerList.transact') as l:
        l.return_value = {
            compoundpi.client.IPv4Address('192.168.0.1'): None,
        }
        client = compoundpi.client.CompoundPiClient()
        client._server.event = Mock()
        client._server.event.wait.return_value = True
        client.download('192.168.0.1', 0, io.BytesIO())
        l.assert_called_once_with('SEND 0,5647', ['192.168.0.1'])
Esempio n. 3
0
def test_client_download_timeout():
    def download_server_effect(bind, handler):
        return Mock(**{'socket.getsockname.return_value': bind})
    with patch('compoundpi.client.CompoundPiDownloadServer', side_effect=download_server_effect), \
            patch('compoundpi.client.CompoundPiServerList.transact') as l:
        l.return_value = {
            compoundpi.client.IPv4Address('192.168.0.1'): None,
            }
        client = compoundpi.client.CompoundPiClient()
        client._server.event = Mock()
        client._server.event.wait.return_value = False
        with pytest.raises(CompoundPiSendTimeout):
            client.download('192.168.0.1', 0, io.BytesIO())
Esempio n. 4
0
def test_client_download_ok():
    def download_server_effect(bind, handler):
        return Mock(**{'socket.getsockname.return_value': bind})
    with patch('compoundpi.client.CompoundPiDownloadServer', side_effect=download_server_effect), \
            patch('compoundpi.client.CompoundPiServerList.transact') as l:
        l.return_value = {
            compoundpi.client.IPv4Address('192.168.0.1'): None,
            }
        client = compoundpi.client.CompoundPiClient()
        client._server.event = Mock()
        client._server.event.wait.return_value = True
        client.download('192.168.0.1', 0, io.BytesIO())
        l.assert_called_once_with('SEND 0,5647', ['192.168.0.1'])
Esempio n. 5
0
def test_client_download_exception():
    def download_server_effect(bind, handler):
        return Mock(**{'socket.getsockname.return_value': bind})
    with patch('compoundpi.client.CompoundPiDownloadServer', side_effect=download_server_effect), \
            patch('compoundpi.client.CompoundPiServerList.transact') as l:
        l.return_value = {
            compoundpi.client.IPv4Address('192.168.0.1'): None,
        }
        client = compoundpi.client.CompoundPiClient()
        client._server.event = Mock()
        client._server.event.wait.return_value = True
        client._server.exception = ValueError('Foo')
        with pytest.raises(ValueError) as excinfo:
            client.download('192.168.0.1', 0, io.BytesIO())
            assert excinfo.value.args == ('Foo', )
Esempio n. 6
0
def test_client_download_exception():
    def download_server_effect(bind, handler):
        return Mock(**{'socket.getsockname.return_value': bind})
    with patch('compoundpi.client.CompoundPiDownloadServer', side_effect=download_server_effect), \
            patch('compoundpi.client.CompoundPiServerList.transact') as l:
        l.return_value = {
            compoundpi.client.IPv4Address('192.168.0.1'): None,
            }
        client = compoundpi.client.CompoundPiClient()
        client._server.event = Mock()
        client._server.event.wait.return_value = True
        client._server.exception = ValueError('Foo')
        with pytest.raises(ValueError) as excinfo:
            client.download('192.168.0.1', 0, io.BytesIO())
            assert excinfo.value.args == ('Foo',)