<commit_before>import unittest
from ts3.protocol import TS3Proto


class TS3ProtoTest(unittest.TestCase):
    """ Tests the TS3Proto class """

    def setUp(self):

        self.ts3 = TS3Proto()

    def testCharacterEscaping(self):

        teststr = '|/ abcdefg| |'
        expected = r'\p\/\sabcdefg\p\s\p'

        res = self.ts3._escape_str(teststr)
        self.assertEqual(res, expected)

    def testControlEscaping(self):

        teststr = "\n\r\t"
        expected = r'\n\r\t'

        self.assertEqual(self.ts3._escape_str(teststr), expected)

    def testCharacterUnEscaping(self):

        teststr = r'\p\/\sabcdefg\p\s\p'
        expected = '|/ abcdefg| |'

        self.assertEqual(self.ts3._unescape_str(teststr), expected)

    def testFullCircle(self):

        teststr = '|/ abcdefg| |'
        res = self.ts3._unescape_str(self.ts3._escape_str(teststr))

        self.assertEqual(res, teststr)

    def testConstructBasic(self):
        self.assertEqual(self.ts3.construct_command('testcommand'), 'testcommand')
        self.assertEqual(self.ts3.construct_command('testcommand', opts=['test']), 'testcommand -test')
        self.assertEqual(self.ts3.construct_command('testcommand', opts=['test1', 'test2', 'test3']), 'testcommand -test1 -test2 -test3')
        self.assertEqual(self.ts3.construct_command('testcommand', keys={'key1': 'test'}), 'testcommand key1=test')
        self.assertEqual(self.ts3.construct_command('testcommand', keys={'key1': 'test', 'key2': 'test'}), 'testcommand key2=test key1=test')
        self.assertEqual(self.ts3.construct_command('testcommand', keys={'key1': 'test', 'key2': [1, 2, 3]}), 'testcommand key2=1|key2=2|key2=3 key1=test')
        self.assertEqual(self.ts3.construct_command('testcommand', keys={'key1': 'test', 'key2': 'test'}, opts=['test']), 'testcommand key2=test key1=test -test')
    
    def testParseData(self):
        # some response examples taken from http://media.teamspeak.com/ts3_literature/TeamSpeak%203%20Server%20Query%20Manual.pdf

        data = 'timestamp=1259356318 level=4 channel=Query msg=query\sfrom\s87.163.52.195:9\sissued:\slogview\slimitcount=30|timestamp=1259356148'<commit_msg>Add asserts for integer handling of the escape functions.<commit_after>import unittest
from ts3.protocol import TS3Proto


class TS3ProtoTest(unittest.TestCase):
    """ Tests the TS3Proto class """

    def setUp(self):

        self.ts3 = TS3Proto()

    def testCharacterEscaping(self):

        teststr = '|/ abcdefg| |'
        expected = r'\p\/\sabcdefg\p\s\p'

        res = self.ts3._escape_str(teststr)
        self.assertEqual(res, expected)

    def testControlEscaping(self):

        teststr = "\n\r\t"
        expected = r'\n\r\t'

        self.assertEqual(self.ts3._escape_str(teststr), expected)
        self.assertEqual(self.ts3._escape_str(1), '1')

    def testCharacterUnEscaping(self):

        teststr = r'\p\/\sabcdefg\p\s\p'
        expected = '|/ abcdefg| |'

        self.assertEqual(self.ts3._unescape_str(teststr), expected)
        self.assertEqual(self.ts3._unescape_str('1'), '1')
        self.assertEqual(self.ts3._unescape_str(1), '1')

    def testFullCircle(self):

        teststr = '|/ abcdefg| |'
        res = self.ts3._unescape_str(self.ts3._escape_str(teststr))

        self.assertEqual(res, teststr)

    def testConstructBasic(self):
        self.assertEqual(self.ts3.construct_command('testcommand'), 'testcommand')
        self.assertEqual(self.ts3.construct_command('testcommand', opts=['test']), 'testcommand -test')
        self.assertEqual(self.ts3.construct_command('testcommand', opts=['test1', 'test2', 'test3']), 'testcommand -test1 -test2 -test3')
        self.assertEqual(self.ts3.construct_command('testcommand', keys={'key1': 'test'}), 'testcommand key1=test')
        self.assertEqual(self.ts3.construct_command('testcommand', keys={'key1': 'test', 'key2': 'test'}), 'testcommand key2=test key1=test')
        self.assertEqual(self.ts3.construct_command('testcommand', keys={'key1': 'test', 'key2': [1, 2, 3]}), 'testcommand key2=1|key2=2|key2=3 key1=test')
        self.assertEqual(self.ts3.construct_command('testcommand', keys={'key1': 'test', 'key2': 'test'}, opts=['test']), 'testcommand key2=test key1=test -test')
    
    def testParseData(self):
        # some response examples taken from http://media.teamspeak.com/ts3_literature/TeamSpeak%203%20Server%20Query%20Manual.pdf

        data = 'timestamp=1259356318 level=4 channel=Query msg=query\sfrom\s192.168.3.11:9\sissued:\slogview\slimitcount=30|timestamp=1259356148'
{'fraction_non_alphanumeric': 0.1574682435392028, 'fraction_numerical': 0.04117389399912396, 'mean_word_length': 3.8023133543638274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6145240', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1536, 'n_words': 237}