Add tests, increment version to 1.0.0
This commit is contained in:
parent
0d66d6c674
commit
795409e5b7
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
*.egg-info/
|
*.egg-info/
|
||||||
|
*.pyc
|
@ -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" },
|
||||||
]
|
]
|
||||||
|
32
tests/test_basic_logger.py
Normal file
32
tests/test_basic_logger.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user