<commit_before>import unittest

import mock
from twisted.internet import protocol
from twisted.test import proto_helpers

from txrudp import heap, packet, rudp


class TestConnectionManagerAPI(unittest.TestCase):
    
    @classmethod
    def setUpClass(cls):
        cls.public_ip = '172.16.17.32'
        cls.port = 12345
        cls.addr = (cls.public_ip, cls.port)

    def _make_cm_with_mocks(self):
        cf = mock.Mock()
        return rudp.ConnectionMultiplexer(cf, self.public_ip)

    def test_default_init(self):
        cf = mock.Mock()
        cm = rudp.ConnectionMultiplexer(cf, self.public_ip)
        self.assertIsInstance(cm, protocol.DatagramProtocol)
        self.assertEqual(cm.public_ip, self.public_ip)
        self.assertFalse(cm.relaying)
        self.assertEqual(len(cm), 0)

    def test_full_init(self):
        cf = mock.Mock()
        cm = rudp.ConnectionMultiplexer(
            connection_factory=cf,
            public_ip='192.168.1.1',
            relaying=True
        )
        self.assertIsInstance(cm, protocol.DatagramProtocol)
        self.assertEqual(cm.public_ip, '192.168.1.1')
        self.assertTrue(cm.relaying)
        self.assertIsNone(cm.transport)
        self.assertEqual(len(cm), 0)

    def test_make_connection(self):
        transport = proto_helpers.StringTransportWithDisconnection()
        cm = self._make_cm_with_mocks()
        cm.makeConnection(transport)
        self.assertIs(cm.transport, transport)

    def test_get_nonexistent_connection(self):
        cm = self._make_cm_with_mocks()
        self.assertNotIn(self.addr, cm)
        with self.assertRaises(KeyError):
            con = cm[self.addr]
        
    def test_set_and_get_new_connection(self):
        cm = self._make_cm_with_mocks()
        mock_connection = mock.Mock()
        cm[self.addr] = mock_connection
        self.assertIn(self.addr, cm)
        self.assertEqual(cm[self.addr], mock_connection)

    def test_set_existent_connection(self):
        pass
<commit_msg>Stricten mocks used in tests.<commit_after>import unittest

import mock
from twisted.internet import protocol
from twisted.test import proto_helpers

from txrudp import connection, heap, packet, rudp


class TestConnectionManagerAPI(unittest.TestCase):
    
    @classmethod
    def setUpClass(cls):
        cls.public_ip = '172.16.17.32'
        cls.port = 12345
        cls.addr = (cls.public_ip, cls.port)

    def _make_cm_with_mocks(self):
        cf = mock.Mock(spec_set=connection.RUDPConnectionFactory)
        return rudp.ConnectionMultiplexer(cf, self.public_ip)

    def test_default_init(self):
        cf = mock.Mock()
        cm = rudp.ConnectionMultiplexer(cf, self.public_ip)
        self.assertIsInstance(cm, protocol.DatagramProtocol)
        self.assertEqual(cm.public_ip, self.public_ip)
        self.assertFalse(cm.relaying)
        self.assertEqual(len(cm), 0)

    def test_full_init(self):
        cf = mock.Mock()
        cm = rudp.ConnectionMultiplexer(
            connection_factory=cf,
            public_ip='192.168.1.1',
            relaying=True
        )
        self.assertIsInstance(cm, protocol.DatagramProtocol)
        self.assertEqual(cm.public_ip, '192.168.1.1')
        self.assertTrue(cm.relaying)
        self.assertIsNone(cm.transport)
        self.assertEqual(len(cm), 0)

    def test_make_connection(self):
        transport = proto_helpers.StringTransportWithDisconnection()
        cm = self._make_cm_with_mocks()
        cm.makeConnection(transport)
        self.assertIs(cm.transport, transport)

    def test_get_nonexistent_connection(self):
        cm = self._make_cm_with_mocks()
        self.assertNotIn(self.addr, cm)
        with self.assertRaises(KeyError):
            con = cm[self.addr]
        
    def test_set_and_get_new_connection(self):
        cm = self._make_cm_with_mocks()
        mock_connection = mock.Mock(spec_set=connection.RUDPConnection)
        cm[self.addr] = mock_connection
        self.assertIn(self.addr, cm)
        self.assertIs(cm[self.addr], mock_connection)

    def test_set_existent_connection(self):
        pass

{'fraction_non_alphanumeric': 0.0967898832684825, 'fraction_numerical': 0.01556420233463035, 'mean_word_length': 2.76993583868011, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '6568761', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1279, 'n_words': 209}