diff --git a/.gitignore b/.gitignore index 7444713..ea9227e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ dist/ -*.egg-info/ \ No newline at end of file +*.egg-info/ +*.pyc \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index b653c12..2735b61 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "icaotix_python_logging" -version = "0.0.1" +version = "1.0.0" authors = [ { name = "Marcel Schwarz", email = "admin@icaotix.de" }, ] diff --git a/tests/test_basic_logger.py b/tests/test_basic_logger.py new file mode 100644 index 0000000..55deedd --- /dev/null +++ b/tests/test_basic_logger.py @@ -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()