headless-safe filedialog tests with optional live dialog tests and ruff fixes
Tests / test_and_lint (push) Failing after 7s
Tests / test_and_lint (push) Failing after 7s
This commit is contained in:
+27
-10
@@ -16,7 +16,7 @@ SECONDS_PER_DAY = 24 * 60 * 60
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def restore_root_logger() -> Generator[None, None, None]:
|
||||
def restore_root_logger() -> Generator[None]:
|
||||
root = logging.getLogger()
|
||||
old_handlers = root.handlers[:]
|
||||
old_level = root.level
|
||||
@@ -45,7 +45,9 @@ def test_invalid_log_level_falls_back_to_info(restore_root_logger: None) -> None
|
||||
LoggingSettings(LOG_LEVEL="NOT_A_LEVEL", LOG_TO_FILE=False)
|
||||
|
||||
assert logging.getLogger().level == logging.INFO
|
||||
log_error.assert_called_once_with("Invalid log level %r; falling back to INFO.", "NOT_A_LEVEL")
|
||||
log_error.assert_called_once_with(
|
||||
"Invalid log level %r; falling back to INFO.", "NOT_A_LEVEL"
|
||||
)
|
||||
|
||||
|
||||
def test_configures_console_handler_only(restore_root_logger: None) -> None:
|
||||
@@ -66,7 +68,9 @@ def test_configures_file_handler_and_creates_parent_dir(
|
||||
|
||||
handlers = logging.getLogger().handlers
|
||||
assert any(type(handler) is logging.StreamHandler for handler in handlers)
|
||||
file_handlers = [handler for handler in handlers if isinstance(handler, logging.FileHandler)]
|
||||
file_handlers = [
|
||||
handler for handler in handlers if isinstance(handler, logging.FileHandler)
|
||||
]
|
||||
assert len(file_handlers) == 1
|
||||
assert log_file.parent.exists()
|
||||
assert isinstance(file_handlers[0], TimedRotatingFileHandler)
|
||||
@@ -77,12 +81,16 @@ def test_configures_file_handler_and_creates_parent_dir(
|
||||
assert file_handlers[0].encoding.lower() == "utf-8"
|
||||
|
||||
|
||||
def test_configures_custom_log_backup_count(tmp_path: Path, restore_root_logger: None) -> None:
|
||||
def test_configures_custom_log_backup_count(
|
||||
tmp_path: Path, restore_root_logger: None
|
||||
) -> None:
|
||||
log_file = tmp_path / "app.log"
|
||||
LoggingSettings(LOG_TO_FILE=True, LOG_FILE_PATH=str(log_file), LOG_BACKUP_COUNT=7)
|
||||
|
||||
file_handler = next(
|
||||
handler for handler in logging.getLogger().handlers if isinstance(handler, TimedRotatingFileHandler)
|
||||
handler
|
||||
for handler in logging.getLogger().handlers
|
||||
if isinstance(handler, TimedRotatingFileHandler)
|
||||
)
|
||||
|
||||
assert file_handler.backupCount == 7
|
||||
@@ -99,7 +107,9 @@ def test_writes_records_to_console_and_file(
|
||||
logging.getLogger("test.logging_output").info("record is written")
|
||||
|
||||
file_handler = next(
|
||||
handler for handler in logging.getLogger().handlers if isinstance(handler, TimedRotatingFileHandler)
|
||||
handler
|
||||
for handler in logging.getLogger().handlers
|
||||
if isinstance(handler, TimedRotatingFileHandler)
|
||||
)
|
||||
file_handler.flush()
|
||||
|
||||
@@ -112,7 +122,9 @@ def test_rotates_active_log_file(tmp_path: Path, restore_root_logger: None) -> N
|
||||
LoggingSettings(LOG_FILE_PATH=str(log_file))
|
||||
logger = logging.getLogger("test.logging_rotation")
|
||||
file_handler = next(
|
||||
handler for handler in logging.getLogger().handlers if isinstance(handler, TimedRotatingFileHandler)
|
||||
handler
|
||||
for handler in logging.getLogger().handlers
|
||||
if isinstance(handler, TimedRotatingFileHandler)
|
||||
)
|
||||
|
||||
logger.info("before rollover")
|
||||
@@ -137,7 +149,9 @@ def test_removes_old_rotated_files_after_backup_limit(
|
||||
LoggingSettings(LOG_FILE_PATH=str(log_file), LOG_BACKUP_COUNT=2)
|
||||
logger = logging.getLogger("test.logging_retention")
|
||||
file_handler = next(
|
||||
handler for handler in logging.getLogger().handlers if isinstance(handler, TimedRotatingFileHandler)
|
||||
handler
|
||||
for handler in logging.getLogger().handlers
|
||||
if isinstance(handler, TimedRotatingFileHandler)
|
||||
)
|
||||
base_timestamp = int(time.time())
|
||||
|
||||
@@ -146,7 +160,8 @@ def test_removes_old_rotated_files_after_backup_limit(
|
||||
file_handler.flush()
|
||||
rollover_timestamp = base_timestamp + day * SECONDS_PER_DAY
|
||||
file_handler.rolloverAt = rollover_timestamp + SECONDS_PER_DAY
|
||||
monkeypatch.setattr(time, "time", lambda: rollover_timestamp)
|
||||
# Bind the loop variable via a default argument to avoid late binding (B023).
|
||||
monkeypatch.setattr(time, "time", lambda now=rollover_timestamp: now)
|
||||
file_handler.doRollover()
|
||||
|
||||
assert len(list(tmp_path.glob("app.*.log"))) == 2
|
||||
@@ -162,7 +177,9 @@ def test_setup_logging_is_idempotent(tmp_path: Path, restore_root_logger: None)
|
||||
settings = LoggingSettings(LOG_TO_FILE=True, LOG_FILE_PATH=str(log_file))
|
||||
|
||||
first_file_handler = next(
|
||||
handler for handler in logging.getLogger().handlers if isinstance(handler, logging.FileHandler)
|
||||
handler
|
||||
for handler in logging.getLogger().handlers
|
||||
if isinstance(handler, logging.FileHandler)
|
||||
)
|
||||
first_handler_count = len(logging.getLogger().handlers)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user