JOJ3-config-generator/tests/convert/utils.py
李衍志523370910113 347c4b91d5
All checks were successful
build / build (push) Successful in 2m29s
build / build (pull_request) Successful in 2m27s
refactor/main (#11)
# what I have done

- sync main function in master branch and tested current code usage
- remove redundant code
- update README documents
- fix the immutable files logic

## TODO

- give fallback options for immutable files

Co-authored-by: Boming Zhang <bomingzh@sjtu.edu.cn>
Reviewed-on: #11
Co-authored-by: jon-lee <jon-lee@sjtu.edu.cn>
Co-committed-by: jon-lee <jon-lee@sjtu.edu.cn>
2025-02-27 15:51:31 +08:00

33 lines
1.0 KiB
Python

import json
from pathlib import Path
from typing import Any, Dict, Tuple
import rtoml
from joj3_config_generator.convert import convert
from joj3_config_generator.models import repo, task
def read_convert_files(
case_name: str,
) -> Tuple[repo.Config, task.Config, Dict[str, Any]]:
root = Path(__file__).resolve().parent / case_name
repo_toml_path = root / "repo.toml"
repo_toml = repo_toml_path.read_text() if repo_toml_path.exists() else ""
task_toml_path = root / "task.toml"
task_toml = task_toml_path.read_text() if task_toml_path.exists() else ""
result = json.loads((root / "task.json").read_text())
return (
repo.Config(root=root, **rtoml.loads(repo_toml)),
task.Config(root=root, **rtoml.loads(task_toml)),
result,
)
def load_case(case_name: str) -> None:
repo, task, expected_result = read_convert_files(case_name)
result = convert(repo, task).model_dump(
mode="json", by_alias=True, exclude_none=True
)
assert result == expected_result