Skip to content

Commit 6c8fe93

Browse files
author
symphony-dbcli
committed
Work on #245
1 parent a9fc0e8 commit 6c8fe93

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Unreleased
22

3+
### Bug Fixes
4+
5+
- Expand `~` in configured log file paths before opening the log.
6+
37
### Internal
48

59
- Add a GitHub Actions workflow to run Codex review on pull requests.

‎litecli/main.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def initialize_logging(self) -> None:
249249
log_file = self.config["main"]["log_file"]
250250
if log_file == "default":
251251
log_file = config_location() + "log"
252+
log_file = os.path.expanduser(log_file)
252253
try:
253254
ensure_dir_exists(log_file)
254255
except OSError:

‎tests/test_main.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import os
23
import shutil
34
from collections import namedtuple
@@ -278,6 +279,33 @@ def test_startup_commands(executor):
278279
# implement tests on executions of the startupcommands
279280

280281

282+
def test_initialize_logging_expands_user_log_file(monkeypatch, tmp_path):
283+
home = tmp_path / "home"
284+
log_file = home / ".cache" / "litecli" / "log"
285+
monkeypatch.setenv("HOME", str(home))
286+
monkeypatch.setenv("USERPROFILE", str(home))
287+
288+
m = object.__new__(LiteCli)
289+
m.config = {"main": {"log_file": "~/.cache/litecli/log", "log_level": "INFO"}}
290+
echo_messages = []
291+
m.echo = lambda *args, **kwargs: echo_messages.append((args, kwargs))
292+
293+
root_logger = logging.getLogger("litecli")
294+
original_handlers = list(root_logger.handlers)
295+
try:
296+
m.initialize_logging()
297+
298+
added_handlers = [handler for handler in root_logger.handlers if handler not in original_handlers]
299+
assert log_file.exists()
300+
assert not echo_messages
301+
assert any(isinstance(handler, logging.FileHandler) and handler.baseFilename == str(log_file) for handler in added_handlers)
302+
finally:
303+
for handler in root_logger.handlers[:]:
304+
if handler not in original_handlers:
305+
root_logger.removeHandler(handler)
306+
handler.close()
307+
308+
281309
@patch("litecli.main.datetime") # Adjust if your module path is different
282310
def test_get_prompt(mock_datetime):
283311
# We'll freeze time at 2025-01-20 13:37:42 for comedic effect.

0 commit comments

Comments
 (0)