Skip to content

Commit

Permalink
log message format test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
korowa committed May 13, 2024
1 parent 3666f5d commit 3f539cd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/test_blocks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import types
from unittest.mock import patch

Expand Down Expand Up @@ -245,3 +246,20 @@ def test_logs_with_compression(self):
query = 'SELECT 1'
client.execute(query, settings=settings)
self.assertIn(query, buffer.getvalue())

def test_logs_message_format(self):
log_regex_source = (
r'^\[ .+? \] ' # hostname
r'[\d-]{10} [\d:]{8}\.\d{6} ' # timestamp
r'\[ \d+? \] ' # thread_id
r'\{[\w-]{36}\} ' # query_id
r'<[a-z]+?> ' # priority
r'\w+?:' # source
)
log_regex = re.compile(log_regex_source, re.I)

with capture_logging('clickhouse_driver.log', 'INFO') as buffer:
settings = {'send_logs_level': 'debug'}
query = 'SELECT 1'
self.client.execute(query, settings=settings)
self.assertRegex(buffer.getvalue(), log_regex)

0 comments on commit 3f539cd

Please sign in to comment.