<commit_before>import unittest
import socket
import time
import threading
from tests import mock

from betfairlightweight.streaming.betfairstream import BetfairStream
from betfairlightweight.exceptions import SocketError


class BetfairStreamTest(unittest.TestCase):

    def setUp(self):
        self.mock_listener = mock.Mock()
        self.mock_listener.on_data.return_value = False
        self.unique_id = 1
        self.app_key = 'app_key'
        self.session_token = '<PASSWORD>'
        self.timeout = 6
        self.buffer_size = 1024
        self.description = 'test_stream'
        self.betfair_stream = BetfairStream(self.unique_id, self.mock_listener, self.app_key, self.session_token,
                                            self.timeout, self.buffer_size, self.description)

    def test_init(self):
        assert self.betfair_stream.unique_id == self.unique_id
        assert self.betfair_stream.listener == self.mock_listener
        assert self.betfair_stream.app_key == self.app_key
        assert self.betfair_stream.session_token == self.session_token
        assert self.betfair_stream.timeout == self.timeout
        assert self.betfair_stream.buffer_size == self.buffer_size
        assert self.betfair_stream.description == self.description
        assert self.betfair_stream.receive_count == 0
        assert self.betfair_stream.datetime_last_received is None

        assert self.betfair_stream._socket is None
        assert self.betfair_stream._running is False

    @mock.patch('betfairlightweight.streaming.betfairstream.BetfairStream.authenticate')
    @mock.patch('betfairlightweight.streaming.betfairstream.BetfairStream._connect')
    @mock.patch('betfairlightweight.streaming.betfairstream.threading')
    @mock.patch('betfairlightweight.streaming.betfairstream.BetfairStream._read_loop')
    def test_start(self, mock_read_loop, mock_threading, mock_connect, mock_authenticate):
        self.betfair_stream._running = True
        self.betfair_stream.start()
        mock_read_loop.assert_called_with()

        self.betfair_stream.start(async=True)
        mock_threading.Thread.assert_called_with(daemon=False, name=self.description, target=mock_read_loop)

        self.betfair_stream._running = False
        self.betfair_stream.start(async=False)<commit_msg>Fix test - Thread not called with daemon kwarg<commit_after>import unittest
import socket
import time
import threading
from tests import mock

from betfairlightweight.streaming.betfairstream import BetfairStream
from betfairlightweight.exceptions import SocketError


class BetfairStreamTest(unittest.TestCase):

    def setUp(self):
        self.mock_listener = mock.Mock()
        self.mock_listener.on_data.return_value = False
        self.unique_id = 1
        self.app_key = 'app_key'
        self.session_token = '<PASSWORD>'
        self.timeout = 6
        self.buffer_size = 1024
        self.description = 'test_stream'
        self.betfair_stream = BetfairStream(self.unique_id, self.mock_listener, self.app_key, self.session_token,
                                            self.timeout, self.buffer_size, self.description)

    def test_init(self):
        assert self.betfair_stream.unique_id == self.unique_id
        assert self.betfair_stream.listener == self.mock_listener
        assert self.betfair_stream.app_key == self.app_key
        assert self.betfair_stream.session_token == self.session_token
        assert self.betfair_stream.timeout == self.timeout
        assert self.betfair_stream.buffer_size == self.buffer_size
        assert self.betfair_stream.description == self.description
        assert self.betfair_stream.receive_count == 0
        assert self.betfair_stream.datetime_last_received is None

        assert self.betfair_stream._socket is None
        assert self.betfair_stream._running is False

    @mock.patch('betfairlightweight.streaming.betfairstream.BetfairStream.authenticate')
    @mock.patch('betfairlightweight.streaming.betfairstream.BetfairStream._connect')
    @mock.patch('betfairlightweight.streaming.betfairstream.threading')
    @mock.patch('betfairlightweight.streaming.betfairstream.BetfairStream._read_loop')
    def test_start(self, mock_read_loop, mock_threading, mock_connect, mock_authenticate):
        self.betfair_stream._running = True
        self.betfair_stream.start()
        mock_read_loop.assert_called_with()

        self.betfair_stream.start(async=True)
        mock_threading.Thread.assert_called_with(name=self.description, target=mock_read_loop)

        self.betfair_stream._running = False
        self.betfair_stream.start(async=False)
{'fraction_non_alphanumeric': 0.08011228676311812, 'fraction_numerical': 0.0030231051608723817, 'mean_word_length': 3.527859237536657, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7529261', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1318, 'n_words': 219}