<commit_before>import unittest
import unittest.mock as mock

import socket

from ogn.gateway.manage import run


class GatewayTest(unittest.TestCase):

    # try simple user interrupt
    @mock.patch('ogn.gateway.manage.ognGateway')
    def test_run_user_interruption(self, mock_gateway):
        instance = mock_gateway.return_value
        instance.run.side_effect = KeyboardInterrupt()

        run("user_1")

        instance.connect_db.assert_called_once_with()
        instance.connect.assert_called_once_with("user_1")
        instance.run.assert_called_once_with()
        instance.disconnect.assert_called_once_with()

    # make BrokenPipeErrors and a socket error (may happen) and then a user interrupt (important!)
    @mock.patch('ogn.gateway.manage.ognGateway')
    def test_run_multiple_errors(self, mock_gateway):
        instance = mock_gateway.return_value
        instance.run.side_effect = [BrokenPipeError(), socket.error(), KeyboardInterrupt()]

        run("user_2")

        instance.connect_db.assert_called_once_with()
        self.assertEqual(instance.connect.call_count, 3)
        self.assertEqual(instance.run.call_count, 3)
        self.assertEqual(instance.disconnect.call_count, 3)

if __name__ == '__main__':
    unittest.main()<commit_msg>Let disconnect crash once<commit_after>import unittest
import unittest.mock as mock

import socket

from ogn.gateway.manage import run


class GatewayTest(unittest.TestCase):

    # try simple user interrupt
    @mock.patch('ogn.gateway.manage.ognGateway')
    def test_run_user_interruption(self, mock_gateway):
        instance = mock_gateway.return_value
        instance.run.side_effect = KeyboardInterrupt()

        run("user_1")

        instance.connect_db.assert_called_once_with()
        instance.connect.assert_called_once_with("user_1")
        instance.run.assert_called_once_with()
        instance.disconnect.assert_called_once_with()

    # make BrokenPipeErrors and a socket error (may happen) and then a user interrupt (important!)
    @mock.patch('ogn.gateway.manage.ognGateway')
    def test_run_multiple_errors(self, mock_gateway):
        instance = mock_gateway.return_value
        instance.run.side_effect = [BrokenPipeError(), socket.error(), KeyboardInterrupt()]
        instance.disconnect.side_effect = [True, True, OSError()]

        run("user_2")

        instance.connect_db.assert_called_once_with()
        self.assertEqual(instance.connect.call_count, 3)
        self.assertEqual(instance.run.call_count, 3)
        self.assertEqual(instance.disconnect.call_count, 3)

if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.09634424980959634, 'fraction_numerical': 0.00456968773800457, 'mean_word_length': 3.820183486238532, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '3924027', 'n_tokens_mistral': 808, 'n_tokens_neox': 784, 'n_words': 140}