Add tests, increment version to 1.0.0

This commit is contained in:
Marcel Schwarz 2024-01-25 16:06:50 +01:00
parent 0d66d6c674
commit 795409e5b7
3 changed files with 35 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
dist/ dist/
*.egg-info/ *.egg-info/
*.pyc

View File

@ -1,6 +1,6 @@
[project] [project]
name = "icaotix_python_logging" name = "icaotix_python_logging"
version = "0.0.1" version = "1.0.0"
authors = [ authors = [
{ name = "Marcel Schwarz", email = "admin@icaotix.de" }, { name = "Marcel Schwarz", email = "admin@icaotix.de" },
] ]

View File

@ -0,0 +1,32 @@
import io
import json
import logging
import logging.handlers
import unittest
from unittest.mock import patch
from src.icaotix_python_logging import logger
class TestStringMethods(unittest.TestCase):
def test_creation(self):
log = logger.get_stdout_logger("test_basic_logger")
self.assertIsInstance(log, logging.Logger)
self.assertEqual(1, len(log.handlers))
self.assertIsInstance(log.handlers[0], logging.handlers.QueueHandler)
@patch('sys.stdout', new_callable=io.StringIO)
def test_single_log_message(self, stdout: io.StringIO):
log = logger.get_stdout_logger("test_basic_logger")
log.info("Hello world")
# wait for all writes to be done (type is checked in test above)
log.handlers[0].listener.queue.join()
actual_json = json.loads(stdout.getvalue())
self.assertEqual(actual_json, actual_json | {"logger": "test_basic_logger", "message": "Hello world"})
if __name__ == '__main__':
unittest.main()