mirror of
https://github.com/d9pouces/id_configurator.git
synced 2026-11-09 01:47:21 +01:00
feat: update repository names to support special characters in configuration files
Signed-off-by: d9pouces <github@19pouces.net>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import tomllib
|
||||
|
||||
from id_configurator.config import Configuration
|
||||
from id_configurator.context import Context
|
||||
from id_configurator.modules.python import PythonModule
|
||||
@@ -76,6 +78,33 @@ def test_apply_single_repository(tmp_path) -> None:
|
||||
assert not (dst / "usr/lib").exists()
|
||||
|
||||
|
||||
def test_apply_escapes_non_bmp_characters_as_valid_toml(tmp_path) -> None:
|
||||
data = {
|
||||
"uuid": "12345678-1234-5678-1234-567812345678",
|
||||
"organisation": "InterDiode",
|
||||
"configurations": {
|
||||
"python": {
|
||||
"repositories": [
|
||||
{"name": "demo 😀", "index-url": "https://example.invalid/simple"}
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
config = Configuration.model_validate(data)
|
||||
dst = tmp_path / "dst"
|
||||
context = Context(config=config, dst=dst, src=None)
|
||||
|
||||
PythonModule().apply(context)
|
||||
|
||||
uv_toml = (dst / "etc/uv/uv.toml").read_text(encoding="utf-8")
|
||||
# json.dumps's default ensure_ascii=True would encode the emoji as a
|
||||
# UTF-16 surrogate pair (😀), which is valid JSON but not
|
||||
# valid TOML (TOML's \uXXXX must be a Unicode scalar value on its own).
|
||||
assert '"demo 😀"' in uv_toml
|
||||
parsed = tomllib.loads(uv_toml)
|
||||
assert parsed["index"][0]["name"] == "demo 😀"
|
||||
|
||||
|
||||
def test_apply_adds_trusted_host_for_non_https_repository(tmp_path) -> None:
|
||||
data = {
|
||||
"uuid": "12345678-1234-5678-1234-567812345678",
|
||||
|
||||
Reference in New Issue
Block a user