From c3df84b7d317b0f9839b75fbaa9526957f10927e Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 27 Feb 2024 19:18:22 +0900 Subject: [PATCH 1/8] Use GitHub Actions to run test Signed-off-by: Inada Naoki --- .github/workflows/test.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..3e5c0c6 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,24 @@ +name: Run test + +on: + push: + branches: + - main + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "pypy3.9", "pypy3.10"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + - name: Install dependencies + run: python -m pip install --upgrade tox + - name: Run tests + run: tox -e py From 5db19d6e1940e819bc42f87b2f9ab271058ba7d5 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 27 Feb 2024 21:12:55 +0900 Subject: [PATCH 2/8] fix tests on pytest Signed-off-by: Inada Naoki --- tests/mockserver.py | 3 --- tests/test_asynchandler.py | 17 ++--------------- tests/test_event.py | 3 ++- tests/test_handler.py | 20 ++------------------ tox.ini | 7 ++++--- 5 files changed, 10 insertions(+), 40 deletions(-) diff --git a/tests/mockserver.py b/tests/mockserver.py index 77ecdd3..f1462a1 100644 --- a/tests/mockserver.py +++ b/tests/mockserver.py @@ -92,6 +92,3 @@ def close(self): pass self.join() - - def __del__(self): - self.close() diff --git a/tests/test_asynchandler.py b/tests/test_asynchandler.py index e88a041..859f36d 100644 --- a/tests/test_asynchandler.py +++ b/tests/test_asynchandler.py @@ -25,9 +25,11 @@ def setUp(self): super(TestHandler, self).setUp() self._server = mockserver.MockRecvServer('localhost') self._port = self._server.port + logging.getLogger().setLevel(logging.INFO) def tearDown(self): self._server.close() + self._server = None def get_handler_class(self): # return fluent.handler.FluentHandler @@ -40,7 +42,6 @@ def test_simple(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -63,7 +64,6 @@ def test_custom_fmt(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ @@ -86,7 +86,6 @@ def test_custom_fmt_with_format_style(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ @@ -109,7 +108,6 @@ def test_custom_fmt_with_template_style(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ @@ -131,7 +129,6 @@ def test_custom_field_raise_exception(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ @@ -147,7 +144,6 @@ 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: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ @@ -172,7 +168,6 @@ def test_json_encoded_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -186,7 +181,6 @@ def test_unstructured_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -200,7 +194,6 @@ def test_unstructured_formatted_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -214,7 +207,6 @@ def test_number_string_simple_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -227,7 +219,6 @@ def test_non_string_simple_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -240,7 +231,6 @@ def test_non_string_dict_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -254,7 +244,6 @@ def test_exception_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -297,7 +286,6 @@ def test_simple(self): self.assertEqual(handler.sender.queue_circular, True) self.assertEqual(handler.sender.queue_maxsize, self.Q_SIZE) - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -359,7 +347,6 @@ def custom_full_queue(): self.assertEqual(handler.sender.queue_circular, True) self.assertEqual(handler.sender.queue_maxsize, self.Q_SIZE) - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) diff --git a/tests/test_event.py b/tests/test_event.py index d341616..21e93e4 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -6,7 +6,8 @@ from tests import mockserver -class TestException(BaseException): pass +class TestException(BaseException): + __test__ = False class TestEvent(unittest.TestCase): diff --git a/tests/test_handler.py b/tests/test_handler.py index 45fea86..a7cdd51 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -13,9 +13,11 @@ def setUp(self): super(TestHandler, self).setUp() self._server = mockserver.MockRecvServer('localhost') self._port = self._server.port + logging.getLogger().setLevel(logging.INFO) def tearDown(self): self._server.close() + self._server = None def get_data(self): return self._server.get_received() @@ -24,7 +26,6 @@ def test_simple(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -50,7 +51,6 @@ def test_custom_fmt(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ @@ -73,7 +73,6 @@ def test_exclude_attrs(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(exclude_attrs=[]) @@ -91,7 +90,6 @@ def test_exclude_attrs_with_exclusion(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(exclude_attrs=["funcName"]) @@ -109,7 +107,6 @@ def test_exclude_attrs_with_extra(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(exclude_attrs=[]) @@ -138,7 +135,6 @@ def formatter(record): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt=formatter) @@ -157,7 +153,6 @@ def test_custom_fmt_with_format_style(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ @@ -181,7 +176,6 @@ def test_custom_fmt_with_template_style(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ @@ -204,7 +198,6 @@ def test_custom_field_raise_exception(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ @@ -223,7 +216,6 @@ def test_custom_field_fill_missing_fmt_key_is_true(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ @@ -248,7 +240,6 @@ def test_json_encoded_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -265,7 +256,6 @@ def test_json_encoded_message_without_json(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter(format_json=False)) log.addHandler(handler) @@ -282,7 +272,6 @@ def test_unstructured_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -297,7 +286,6 @@ def test_unstructured_formatted_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -312,7 +300,6 @@ def test_number_string_simple_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -326,7 +313,6 @@ def test_non_string_simple_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -340,7 +326,6 @@ def test_non_string_dict_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -355,7 +340,6 @@ def test_exception_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - logging.basicConfig(level=logging.INFO) log = logging.getLogger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) diff --git a/tox.ini b/tox.ini index 6c3f032..a0e2c95 100644 --- a/tox.ini +++ b/tox.ini @@ -4,6 +4,7 @@ envlist = py27, py32, py33, py34, py35, py36, py37, py38 skip_missing_interpreters = True [testenv] -deps = nose - coverage~=4.5.4 -commands = python setup.py nosetests +deps = + pytest + msgpack +commands = pytest -v From 84294d7b0ad5ef9a73a97337d9188c58ec7fa9fb Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 27 Feb 2024 21:14:47 +0900 Subject: [PATCH 3/8] add python 3.12 Signed-off-by: Inada Naoki --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e5c0c6..57b4122 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "pypy3.9", "pypy3.10"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"] steps: - uses: actions/checkout@v4 - name: Set up Python From 5f02060bc0bddcfbcf18c6ee83dd33045db85587 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 28 Feb 2024 13:40:27 +0900 Subject: [PATCH 4/8] add comment Signed-off-by: Inada Naoki --- tests/test_event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_event.py b/tests/test_event.py index 21e93e4..9f2010f 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -7,7 +7,7 @@ class TestException(BaseException): - __test__ = False + __test__ = False # teach pytest this is not test class. class TestEvent(unittest.TestCase): From e1e17ab36d2d3e1143b5f6d5b9d5da607720c593 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 28 Feb 2024 13:45:46 +0900 Subject: [PATCH 5/8] use helper method Signed-off-by: Inada Naoki --- tests/test_asynchandler.py | 37 +++++++++++++++++--------------- tests/test_event.py | 2 +- tests/test_handler.py | 43 ++++++++++++++++++++------------------ 3 files changed, 44 insertions(+), 38 deletions(-) diff --git a/tests/test_asynchandler.py b/tests/test_asynchandler.py index 859f36d..8cd2681 100644 --- a/tests/test_asynchandler.py +++ b/tests/test_asynchandler.py @@ -25,11 +25,9 @@ def setUp(self): super(TestHandler, self).setUp() self._server = mockserver.MockRecvServer('localhost') self._port = self._server.port - logging.getLogger().setLevel(logging.INFO) def tearDown(self): self._server.close() - self._server = None def get_handler_class(self): # return fluent.handler.FluentHandler @@ -38,11 +36,16 @@ 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 = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) log.info({ @@ -64,7 +67,7 @@ def test_custom_fmt(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ 'name': '%(name)s', @@ -86,7 +89,7 @@ def test_custom_fmt_with_format_style(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ 'name': '{name}', @@ -108,7 +111,7 @@ def test_custom_fmt_with_template_style(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ 'name': '${name}', @@ -129,7 +132,7 @@ def test_custom_field_raise_exception(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ 'name': '%(name)s', @@ -144,7 +147,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 = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ 'name': '%(name)s', @@ -168,7 +171,7 @@ def test_json_encoded_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) log.info('{"key": "hello world!", "param": "value"}') @@ -181,7 +184,7 @@ def test_unstructured_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) log.info('hello %s', 'world') @@ -194,7 +197,7 @@ def test_unstructured_formatted_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) log.info('hello world, %s', 'you!') @@ -207,7 +210,7 @@ def test_number_string_simple_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) log.info("1") @@ -219,7 +222,7 @@ def test_non_string_simple_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) log.info(42) @@ -231,7 +234,7 @@ def test_non_string_dict_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) log.info({42: 'root'}) @@ -244,7 +247,7 @@ def test_exception_message(self): handler = self.get_handler_class()('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) try: @@ -286,7 +289,7 @@ def test_simple(self): self.assertEqual(handler.sender.queue_circular, True) self.assertEqual(handler.sender.queue_maxsize, self.Q_SIZE) - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) log.info({'cnt': 1, 'from': 'userA', 'to': 'userB'}) @@ -347,7 +350,7 @@ def custom_full_queue(): self.assertEqual(handler.sender.queue_circular, True) self.assertEqual(handler.sender.queue_maxsize, self.Q_SIZE) - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) diff --git a/tests/test_event.py b/tests/test_event.py index 9f2010f..0f47ffa 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -19,7 +19,7 @@ def tearDown(self): from fluent.sender import _set_global_sender sender.close() _set_global_sender(None) - + def test_logging(self): # XXX: This tests succeeds even if the fluentd connection failed # send event with tag app.follow diff --git a/tests/test_handler.py b/tests/test_handler.py index a7cdd51..7c40c07 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -13,20 +13,23 @@ def setUp(self): super(TestHandler, self).setUp() self._server = mockserver.MockRecvServer('localhost') self._port = self._server.port - logging.getLogger().setLevel(logging.INFO) def tearDown(self): self._server.close() - self._server = None 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 = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -51,7 +54,7 @@ def test_custom_fmt(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ 'name': '%(name)s', @@ -73,7 +76,7 @@ def test_exclude_attrs(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(exclude_attrs=[]) ) @@ -90,7 +93,7 @@ def test_exclude_attrs_with_exclusion(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(exclude_attrs=["funcName"]) ) @@ -107,7 +110,7 @@ def test_exclude_attrs_with_extra(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(exclude_attrs=[]) ) @@ -135,7 +138,7 @@ def formatter(record): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt=formatter) ) @@ -153,7 +156,7 @@ def test_custom_fmt_with_format_style(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ 'name': '{name}', @@ -176,7 +179,7 @@ def test_custom_fmt_with_template_style(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ 'name': '${name}', @@ -198,7 +201,7 @@ def test_custom_field_raise_exception(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ 'name': '%(name)s', @@ -216,7 +219,7 @@ def test_custom_field_fill_missing_fmt_key_is_true(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter( fluent.handler.FluentRecordFormatter(fmt={ 'name': '%(name)s', @@ -240,7 +243,7 @@ def test_json_encoded_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) @@ -256,7 +259,7 @@ def test_json_encoded_message_without_json(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter(format_json=False)) log.addHandler(handler) @@ -272,7 +275,7 @@ def test_unstructured_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) log.info('hello %s', 'world') @@ -286,7 +289,7 @@ def test_unstructured_formatted_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) log.info('hello world, %s', 'you!') @@ -300,7 +303,7 @@ def test_number_string_simple_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) log.info("1") @@ -313,7 +316,7 @@ def test_non_string_simple_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) log.info(42) @@ -326,7 +329,7 @@ def test_non_string_dict_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) log.info({42: 'root'}) @@ -340,7 +343,7 @@ def test_exception_message(self): handler = fluent.handler.FluentHandler('app.follow', port=self._port) with handler: - log = logging.getLogger('fluent.test') + log = self.get_logger('fluent.test') handler.setFormatter(fluent.handler.FluentRecordFormatter()) log.addHandler(handler) try: From 9e2b1eb6a0adf66f1e566d3ac170170a91f746c0 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 28 Feb 2024 14:14:53 +0900 Subject: [PATCH 6/8] fixup Signed-off-by: Inada Naoki --- tests/test_asynchandler.py | 41 +++++++++++++++++---------------- tests/test_handler.py | 47 +++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/tests/test_asynchandler.py b/tests/test_asynchandler.py index 8cd2681..bbbf52e 100644 --- a/tests/test_asynchandler.py +++ b/tests/test_asynchandler.py @@ -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() @@ -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({ @@ -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', @@ -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}', @@ -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}', @@ -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', @@ -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', @@ -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"}') @@ -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') @@ -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!') @@ -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") @@ -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) @@ -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'}) @@ -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: @@ -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'}) @@ -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) diff --git a/tests/test_handler.py b/tests/test_handler.py index 7c40c07..2ef0695 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -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() @@ -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) @@ -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', @@ -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=[]) ) @@ -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"]) ) @@ -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=[]) ) @@ -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) ) @@ -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}', @@ -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}', @@ -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', @@ -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', @@ -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) @@ -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) @@ -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') @@ -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!') @@ -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") @@ -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) @@ -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'}) @@ -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: From fc1685a414343ac64a6db062a920934e5000c07b Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 28 Feb 2024 18:48:26 +0900 Subject: [PATCH 7/8] fix workflow Signed-off-by: Inada Naoki --- .github/workflows/test.yml | 10 ++++++---- requirements-dev.txt | 3 +++ tox.ini | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 requirements-dev.txt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 57b4122..ba4c1e0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,10 +15,12 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python }} + python-version: ${{ matrix.python-version }} + cache: "pip" + cache-dependency-path: requirements-dev.txt - name: Install dependencies - run: python -m pip install --upgrade tox + run: python -m pip install -r requirements-dev.txt - name: Run tests - run: tox -e py + run: pytest --cov=fluent diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..3707664 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,3 @@ +pytest +pytest-cov +msgpack diff --git a/tox.ini b/tox.ini index a0e2c95..14634e9 100644 --- a/tox.ini +++ b/tox.ini @@ -6,5 +6,6 @@ skip_missing_interpreters = True [testenv] deps = pytest + pytest-cov msgpack -commands = pytest -v +commands = pytest --cov=fluent From 8ed84698eddc133e845c32e1b4308dac898b551d Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 28 Feb 2024 18:51:27 +0900 Subject: [PATCH 8/8] remove .travis.yml Signed-off-by: Inada Naoki --- .travis.yml | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0e5e0c8..0000000 --- a/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -sudo: false -language: python -python: - - "3.5" - - "3.6" - - "3.7" - - "3.8" - - "3.9" - - pypy3 - - nightly -# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors -install: - - "pip install -e ." - - "pip install 'coverage~=4.5.4' coveralls" -script: - - "PYTHONFAULTHANDLER=x timeout -sABRT 30s nosetests -vsd" -after_success: - - coveralls - -deploy: - provider: pypi - user: repeatedly - server: https://upload.pypi.org/legacy/ - password: - secure: CpNaj4F3TZvpP1aSJWidh/XexrWODV2sBdObrYU79Gyh9hFl6WLsA3JM9BfVsy9cGb/P/jP6ly4Z0/6qdIzZ5D6FPOB1B7rn5GZ2LAMOypRCA6W2uJbRjUU373Wut0p0OmQcMPto6XJsMlpvOEq+1uAq+LLAnAGEmmYTeskZebs= - on: - tags: true - condition: '"$TRAVIS_PYTHON_VERSION" = "3.9" || "$TRAVIS_PYTHON_VERSION" = "2.7"' - distributions: "sdist bdist_wheel" - -matrix: - allow_failures: - - python: nightly