# Path: mcm/librouteros/connections.py
# def enclen( length ):
# def declen( bytes ):
# def decsnt( sentence ):
# def encsnt( sentence ):
# def encword( word ):
# def log_snt( logger, sentence, direction ):
#     def __init__( self, sock, log ):
#     def writeSnt( self, snt ):
#     def readSnt( self ):
#     def readSock( self, length ):
#     def writeSock( self, string ):
#     def getLen( self ):
#     def close( self ):
#         XOR = 0
#         XOR = 0x8000
#         XOR = 0xC00000
#         XOR = 0xE0000000
# class ReaderWriter:
# 
# Path: mcm/librouteros/exceptions.py
# class ConnError( LibError ):
#     '''
#     Connection related errors.
#     '''


import unittest
import pytest
from socket import SHUT_RDWR, error as SOCKET_ERROR, timeout as SOCKET_TIMEOUT, socket
from mock import MagicMock, call, patch
from mcm.librouteros import connections
from mcm.librouteros.exceptions import ConnError
    def test_calls_read_socket_less_than_2097152( self , dec_len_mock):
        self.rwo.readSock.side_effect = [ b'\xdf', b'\xff\xf4' ]
        self.rwo.getLen()
        expected_calls = [ call(1), call(2) ]
        self.assertEqual( self.rwo.readSock.mock_calls, expected_calls )

    def test_calls_read_socket_less_than_268435456( self , dec_len_mock):
        self.rwo.readSock.side_effect = [ b'\xef', b'\xff\xff\xf0' ]
        self.rwo.getLen()
        expected_calls = [ call(1), call(3) ]
        self.assertEqual( self.rwo.readSock.mock_calls, expected_calls )






class Test_socket_writing:


    def setup(self):
        self.connection = connections.ReaderWriter( sock=MagicMock(), log=None )

    def test_calls_sendall(self):
        self.connection.writeSock(b'some message')
        self.connection.sock.sendall.assert_called_once_with(b'some message')

    @pytest.mark.parametrize("exception", (SOCKET_ERROR, SOCKET_TIMEOUT))
    def test_raises_socket_errors(self, exception):
        self.connection.sock.sendall.side_effect = exception

# Path: mcm/librouteros/connections.py
# def enclen( length ):
# def declen( bytes ):
# def decsnt( sentence ):
# def encsnt( sentence ):
# def encword( word ):
# def log_snt( logger, sentence, direction ):
#     def __init__( self, sock, log ):
#     def writeSnt( self, snt ):
#     def readSnt( self ):
#     def readSock( self, length ):
#     def writeSock( self, string ):
#     def getLen( self ):
#     def close( self ):
#         XOR = 0
#         XOR = 0x8000
#         XOR = 0xC00000
#         XOR = 0xE0000000
# class ReaderWriter:
# 
# Path: mcm/librouteros/exceptions.py
# class ConnError( LibError ):
#     '''
#     Connection related errors.
#     '''


# Path: tests/test_connections.py
import unittest
import pytest
from socket import SHUT_RDWR, error as SOCKET_ERROR, timeout as SOCKET_TIMEOUT, socket
from mock import MagicMock, call, patch
from mcm.librouteros import connections
from mcm.librouteros.exceptions import ConnError

    def test_calls_read_socket_less_than_2097152( self , dec_len_mock):
        self.rwo.readSock.side_effect = [ b'\xdf', b'\xff\xf4' ]
        self.rwo.getLen()
        expected_calls = [ call(1), call(2) ]
        self.assertEqual( self.rwo.readSock.mock_calls, expected_calls )

    def test_calls_read_socket_less_than_268435456( self , dec_len_mock):
        self.rwo.readSock.side_effect = [ b'\xef', b'\xff\xff\xf0' ]
        self.rwo.getLen()
        expected_calls = [ call(1), call(3) ]
        self.assertEqual( self.rwo.readSock.mock_calls, expected_calls )






class Test_socket_writing:


    def setup(self):
        self.connection = connections.ReaderWriter( sock=MagicMock(), log=None )

    def test_calls_sendall(self):
        self.connection.writeSock(b'some message')
        self.connection.sock.sendall.assert_called_once_with(b'some message')

    @pytest.mark.parametrize("exception", (SOCKET_ERROR, SOCKET_TIMEOUT))
    def test_raises_socket_errors(self, exception):
        self.connection.sock.sendall.side_effect = exception

        with pytest.raises(ConnError):