Slice-Watch mit Ordnern/Filtern, Orca-Nachbearbeitung, Cockpit-Verlauf mit ED, Zeitzone im Browser. Tasten-Grenze und README-API angeglichen, toter Code entfernt, Requirements gepinnt.
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
"""Slice-Ordner (watch_dir) in config."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from grotti import config
|
|
from grotti.errors import GrottiError
|
|
|
|
|
|
class WatchDirTest(unittest.TestCase):
|
|
def test_empty(self):
|
|
path, stored = config.parse_watch_dir("")
|
|
self.assertIsNone(path)
|
|
self.assertEqual(stored, "")
|
|
|
|
def test_relative_under_root(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
target = root / "slice"
|
|
target.mkdir()
|
|
with patch.object(config, "ROOT", root):
|
|
path, stored = config.parse_watch_dir("slice", create=False)
|
|
self.assertEqual(path, target.resolve())
|
|
self.assertEqual(stored, "slice")
|
|
|
|
def test_create(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
with patch.object(config, "ROOT", root):
|
|
path, stored = config.parse_watch_dir("slice", create=True)
|
|
self.assertTrue(path.is_dir())
|
|
self.assertEqual(stored, "slice")
|
|
|
|
def test_file_rejected(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
file_path = root / "not-a-dir"
|
|
file_path.write_text("x", encoding="utf-8")
|
|
with patch.object(config, "ROOT", root):
|
|
with self.assertRaises(GrottiError):
|
|
config.parse_watch_dir(str(file_path), create=False)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|