From cfed7c511404d3a689c446896d66ddeb434ecc41 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 29 Feb 2024 16:15:54 +0900 Subject: [PATCH] hatch fmt (#204) Signed-off-by: Inada Naoki --- fluent/asynchandler.py | 3 +-- fluent/asyncsender.py | 2 +- fluent/handler.py | 2 +- tests/test_asyncsender.py | 7 +++---- tests/test_event.py | 2 +- tests/test_sender.py | 13 ++++++------- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/fluent/asynchandler.py b/fluent/asynchandler.py index e150383..397608e 100644 --- a/fluent/asynchandler.py +++ b/fluent/asynchandler.py @@ -1,5 +1,4 @@ -from fluent import asyncsender -from fluent import handler +from fluent import asyncsender, handler class FluentHandler(handler.FluentHandler): diff --git a/fluent/asyncsender.py b/fluent/asyncsender.py index 73a1e61..b391290 100644 --- a/fluent/asyncsender.py +++ b/fluent/asyncsender.py @@ -1,5 +1,5 @@ import threading -from queue import Queue, Full, Empty +from queue import Empty, Full, Queue from fluent import sender from fluent.sender import EventTime diff --git a/fluent/handler.py b/fluent/handler.py index 2bc42b4..1018d69 100644 --- a/fluent/handler.py +++ b/fluent/handler.py @@ -76,7 +76,7 @@ def __init__( self._formatter = self._format_by_dict self.usesTime = self._format_by_dict_uses_time else: - if hasattr(fmt, "__call__"): + if callable(fmt): self._formatter = fmt self.usesTime = fmt.usesTime else: diff --git a/tests/test_asyncsender.py b/tests/test_asyncsender.py index d690ae1..a16c43f 100644 --- a/tests/test_asyncsender.py +++ b/tests/test_asyncsender.py @@ -1,4 +1,3 @@ -import socket import unittest import msgpack @@ -122,13 +121,13 @@ def test_no_last_error_on_successful_emit(self): def test_last_error_property(self): EXCEPTION_MSG = "custom exception for testing last_error property" - self._sender.last_error = socket.error(EXCEPTION_MSG) + self._sender.last_error = OSError(EXCEPTION_MSG) self.assertEqual(self._sender.last_error.args[0], EXCEPTION_MSG) def test_clear_last_error(self): EXCEPTION_MSG = "custom exception for testing clear_last_error" - self._sender.last_error = socket.error(EXCEPTION_MSG) + self._sender.last_error = OSError(EXCEPTION_MSG) self._sender.clear_last_error() self.assertEqual(self._sender.last_error, None) @@ -141,7 +140,7 @@ def test_connect_exception_during_sender_init(self, mock_socket): # Make the socket.socket().connect() call raise a custom exception mock_connect = mock_socket.socket.return_value.connect EXCEPTION_MSG = "a sender init socket connect() exception" - mock_connect.side_effect = socket.error(EXCEPTION_MSG) + mock_connect.side_effect = OSError(EXCEPTION_MSG) self.assertEqual(self._sender.last_error.args[0], EXCEPTION_MSG) diff --git a/tests/test_event.py b/tests/test_event.py index 6e2f0a0..1e597d8 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -28,7 +28,7 @@ def test_logging_with_timestamp(self): # XXX: This tests succeeds even if the fluentd connection failed # send event with tag app.follow, with timestamp - event.Event("follow", {"from": "userA", "to": "userB"}, time=int(0)) + event.Event("follow", {"from": "userA", "to": "userB"}, time=0) def test_no_last_error_on_successful_event(self): global_sender = sender.get_global_sender() diff --git a/tests/test_sender.py b/tests/test_sender.py index d915e98..69d09ed 100644 --- a/tests/test_sender.py +++ b/tests/test_sender.py @@ -1,5 +1,4 @@ import errno -import socket import sys import unittest from shutil import rmtree @@ -121,13 +120,13 @@ def test_no_last_error_on_successful_emit(self): def test_last_error_property(self): EXCEPTION_MSG = "custom exception for testing last_error property" - self._sender.last_error = socket.error(EXCEPTION_MSG) + self._sender.last_error = OSError(EXCEPTION_MSG) self.assertEqual(self._sender.last_error.args[0], EXCEPTION_MSG) def test_clear_last_error(self): EXCEPTION_MSG = "custom exception for testing clear_last_error" - self._sender.last_error = socket.error(EXCEPTION_MSG) + self._sender.last_error = OSError(EXCEPTION_MSG) self._sender.clear_last_error() self.assertEqual(self._sender.last_error, None) @@ -225,12 +224,12 @@ def __init__(self): self.send_side_effects = [3, 0, 9] self.send_idx = 0 self.recv_side_effects = [ - socket.error(errno.EWOULDBLOCK, "Blah"), + OSError(errno.EWOULDBLOCK, "Blah"), b"this data is going to be ignored", b"", - socket.error(errno.EWOULDBLOCK, "Blah"), - socket.error(errno.EWOULDBLOCK, "Blah"), - socket.error(errno.EACCES, "This error will never happen"), + OSError(errno.EWOULDBLOCK, "Blah"), + OSError(errno.EWOULDBLOCK, "Blah"), + OSError(errno.EACCES, "This error will never happen"), ] self.recv_idx = 0