Skip to content

Commit 1c1c9ea

Browse files
committed
test the last remaining uncovered section of the code 🎉
Signed-off-by: Grant Ramsay <seapagan@gmail.com>
1 parent 1dd78b2 commit 1c1c9ea

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

tests/test_debug_logging.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ def test_sqliterdb_debug_default(self) -> None:
1717
def test_sqliterdb_debug_set_false(self) -> None:
1818
"""Test that the default value for the debug flag is False."""
1919
db = SqliterDB(":memory:", debug=False) # Set debug argument to False
20-
assert db.debug is False, (
21-
"The debug flag should be False when explicitly passed as False."
22-
)
20+
assert (
21+
db.debug is False
22+
), "The debug flag should be False when explicitly passed as False."
2323

2424
def test_sqliterdb_debug_set_true(self) -> None:
2525
"""Test that the debug flag can be set to True."""
2626
db = SqliterDB(":memory:", debug=True) # Set debug argument to True
27-
assert db.debug is True, (
28-
"The debug flag should be True when explicitly passed as True."
29-
)
27+
assert (
28+
db.debug is True
29+
), "The debug flag should be True when explicitly passed as True."
3030

3131
def test_debug_sql_output_basic_query(
3232
self, db_mock_complex_debug: SqliterDB, caplog
@@ -271,3 +271,33 @@ def test_reset_database_debug_logging(self, temp_db_path, caplog) -> None:
271271
SqliterDB(temp_db_path, reset=True, debug=True)
272272

273273
assert "Database reset: 0 user-created tables dropped." in caplog.text
274+
275+
def test_setup_logger_else_clause(self, mocker) -> None:
276+
"""Test the else clause configuration for the logger setup."""
277+
# Mock the root logger's hasHandlers BEFORE creating the instance
278+
mocker.patch.object(
279+
logging.getLogger(), "hasHandlers", return_value=False
280+
)
281+
282+
# Now create the instance which will trigger _setup_logger
283+
instance = SqliterDB(":memory:", debug=True)
284+
285+
# Verify the else clause configuration
286+
logger = instance.logger
287+
assert logger is not None
288+
289+
assert logger.name == "sqliter"
290+
assert len(logger.handlers) == 1
291+
292+
handler = logger.handlers[0]
293+
assert isinstance(handler, logging.StreamHandler)
294+
assert handler.formatter is not None
295+
assert handler.formatter._fmt == "%(levelname)-8s%(message)s"
296+
assert logger.level == logging.DEBUG
297+
assert logger.propagate is False
298+
299+
# Cleanup - crucial to prevent test pollution
300+
for hdlr in logger.handlers[:]:
301+
logger.removeHandler(hdlr)
302+
logger.setLevel(logging.NOTSET)
303+
logger.propagate = True

0 commit comments

Comments
 (0)