# 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


@patch('mcm.librouteros.connections.encword', side_effect = [ b'first', b'second' ])
class EncodeSentence(unittest.TestCase):

    def test_calls_encword( self, enc_word_mock ):
        sentence = ('first', 'second')
        connections.encsnt( sentence )
        assert enc_word_mock.mock_calls == [ call(elem) for elem in sentence ]

    def test_returns_bytes_encoded_sentence_with_appended_EOS(self, enc_word_mock):
        assert connections.encsnt(( 'first', 'second' )) == b'firstsecond\x00'


def test_sentence_decoding():
    assert connections.decsnt( (b'first', b'second') ) == ('first', 'second')

def test_non_ASCII_sentence_decoding():
    non_ascii = b'\xc5\x82\xc4\x85'
    with pytest.raises(ConnError) as error:
        connections.decsnt((non_ascii,))
    assert str(non_ascii) in str(error.value)



@patch('mcm.librouteros.connections.declen')
class GetLengths(unittest.TestCase):


    def setUp(self):

# 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



@patch('mcm.librouteros.connections.encword', side_effect = [ b'first', b'second' ])
class EncodeSentence(unittest.TestCase):

    def test_calls_encword( self, enc_word_mock ):
        sentence = ('first', 'second')
        connections.encsnt( sentence )
        assert enc_word_mock.mock_calls == [ call(elem) for elem in sentence ]

    def test_returns_bytes_encoded_sentence_with_appended_EOS(self, enc_word_mock):
        assert connections.encsnt(( 'first', 'second' )) == b'firstsecond\x00'


def test_sentence_decoding():
    assert connections.decsnt( (b'first', b'second') ) == ('first', 'second')

def test_non_ASCII_sentence_decoding():
    non_ascii = b'\xc5\x82\xc4\x85'
    with pytest.raises(ConnError) as error:
        connections.decsnt((non_ascii,))
    assert str(non_ascii) in str(error.value)



@patch('mcm.librouteros.connections.declen')
class GetLengths(unittest.TestCase):


    def setUp(self):

        self.rwo = connections.ReaderWriter( None, None )