mirror of
https://github.com/d9pouces/id_configurator.git
synced 2026-11-09 01:47:21 +01:00
3b6eb7290f
Signed-off-by: d9pouces <github@19pouces.net>
54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
from id_configurator.modules import base as base_module
|
|
from id_configurator.modules.base import (
|
|
Module,
|
|
all_modules,
|
|
register,
|
|
sanitize_filename,
|
|
)
|
|
|
|
|
|
def test_register_and_all_modules_are_isolated(monkeypatch) -> None:
|
|
monkeypatch.setattr(base_module, "_REGISTRY", [])
|
|
|
|
class DummyModule(Module):
|
|
name = "dummy"
|
|
|
|
def is_relevant(self, context) -> bool:
|
|
return True
|
|
|
|
def apply(self, context) -> None:
|
|
pass
|
|
|
|
register(DummyModule)
|
|
|
|
assert all_modules() == [DummyModule]
|
|
|
|
|
|
def test_sanitize_filename_leaves_plain_names_untouched() -> None:
|
|
assert sanitize_filename("interdiode") == "interdiode"
|
|
|
|
|
|
def test_sanitize_filename_replaces_forward_slash() -> None:
|
|
assert sanitize_filename("../../etc/passwd") == "______etc_passwd"
|
|
|
|
|
|
def test_sanitize_filename_replaces_backslash() -> None:
|
|
assert sanitize_filename(r"a\b") == "a_b"
|
|
|
|
|
|
def test_sanitize_filename_replaces_non_identifier_characters() -> None:
|
|
assert sanitize_filename("My Root CA (v2).pem\n") == "My_Root_CA__v2__pem_"
|
|
|
|
|
|
def test_sanitize_filename_keeps_letters_digits_underscore_and_dash() -> None:
|
|
assert sanitize_filename("Inter_Diode-2026") == "Inter_Diode-2026"
|
|
|
|
|
|
def test_sanitize_filename_never_returns_dot_names() -> None:
|
|
assert sanitize_filename(".") == "_"
|
|
assert sanitize_filename("..") == "__"
|
|
|
|
|
|
def test_sanitize_filename_never_returns_empty_string() -> None:
|
|
assert sanitize_filename("") == "_"
|