Refactor handlers to be in their own classes for easier maintainability

This commit is contained in:
Miguel Jacq 2025-11-27 20:41:10 +11:00
parent d1ca60b779
commit 85f21e739d
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
19 changed files with 1826 additions and 1463 deletions

View file

@ -0,0 +1,34 @@
from __future__ import annotations
from pathlib import Path
import pytest
from jinjaturtle.handlers.base import BaseHandler
def test_split_inline_comment_handles_quoted_hash():
# The '#' inside quotes should not start a comment; the one outside should.
text = " 'foo # not comment' # real"
handler = BaseHandler()
value, comment = handler._split_inline_comment(text, {"#"})
assert "not comment" in value
assert comment.strip() == "# real"
def test_base_handler_abstract_methods_raise_not_implemented(tmp_path: Path):
"""
Ensure the abstract methods on BaseHandler all raise NotImplementedError.
This covers the stub implementations.
"""
handler = BaseHandler()
dummy_path = tmp_path / "dummy.cfg"
with pytest.raises(NotImplementedError):
handler.parse(dummy_path)
with pytest.raises(NotImplementedError):
handler.flatten(object())
with pytest.raises(NotImplementedError):
handler.generate_template(parsed=object(), role_prefix="role")