2026-04-23 07:39:52 -05:00
|
|
|
from __future__ import annotations
|
2026-04-24 15:33:30 +02:00
|
|
|
|
2026-04-23 07:39:52 -05:00
|
|
|
import pytest
|
2026-04-24 15:33:30 +02:00
|
|
|
|
2026-04-23 07:39:52 -05:00
|
|
|
import headroom.transforms as transforms
|
2026-04-24 15:33:30 +02:00
|
|
|
|
|
|
|
|
|
2026-04-23 07:39:52 -05:00
|
|
|
def test_transforms_getattr_and_dir(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
|
|
|
monkeypatch.setattr(transforms, "_HTML_EXTRACTOR_AVAILABLE", True)
|
|
|
|
|
monkeypatch.setattr(
|
|
|
|
|
transforms,
|
|
|
|
|
"_LAZY_EXPORTS",
|
|
|
|
|
{"FakeExport": ("fake.module", "VALUE")},
|
|
|
|
|
)
|
|
|
|
|
monkeypatch.setattr(transforms, "import_module", lambda name: type("M", (), {"VALUE": 123})())
|
2026-04-24 15:33:30 +02:00
|
|
|
|
2026-04-23 07:39:52 -05:00
|
|
|
assert transforms.__getattr__("_HTML_EXTRACTOR_AVAILABLE") is True
|
|
|
|
|
assert transforms.__getattr__("FakeExport") == 123
|
|
|
|
|
assert transforms.FakeExport == 123
|
|
|
|
|
assert "FakeExport" in transforms.__dir__()
|
2026-04-24 15:33:30 +02:00
|
|
|
|
2026-04-23 07:39:52 -05:00
|
|
|
with pytest.raises(AttributeError, match="__path__"):
|
|
|
|
|
transforms.__getattr__("__path__")
|
2026-04-24 15:33:30 +02:00
|
|
|
|
2026-04-23 07:39:52 -05:00
|
|
|
with pytest.raises(AttributeError, match="MissingExport"):
|
|
|
|
|
transforms.__getattr__("MissingExport")
|