8000 Fix tests. · fluent/fluent-logger-python@8e70e6a · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e70e6a

Browse files
author
Paweł Guz
committed
Fix tests.
Signed-off-by: Paweł Guz <pawel.guz@socialwifi.com>
1 parent 258b445 commit 8e70e6a

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

tests/test_asynchandler.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44
import sys
55
import unittest
66

7-
from mock import patch
8-
from unittest import mock
7+
try:
8+
from unittest import mock
9+
except ImportError:
10+
import mock
11+
try:
12+
from unittest.mock import patch
13+
except ImportError:
14+
from mock import patch
15+
16+
917

1018
import fluent.asynchandler
1119
import fluent.handler
@@ -322,8 +330,6 @@ def queue_overflow_handler(discarded_bytes):
322330
raise QueueOverflowException(discarded_bytes)
323331

324332

325-
326-
327333
class TestHandlerWithCircularQueueHandler(unittest.TestCase):
328334
Q_SIZE = 1
329335

@@ -339,25 +345,30 @@ def get_handler_class(self):
339345
# return fluent.handler.FluentHandler
340346
return fluent.asynchandler.FluentHandler
341347

342-
@patch.object(fluent.asynchandler.asyncsender.Queue, 'full', mock.Mock(return_value=True))
343348
def test_simple(self):
344349
handler = self.get_handler_class()('app.follow', port=self._port,
345350
queue_maxsize=self.Q_SIZE,
346351
queue_circular=True,
347352
queue_overflow_handler=queue_overflow_handler)
348353
with handler:
349-
self.assertEqual(handler.sender.queue_circular, True)
350-
self.assertEqual(handler.sender.queue_maxsize, self.Q_SIZE)
354+
def custom_full_queue():
355+
handler.sender._queue.put(b'Mock', block=True)
356+
return True
351357

352-
logging.basicConfig(level=logging.INFO)
353-
log = logging.getLogger('fluent.test')
354-
handler.setFormatter(fluent.handler.FluentRecordFormatter())
355-
log.addHandler(handler)
358+
with patch.object(fluent.asynchandler.asyncsender.Queue, 'full', mock.Mock(side_effect=custom_full_queue)):
359+
self.assertEqual(handler.sender.queue_circular, True)
360+
self.assertEqual(handler.sender.queue_maxsize, self.Q_SIZE)
356361

357-
log.info({'cnt': 1, 'from': 'userA', 'to': 'userB'})
358-
with self.assertRaises(QueueOverflowException):
359-
log.info({'cnt': 2, 'from': 'userA', 'to': 'userB'})
360-
log.info({'cnt': 3, 'from': 'userA', 'to': 'userB'})
361-
with self.assertRaises(QueueOverflowException):
362-
log.info({'cnt': 4, 'from': 'userA', 'to': 'userB'})
362+
logging.basicConfig(level=logging.INFO)
363+
log = logging.getLogger('fluent.test')
364+
handler.setFormatter(fluent.handler.FluentRecordFormatter())
365+
log.addHandler(handler)
366+
367+
with self.assertRaises(QueueOverflowException):
368+
log.info({'cnt': 1, 'from': 'userA', 'to': 'userB'})
369+
370+
with self.assertRaises(QueueOverflowException):
371+
log.info({'cnt': 2, 'from': 'userA', 'to': 'userB'})
363372

373+
with self.assertRaises(QueueOverflowException):
374+
log.info({'cnt': 3, 'from': 'userA', 'to': 'userB'})

0 commit comments

Comments
 (0)
0