Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Feb 28, 2024
1 parent c4d3326 commit a352e16
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 43 deletions.
41 changes: 21 additions & 20 deletions tests/test_asynchandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
from tests import mockserver


def get_logger(name, level=logging.INFO):
logger = logging.getLogger(name)
logger.setLevel(level)
return logger


class TestHandler(unittest.TestCase):
def setUp(self):
super(TestHandler, self).setUp()
Expand All @@ -36,16 +42,11 @@ def get_handler_class(self):
def get_data(self):
return self._server.get_received()

def get_logger(self, name, level=logging.INFO):
logger = logging.getLogger(name)
logger.setLevel(level)
return logger

def test_simple(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info({
Expand All @@ -67,7 +68,7 @@ def test_custom_fmt(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '%(name)s',
Expand All @@ -89,7 +90,7 @@ def test_custom_fmt_with_format_style(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '{name}',
Expand All @@ -111,7 +112,7 @@ def test_custom_fmt_with_template_style(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '${name}',
Expand All @@ -132,7 +133,7 @@ def test_custom_field_raise_exception(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '%(name)s',
Expand All @@ -147,7 +148,7 @@ def test_custom_field_raise_exception(self):
def test_custom_field_fill_missing_fmt_key_is_true(self):
handler = self.get_handler_class()('app.follow', port=self._port)
with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '%(name)s',
Expand All @@ -171,7 +172,7 @@ def test_json_encoded_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info('{"key": "hello world!", "param": "value"}')
Expand All @@ -184,7 +185,7 @@ def test_unstructured_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info('hello %s', 'world')
Expand All @@ -197,7 +198,7 @@ def test_unstructured_formatted_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info('hello world, %s', 'you!')
Expand All @@ -210,7 +211,7 @@ def test_number_string_simple_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info("1")
Expand All @@ -222,7 +223,7 @@ def test_non_string_simple_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info(42)
Expand All @@ -234,7 +235,7 @@ def test_non_string_dict_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info({42: 'root'})
Expand All @@ -247,7 +248,7 @@ def test_exception_message(self):
handler = self.get_handler_class()('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
try:
Expand Down Expand Up @@ -289,7 +290,7 @@ def test_simple(self):
self.assertEqual(handler.sender.queue_circular, True)
self.assertEqual(handler.sender.queue_maxsize, self.Q_SIZE)

log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info({'cnt': 1, 'from': 'userA', 'to': 'userB'})
Expand Down Expand Up @@ -350,7 +351,7 @@ def custom_full_queue():
self.assertEqual(handler.sender.queue_circular, True)
self.assertEqual(handler.sender.queue_maxsize, self.Q_SIZE)

log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)

Expand Down
47 changes: 24 additions & 23 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
from tests import mockserver


def get_logger(name, level=logging.INFO):
logger = logging.getLogger(name)
logger.setLevel(level)
return logger


class TestHandler(unittest.TestCase):
def setUp(self):
super(TestHandler, self).setUp()
Expand All @@ -20,16 +26,11 @@ def tearDown(self):
def get_data(self):
return self._server.get_received()

def get_logger(self, name, level=logging.INFO):
logger = logging.getLogger(name)
logger.setLevel(level)
return logger

def test_simple(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)

Expand All @@ -54,7 +55,7 @@ def test_custom_fmt(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '%(name)s',
Expand All @@ -76,7 +77,7 @@ def test_exclude_attrs(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(exclude_attrs=[])
)
Expand All @@ -93,7 +94,7 @@ def test_exclude_attrs_with_exclusion(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(exclude_attrs=["funcName"])
)
Expand All @@ -110,7 +111,7 @@ def test_exclude_attrs_with_extra(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(exclude_attrs=[])
)
Expand Down Expand Up @@ -138,7 +139,7 @@ def formatter(record):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt=formatter)
)
Expand All @@ -156,7 +157,7 @@ def test_custom_fmt_with_format_style(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '{name}',
Expand All @@ -179,7 +180,7 @@ def test_custom_fmt_with_template_style(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '${name}',
Expand All @@ -201,7 +202,7 @@ def test_custom_field_raise_exception(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '%(name)s',
Expand All @@ -219,7 +220,7 @@ def test_custom_field_fill_missing_fmt_key_is_true(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(
fluent.handler.FluentRecordFormatter(fmt={
'name': '%(name)s',
Expand All @@ -243,7 +244,7 @@ def test_json_encoded_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)

Expand All @@ -259,7 +260,7 @@ def test_json_encoded_message_without_json(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter(format_json=False))
log.addHandler(handler)

Expand All @@ -275,7 +276,7 @@ def test_unstructured_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info('hello %s', 'world')
Expand All @@ -289,7 +290,7 @@ def test_unstructured_formatted_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info('hello world, %s', 'you!')
Expand All @@ -303,7 +304,7 @@ def test_number_string_simple_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info("1")
Expand All @@ -316,7 +317,7 @@ def test_non_string_simple_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info(42)
Expand All @@ -329,7 +330,7 @@ def test_non_string_dict_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
log.info({42: 'root'})
Expand All @@ -343,7 +344,7 @@ def test_exception_message(self):
handler = fluent.handler.FluentHandler('app.follow', port=self._port)

with handler:
log = self.get_logger('fluent.test')
log = get_logger('fluent.test')
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)
try:
Expand Down

0 comments on commit a352e16

Please sign in to comment.