krkn_lib.tests.test_safe_logger module

Comprehensive unit tests for SafeLogger class.

This test suite covers both file-based logging mode (with worker thread) and standard logging mode (fallback).

Assisted By: Claude Code

class krkn_lib.tests.test_safe_logger.TestSafeLoggerAfterClose(methodName='runTest')

Bases: TestCase

Test behavior after close() is called.

setUp()

Hook method for setting up the test fixture before exercising it.

tearDown()

Hook method for deconstructing the test fixture after testing it.

test_error_uses_logging_after_close(mock_error)

Test error() uses logging after close().

test_info_uses_logging_after_close(mock_info)

Test info() uses logging after close().

test_warning_uses_logging_after_close(mock_warning)

Test warning() uses logging after close().

class krkn_lib.tests.test_safe_logger.TestSafeLoggerEdgeCases(methodName='runTest')

Bases: TestCase

Test edge cases and error conditions.

setUp()

Hook method for setting up the test fixture before exercising it.

tearDown()

Hook method for deconstructing the test fixture after testing it.

test_empty_message()

Test logging empty string.

test_log_file_name_none_when_no_file(mock_info)

Test log_file_name is None when using standard logging.

test_multiline_message()

Test logging multiline message.

test_rapid_logging()

Test rapid successive logging.

test_special_characters()

Test logging messages with special characters.

test_very_long_message()

Test logging very long message.

class krkn_lib.tests.test_safe_logger.TestSafeLoggerFileLogging(methodName='runTest')

Bases: TestCase

Test file-based logging functionality.

setUp()

Hook method for setting up the test fixture before exercising it.

tearDown()

Hook method for deconstructing the test fixture after testing it.

test_append_mode()

Test append mode preserves existing content.

test_close_waits_for_queue()

Test close() waits for all messages to be processed.

test_error_logs_to_file()

Test error() writes to file with [ERR] prefix.

test_info_logs_to_file()

Test info() writes to file with [INF] prefix.

test_log_file_name_property()

Test log_file_name property returns filename.

test_multiple_logs_to_file()

Test multiple log messages are written in order.

test_timestamp_in_logs()

Test log messages include timestamp.

test_warning_logs_to_file()

Test warning() writes to file with [WRN] prefix.

class krkn_lib.tests.test_safe_logger.TestSafeLoggerInit(methodName='runTest')

Bases: TestCase

Test SafeLogger initialization.

test_init_default_write_mode()

Test default write mode is w+.

test_init_with_filename()

Test initialization with filename creates file writer and thread.

test_init_with_filename_and_write_mode()

Test initialization with custom write mode.

test_init_without_filename()

Test initialization without filename uses standard logging.

class krkn_lib.tests.test_safe_logger.TestSafeLoggerStandardLogging(methodName='runTest')

Bases: TestCase

Test standard logging fallback (no file).

test_error_uses_logging_when_no_file(mock_error)

Test error() uses logging.error when no file specified.

test_info_uses_logging_when_no_file(mock_info)

Test info() uses logging.info when no file specified.

test_multiple_logs_use_logging(mock_info, mock_warning, mock_error)

Test multiple calls use standard logging.

test_warning_uses_logging_when_no_file(mock_warning)

Test warning() uses logging.warning when no file specified.

class krkn_lib.tests.test_safe_logger.TestSafeLoggerWorkerThread(methodName='runTest')

Bases: TestCase

Test worker thread functionality.

setUp()

Hook method for setting up the test fixture before exercising it.

tearDown()

Hook method for deconstructing the test fixture after testing it.

test_worker_stops_when_finished()

Test worker thread stops when finished flag is set.

test_worker_thread_is_daemon()

Test worker thread is created as daemon.

test_worker_thread_processes_queue()

Test worker thread processes messages from queue.