Esempio n. 1
0
class HistoricalStreamTest(unittest.TestCase):

    def setUp(self):
        self.directory = 'test'
        self.listener = mock.Mock()
        self.stream = HistoricalStream(self.directory, self.listener)

    def test_init(self):
        assert self.stream.directory == self.directory
        assert self.stream.listener == self.listener
        assert self.stream._running is False

    @mock.patch('betfairlightweight.endpoints.streaming.HistoricalStream._read_loop')
    def test_start(self, mock_read_loop):
        self.stream.start()
        mock_read_loop.assert_called_with()
        assert self.stream._running is True

    @mock.patch('betfairlightweight.streaming.betfairstream.HistoricalStream._read_loop')
    @mock.patch('betfairlightweight.streaming.betfairstream.threading')
    def test_start_thread(self, mock_threading, mock_read_loop):
        self.stream.start(async=True)
        mock_threading.Thread.assert_called_with(name='HistoricalStream', target=mock_read_loop)
        assert self.stream._running is True

    def test_stop(self):
        self.stream._running = True
        self.stream.stop()
        assert self.stream._running is False
Esempio n. 2
0
class HistoricalStreamTest(unittest.TestCase):
    def setUp(self):
        self.directory = "tests/resources/historicaldata/BASIC-1.132153978"
        self.listener = mock.Mock()
        self.stream = HistoricalStream(self.directory, self.listener)

    def test_init(self):
        assert self.stream.directory == self.directory
        assert self.stream.listener == self.listener
        assert self.stream._running is False

    @mock.patch(
        "betfairlightweight.endpoints.streaming.HistoricalStream._read_loop")
    def test_start(self, mock_read_loop):
        self.stream.start()
        mock_read_loop.assert_called_with()
        assert self.stream._running is True

    def test_stop(self):
        self.stream._running = True
        self.stream.stop()
        assert self.stream._running is False

    @mock.patch(
        "betfairlightweight.streaming.betfairstream.HistoricalStream.stop")
    def test__read_loop(self, mock_stop):
        self.stream._running = True
        self.stream._read_loop()
        self.assertEqual(self.listener.on_data.call_count, 480)
        self.listener.on_data.snap()
        mock_stop.assert_called_with()
        self.assertTrue(self.stream._running)
Esempio n. 3
0
class HistoricalStreamTest(unittest.TestCase):
    def setUp(self):
        self.file_path = "tests/resources/historicaldata/BASIC-1.132153978"
        self.listener = mock.Mock()
        self.operation = "marketSubscription"
        self.stream = HistoricalStream(self.file_path, self.listener, self.operation)

    def test_init(self):
        assert self.stream.file_path == self.file_path
        assert self.stream.listener == self.listener
        assert self.stream._running is False
        assert self.stream.operation == self.operation

    @mock.patch("betfairlightweight.endpoints.streaming.HistoricalStream._read_loop")
    def test_start(self, mock_read_loop):
        self.stream.start()
        mock_read_loop.assert_called_with()
        assert self.stream._running is True

    def test_stop(self):
        self.stream._running = True
        self.stream.stop()
        assert self.stream._running is False

    @mock.patch("betfairlightweight.streaming.betfairstream.HistoricalStream.stop")
    def test__read_loop(self, mock_stop):
        self.stream._running = True
        self.stream._read_loop()
        self.assertEqual(self.listener.on_data.call_count, 480)
        self.listener.on_data.snap()
        mock_stop.assert_called_with()
        self.assertTrue(self.stream._running)
        self.listener.register_stream.assert_called_with(0, self.operation)
Esempio n. 4
0
 def setUp(self):
     self.directory = 'test'
     self.listener = mock.Mock()
     self.stream = HistoricalStream(self.directory, self.listener)
Esempio n. 5
0
 def setUp(self):
     self.directory = "tests/resources/historicaldata/BASIC-1.132153978"
     self.listener = mock.Mock()
     self.stream = HistoricalStream(self.directory, self.listener)
Esempio n. 6
0
 def setUp(self):
     self.file_path = "tests/resources/historicaldata/BASIC-1.132153978"
     self.listener = mock.Mock()
     self.operation = "marketSubscription"
     self.stream = HistoricalStream(self.file_path, self.listener, self.operation)