Files
computer-playbook/tests/unit/cli/core/test_logging.py
T
kevinveenbirkenbach 505af3e2ad cli: make --log require explicit directory and create parents automatically
- Change --log flag to require explicit log directory (--log <LOG_DIR>)
- Automatically create log directory with parents=True
- Harden permissions best-effort (0700)
- Update CLI help text accordingly
- Adjust Makefile test targets to pass explicit log directory
- Ignore logs/ via .gitignore and .dockerignore
- Refactor flag parsing to correctly detect deploy with --log
- Add dedicated logging unit tests
- Update existing tests for new log semantics
- Remove deprecated -i alias for --id in deploy command

https://chatgpt.com/share/6969680a-dbf8-800f-aafb-3d32d6212ba0
2026-01-15 23:19:31 +01:00

32 lines
903 B
Python

import tempfile
import unittest
from pathlib import Path
from cli.core.run import open_log_file
class TestLogging(unittest.TestCase):
def test_open_log_file_creates_parents_and_writes(self):
with tempfile.TemporaryDirectory() as td:
# nested path to ensure parents=True behavior is exercised
log_dir = Path(td) / "a" / "b" / "c" / "logs"
self.assertFalse(log_dir.exists())
f, path = open_log_file(log_dir)
try:
self.assertTrue(log_dir.exists())
self.assertTrue(path.exists())
self.assertIn(log_dir, path.parents)
f.write("hello\n")
f.flush()
content = path.read_text(encoding="utf-8")
self.assertIn("hello", content)
finally:
f.close()
if __name__ == "__main__":
unittest.main()