Compare commits

..

No commits in common. "c19801f9a159d4b6720cc342a11a8acce7644bef" and "994137af8584d6dac33f098379805efc8086e5bc" have entirely different histories.

14 changed files with 136 additions and 114 deletions

View File

@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out repository code - name: Check out repository code
uses: actions/checkout@focs uses: https://gitea.com/BoYanZh/checkout@focs
- name: Display Python3 version - name: Display Python3 version
run: python3 --version run: python3 --version
- name: Install PDM - name: Install PDM

View File

@ -15,7 +15,6 @@
3. Change dir to the repo, `cd JOJ3-config-generator` 3. Change dir to the repo, `cd JOJ3-config-generator`
4. Install deps by `pdm install && pdm run pre-commit install` 4. Install deps by `pdm install && pdm run pre-commit install`
5. Run the cli app by `pdm run app --help` 5. Run the cli app by `pdm run app --help`
<<<<<<< HEAD
## How to use? ## How to use?
@ -29,6 +28,3 @@
```shell ```shell
joj3-config-generator convert -d -c /home/tt/.config/joj/ -r immutable_files joj3-config-generator convert -d -c /home/tt/.config/joj/ -r immutable_files
``` ```
=======
6. Check other commands or scripts with `pdm run --list`
>>>>>>> master

View File

@ -22,7 +22,9 @@ from joj3_config_generator.processers.task import (
) )
def convert(repo_conf: repo.Config, task_conf: task.Config) -> result.Config: def convert(
repo_conf: repo.Config, task_conf: task.Config, repo_root: Path
) -> result.Config:
# Create the base ResultConf object # Create the base ResultConf object
result_conf = result.Config( result_conf = result.Config(
name=task_conf.task.name, name=task_conf.task.name,
@ -47,7 +49,7 @@ def convert(repo_conf: repo.Config, task_conf: task.Config) -> result.Config:
not repo_conf.force_skip_heatlh_check_on_test not repo_conf.force_skip_heatlh_check_on_test
or os.environ.get("PYTEST_CURRENT_TEST") is None or os.environ.get("PYTEST_CURRENT_TEST") is None
): ):
healthcheck_stage = get_healthcheck_config(repo_conf) healthcheck_stage = get_healthcheck_config(repo_conf, repo_root)
result_conf.stage.stages.append(healthcheck_stage) result_conf.stage.stages.append(healthcheck_stage)
stages: List[str] = [] stages: List[str] = []
# Convert each stage in the task configuration # Convert each stage in the task configuration
@ -84,7 +86,9 @@ def distribute_json(folder_path: str, repo_obj: Any, repo_conf: Path) -> None:
with open(toml_file_path) as toml_file: with open(toml_file_path) as toml_file:
task_toml = toml_file.read() task_toml = toml_file.read()
task_obj = rtoml.loads(task_toml) task_obj = rtoml.loads(task_toml)
result_model = convert(repo.Config(**repo_obj), task.Config(**task_obj)) result_model = convert(
repo.Config(**repo_obj), task.Config(**task_obj), repo_conf
)
result_dict = result_model.model_dump(by_alias=True, exclude_none=True) result_dict = result_model.model_dump(by_alias=True, exclude_none=True)
with open(json_file_path, "w") as result_file: with open(json_file_path, "w") as result_file:

View File

@ -1,37 +1,21 @@
import json import json
import os
from pathlib import Path from pathlib import Path
from typing import Any, Dict
import inquirer
import rtoml import rtoml
import typer import typer
import yaml import yaml
from typing_extensions import Annotated
from joj3_config_generator.convert import convert as convert_conf from joj3_config_generator.convert import convert as convert_conf
from joj3_config_generator.convert import convert_joj1 as convert_joj1_conf from joj3_config_generator.convert import convert_joj1 as convert_joj1_conf
from joj3_config_generator.convert import distribute_json
from joj3_config_generator.models import joj1, repo, task from joj3_config_generator.models import joj1, repo, task
from joj3_config_generator.utils.logger import logger from joj3_config_generator.utils.logger import logger
app = typer.Typer(add_completion=False) app = typer.Typer(add_completion=False)
@app.command()
def create(toml: typer.FileTextWrite) -> None:
"""
Create a new JOJ3 toml config file
"""
logger.info("Creating")
questions = [
inquirer.List(
"size",
message="What size do you need?",
choices=["Jumbo", "Large", "Standard", "Medium", "Small", "Micro"],
),
]
answers = inquirer.prompt(questions)
logger.info(answers)
@app.command() @app.command()
def convert_joj1(yaml_file: typer.FileText, toml_file: typer.FileTextWrite) -> None: def convert_joj1(yaml_file: typer.FileText, toml_file: typer.FileTextWrite) -> None:
""" """
@ -41,42 +25,60 @@ def convert_joj1(yaml_file: typer.FileText, toml_file: typer.FileTextWrite) -> N
joj1_obj = yaml.safe_load(yaml_file.read()) joj1_obj = yaml.safe_load(yaml_file.read())
joj1_model = joj1.Config(**joj1_obj) joj1_model = joj1.Config(**joj1_obj)
task_model = convert_joj1_conf(joj1_model) task_model = convert_joj1_conf(joj1_model)
result_dict = task_model.model_dump(by_alias=True) result_dict = task_model.model_dump(by_alias=True, exclude_none=True)
toml_file.write(rtoml.dumps(result_dict)) toml_file.write(rtoml.dumps(result_dict))
@app.command() @app.command()
def convert( def convert(
root: Annotated[ root: Path = typer.Option(
Path, Path("."),
typer.Argument( "--conf-root",
help="root directory of config files, " "-c",
"located at /home/tt/.config/joj in JTC" help="This is where you want to put all your 'task.toml' type folders, default choice for your input can be '/home/tt/.config/joj/'",
),
repo_path: Path = typer.Option(
Path("."),
"--repo-root",
"-r",
help="This would be where you put your 'repo.toml' file as well as your 'immutable files', they should all be at same place, default choice for your input can be 'immutable_files', which is the folder at the position '/home/tt/.config/joj/'",
),
distribute: bool = typer.Option(
False, "--distribute", "-d", help="This flag determine whether to distribute"
), ),
] = Path(".")
) -> None: ) -> None:
"""
Convert given dir of JOJ3 toml config files to JOJ3 json config files
"""
logger.info(f"Converting files in {root.absolute()}") logger.info(f"Converting files in {root.absolute()}")
for repo_toml_path in root.glob("**/repo.toml"): if distribute is False:
repo_path = repo_toml_path.parent repo_toml_path = os.path.join(repo_path.absolute(), "basic", "repo.toml")
repo_obj = rtoml.loads(repo_toml_path.read_text()) else:
for task_toml_path in repo_path.glob("**/*.toml"): repo_toml_path = os.path.join("/home/tt/.config/joj", repo_path, "repo.toml")
if repo_toml_path == task_toml_path: repo_toml_path = os.path.join(repo_path, "repo.toml")
continue with open(repo_toml_path, encoding=None) as repo_file:
toml_name = task_toml_path.name.removesuffix(".toml") repo_toml = repo_file.read()
result_json_path = task_toml_path.parent / f"{toml_name}.json" repo_obj = rtoml.loads(repo_toml)
logger.info( if distribute is False:
f"Converting {repo_toml_path} & {task_toml_path} to {result_json_path}" task_toml_path = os.path.join(root.absolute(), "basic", "task.toml")
result_json_path = os.path.join(root.absolute(), "basic", "task.json")
with open(task_toml_path, encoding=None) as task_file:
task_toml = task_file.read()
task_obj = rtoml.loads(task_toml)
result_model = convert_conf(
repo.Config(**repo_obj), task.Config(**task_obj), repo_path
) )
task_obj = rtoml.loads(task_toml_path.read_text())
repo_conf = repo.Config(**repo_obj)
repo_conf.path = repo_toml_path
task_conf = task.Config(**task_obj)
task_conf.path = task_toml_path
result_model = convert_conf(repo_conf, task_conf)
result_dict = result_model.model_dump(by_alias=True, exclude_none=True) result_dict = result_model.model_dump(by_alias=True, exclude_none=True)
with result_json_path.open("w") as result_file:
with open(result_json_path, "w", encoding=None) as result_file:
json.dump(result_dict, result_file, ensure_ascii=False, indent=4) json.dump(result_dict, result_file, ensure_ascii=False, indent=4)
result_file.write("\n") result_file.write("\n")
# distribution on json
# need a get folder path function
else:
folder_path = "/home/tt/.config/joj"
folder_path = f"{Path.home()}/Desktop/engr151-joj/home/tt/.config/joj/homework"
folder_path = f"{Path.home()}/Desktop/FOCS/JOJ3-config-generator/tests/convert/"
# to be used in real action
folder_path = f"{root}"
distribute_json(folder_path, repo_obj, repo_path)

View File

@ -1,5 +1,4 @@
from pathlib import Path from typing import List
from typing import List, Optional
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -22,4 +21,3 @@ class Config(BaseModel):
max_total_score: int = Field(100) max_total_score: int = Field(100)
force_skip_heatlh_check_on_test: bool = False force_skip_heatlh_check_on_test: bool = False
groups: Groups = Groups() groups: Groups = Groups()
path: Path = Path(".")

View File

@ -1,8 +1,7 @@
from datetime import datetime from datetime import datetime
from pathlib import Path
from typing import Any, Dict, List, Optional, Type from typing import Any, Dict, List, Optional, Type
from pydantic import BaseModel, Field, model_validator from pydantic import BaseModel, Field, model_serializer, model_validator
class ParserResultDetail(BaseModel): class ParserResultDetail(BaseModel):
@ -110,5 +109,4 @@ class Task(BaseModel):
class Config(BaseModel): class Config(BaseModel):
task: Task task: Task
release: Release release: Release
path: Path = Path(".")
stages: List[Stage] # list of stage configurations stages: List[Stage] # list of stage configurations

View File

@ -37,7 +37,7 @@ def get_teapot_stage(repo_conf: repo.Config) -> result.StageDetail:
return stage_conf return stage_conf
def get_healthcheck_args(repo_conf: repo.Config) -> str: def get_healthcheck_args(repo_conf: repo.Config, repo_root: Path) -> str:
repoSize = repo_conf.max_size repoSize = repo_conf.max_size
immutable = repo_conf.files.immutable immutable = repo_conf.files.immutable
repo_size = f"-repoSize={str(repoSize)} " repo_size = f"-repoSize={str(repoSize)} "
@ -59,7 +59,7 @@ def get_healthcheck_args(repo_conf: repo.Config) -> str:
for meta in required_files: for meta in required_files:
args = args + meta args = args + meta
args = args + get_hash(immutable, repo_conf) args = args + get_hash(immutable, repo_root)
args = args + immutable_files args = args + immutable_files
@ -84,7 +84,9 @@ def get_debug_args(repo_conf: repo.Config) -> str:
return args return args
def get_healthcheck_config(repo_conf: repo.Config) -> result.StageDetail: def get_healthcheck_config(
repo_conf: repo.Config, repo_root: Path
) -> result.StageDetail:
healthcheck_stage = result.StageDetail( healthcheck_stage = result.StageDetail(
name="healthcheck", name="healthcheck",
group="", group="",
@ -94,7 +96,7 @@ def get_healthcheck_config(repo_conf: repo.Config) -> result.StageDetail:
default=result.Cmd(), default=result.Cmd(),
cases=[ cases=[
result.OptionalCmd( result.OptionalCmd(
args=shlex.split(get_healthcheck_args(repo_conf)), args=shlex.split(get_healthcheck_args(repo_conf, repo_root)),
), ),
result.OptionalCmd( result.OptionalCmd(
args=shlex.split(get_debug_args(repo_conf)), args=shlex.split(get_debug_args(repo_conf)),
@ -120,7 +122,7 @@ def calc_sha256sum(file_path: str) -> str:
def get_hash( def get_hash(
immutable_files: list[str], repo_conf: repo.Config immutable_files: list[str], repo_root: Path
) -> str: # input should be a list ) -> str: # input should be a list
# FIXME: should be finalized when get into the server # FIXME: should be finalized when get into the server
current_file_path = Path(__file__).resolve() current_file_path = Path(__file__).resolve()
@ -129,7 +131,7 @@ def get_hash(
file_path = f"{project_root}/tests/immutable_file/" file_path = f"{project_root}/tests/immutable_file/"
# file_path = "{Path.home()}/.cache/immutable" # file_path = "{Path.home()}/.cache/immutable"
# to be use # to be use
# file_path = repo_conf.path # file_path = f"/home/tt/.config/joj/{repo_root}/"
immutable_hash = [] immutable_hash = []
for i, file in enumerate(immutable_files): for i, file in enumerate(immutable_files):
immutable_files[i] = file_path + file.rsplit("/", 1)[-1] immutable_files[i] = file_path + file.rsplit("/", 1)[-1]

View File

@ -7,7 +7,7 @@
"maxTotalScore": 100, "maxTotalScore": 100,
"stage": { "stage": {
"sandboxExecServer": "172.17.0.1:5051", "sandboxExecServer": "172.17.0.1:5051",
"sandboxToken": "", "sandboxToken": "test",
"outputPath": "/tmp/joj3_result.json", "outputPath": "/tmp/joj3_result.json",
"stages": [ "stages": [
{ {
@ -60,8 +60,11 @@
"args": [ "args": [
"/usr/local/bin/repo-health-checker", "/usr/local/bin/repo-health-checker",
"-root=.", "-root=.",
"-repoSize=10", "-repoSize=50.5",
"-checkFileSumList=-checkFileNameList=" "-meta=README.md",
"-meta=Changelog.md",
"-checkFileSumList=a5b63323a692d3d8b952442969649b4f823d58dae26429494f613df160710dfc,b1bbad25b830db0a77b15a033f9ca1b7ab44c1d2d05056412bd3e4421645f0bf,f6740081487ca34963a005209e2e9adfdf6f3561719af082d40fe80145e0cceb,bbeca1491c2f8364821a328a6677c0c5d59ccd60250abac3cec0887eeb9bde3e",
"-checkFileNameList=.gitignore,.gitattributes,.gitea/workflows/push.yaml,.gitea/workflows/release.yaml"
], ],
"env": [ "env": [
"PATH=/usr/bin:/bin:/usr/local/bin" "PATH=/usr/bin:/bin:/usr/local/bin"
@ -83,7 +86,7 @@
"--grading-repo-name", "--grading-repo-name",
"ece280-joj", "ece280-joj",
"--group-config", "--group-config",
"=100:24" "joj=1000:24,run=1000:24,=100:24"
], ],
"env": [ "env": [
"LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log" "LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log"
@ -156,11 +159,11 @@
"cpuSetLimit": "", "cpuSetLimit": "",
"copyIn": { "copyIn": {
"tests/homework/h7/.clang-tidy": { "tests/homework/h7/.clang-tidy": {
"src": "/home/tt/.config/joj/tests/homework/h7/.clang-tidy", "src": "/home/tt/.config/joj/tools/tests/homework/h7/.clang-tidy",
"max": 419430400 "max": 419430400
}, },
"h7/build/compile_commands.json": { "h7/build/compile_commands.json": {
"src": "/home/tt/.config/joj/h7/build/compile_commands.json", "src": "/home/tt/.config/joj/tools/h7/build/compile_commands.json",
"max": 419430400 "max": 419430400
} }
}, },

View File

@ -7,7 +7,7 @@
"maxTotalScore": 100, "maxTotalScore": 100,
"stage": { "stage": {
"sandboxExecServer": "172.17.0.1:5051", "sandboxExecServer": "172.17.0.1:5051",
"sandboxToken": "", "sandboxToken": "test",
"outputPath": "/tmp/joj3_result.json", "outputPath": "/tmp/joj3_result.json",
"stages": [ "stages": [
{ {
@ -60,8 +60,11 @@
"args": [ "args": [
"/usr/local/bin/repo-health-checker", "/usr/local/bin/repo-health-checker",
"-root=.", "-root=.",
"-repoSize=10", "-repoSize=50.5",
"-checkFileSumList=-checkFileNameList=" "-meta=README.md",
"-meta=Changelog.md",
"-checkFileSumList=a5b63323a692d3d8b952442969649b4f823d58dae26429494f613df160710dfc,b1bbad25b830db0a77b15a033f9ca1b7ab44c1d2d05056412bd3e4421645f0bf,f6740081487ca34963a005209e2e9adfdf6f3561719af082d40fe80145e0cceb,bbeca1491c2f8364821a328a6677c0c5d59ccd60250abac3cec0887eeb9bde3e",
"-checkFileNameList=.gitignore,.gitattributes,.gitea/workflows/push.yaml,.gitea/workflows/release.yaml"
], ],
"env": [ "env": [
"PATH=/usr/bin:/bin:/usr/local/bin" "PATH=/usr/bin:/bin:/usr/local/bin"
@ -83,7 +86,7 @@
"--grading-repo-name", "--grading-repo-name",
"ece280-joj", "ece280-joj",
"--group-config", "--group-config",
"=100:24" "joj=1000:24,run=1000:24,=100:24"
], ],
"env": [ "env": [
"LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log" "LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log"

View File

@ -7,7 +7,7 @@
"maxTotalScore": 100, "maxTotalScore": 100,
"stage": { "stage": {
"sandboxExecServer": "172.17.0.1:5051", "sandboxExecServer": "172.17.0.1:5051",
"sandboxToken": "", "sandboxToken": "test",
"outputPath": "/tmp/joj3_result.json", "outputPath": "/tmp/joj3_result.json",
"stages": [ "stages": [
{ {
@ -60,8 +60,11 @@
"args": [ "args": [
"/usr/local/bin/repo-health-checker", "/usr/local/bin/repo-health-checker",
"-root=.", "-root=.",
"-repoSize=10", "-repoSize=50.5",
"-checkFileSumList=-checkFileNameList=" "-meta=README.md",
"-meta=Changelog.md",
"-checkFileSumList=a5b63323a692d3d8b952442969649b4f823d58dae26429494f613df160710dfc,b1bbad25b830db0a77b15a033f9ca1b7ab44c1d2d05056412bd3e4421645f0bf,f6740081487ca34963a005209e2e9adfdf6f3561719af082d40fe80145e0cceb,bbeca1491c2f8364821a328a6677c0c5d59ccd60250abac3cec0887eeb9bde3e",
"-checkFileNameList=.gitignore,.gitattributes,.gitea/workflows/push.yaml,.gitea/workflows/release.yaml"
], ],
"env": [ "env": [
"PATH=/usr/bin:/bin:/usr/local/bin" "PATH=/usr/bin:/bin:/usr/local/bin"
@ -83,7 +86,7 @@
"--grading-repo-name", "--grading-repo-name",
"ece280-joj", "ece280-joj",
"--group-config", "--group-config",
"=100:24" "joj=1000:24,run=1000:24,=100:24"
], ],
"env": [ "env": [
"LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log" "LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log"

View File

@ -7,7 +7,7 @@
"maxTotalScore": 100, "maxTotalScore": 100,
"stage": { "stage": {
"sandboxExecServer": "172.17.0.1:5051", "sandboxExecServer": "172.17.0.1:5051",
"sandboxToken": "", "sandboxToken": "test",
"outputPath": "/tmp/joj3_result.json", "outputPath": "/tmp/joj3_result.json",
"stages": [ "stages": [
{ {
@ -60,8 +60,11 @@
"args": [ "args": [
"/usr/local/bin/repo-health-checker", "/usr/local/bin/repo-health-checker",
"-root=.", "-root=.",
"-repoSize=10", "-repoSize=50.5",
"-checkFileSumList=-checkFileNameList=" "-meta=README.md",
"-meta=Changelog.md",
"-checkFileSumList=a5b63323a692d3d8b952442969649b4f823d58dae26429494f613df160710dfc,b1bbad25b830db0a77b15a033f9ca1b7ab44c1d2d05056412bd3e4421645f0bf,f6740081487ca34963a005209e2e9adfdf6f3561719af082d40fe80145e0cceb,bbeca1491c2f8364821a328a6677c0c5d59ccd60250abac3cec0887eeb9bde3e",
"-checkFileNameList=.gitignore,.gitattributes,.gitea/workflows/push.yaml,.gitea/workflows/release.yaml"
], ],
"env": [ "env": [
"PATH=/usr/bin:/bin:/usr/local/bin" "PATH=/usr/bin:/bin:/usr/local/bin"
@ -83,7 +86,7 @@
"--grading-repo-name", "--grading-repo-name",
"ece280-joj", "ece280-joj",
"--group-config", "--group-config",
"=100:24" "joj=1000:24,run=1000:24,=100:24"
], ],
"env": [ "env": [
"LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log" "LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log"
@ -147,7 +150,7 @@
"cpuSetLimit": "", "cpuSetLimit": "",
"copyIn": { "copyIn": {
"h7/build/ex2-asan": { "h7/build/ex2-asan": {
"src": "/home/tt/.config/joj/h7/build/ex2-asan", "src": "/home/tt/.config/joj/tools/h7/build/ex2-asan",
"max": 419430400 "max": 419430400
} }
}, },

View File

@ -7,7 +7,7 @@
"maxTotalScore": 100, "maxTotalScore": 100,
"stage": { "stage": {
"sandboxExecServer": "172.17.0.1:5051", "sandboxExecServer": "172.17.0.1:5051",
"sandboxToken": "", "sandboxToken": "test",
"outputPath": "/tmp/joj3_result.json", "outputPath": "/tmp/joj3_result.json",
"stages": [ "stages": [
{ {
@ -60,8 +60,11 @@
"args": [ "args": [
"/usr/local/bin/repo-health-checker", "/usr/local/bin/repo-health-checker",
"-root=.", "-root=.",
"-repoSize=10", "-repoSize=50.5",
"-checkFileSumList=-checkFileNameList=" "-meta=README.md",
"-meta=Changelog.md",
"-checkFileSumList=a5b63323a692d3d8b952442969649b4f823d58dae26429494f613df160710dfc,b1bbad25b830db0a77b15a033f9ca1b7ab44c1d2d05056412bd3e4421645f0bf,f6740081487ca34963a005209e2e9adfdf6f3561719af082d40fe80145e0cceb,bbeca1491c2f8364821a328a6677c0c5d59ccd60250abac3cec0887eeb9bde3e",
"-checkFileNameList=.gitignore,.gitattributes,.gitea/workflows/push.yaml,.gitea/workflows/release.yaml"
], ],
"env": [ "env": [
"PATH=/usr/bin:/bin:/usr/local/bin" "PATH=/usr/bin:/bin:/usr/local/bin"
@ -83,7 +86,7 @@
"--grading-repo-name", "--grading-repo-name",
"ece280-joj", "ece280-joj",
"--group-config", "--group-config",
"=100:24" "joj=1000:24,run=1000:24,=100:24"
], ],
"env": [ "env": [
"LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log" "LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log"
@ -154,7 +157,7 @@
"cpuSetLimit": "", "cpuSetLimit": "",
"copyIn": { "copyIn": {
"tools/filelength": { "tools/filelength": {
"src": "/home/tt/.config/joj/tools/filelength", "src": "/home/tt/.config/joj/tools/tools/filelength",
"max": 419430400 "max": 419430400
} }
}, },

View File

@ -1,4 +1,5 @@
import json import json
import os
from pathlib import Path from pathlib import Path
from typing import Any, Dict, Tuple from typing import Any, Dict, Tuple
@ -11,22 +12,24 @@ from joj3_config_generator.models import repo, task
def read_convert_files( def read_convert_files(
case_name: str, case_name: str,
) -> Tuple[repo.Config, task.Config, Dict[str, Any]]: ) -> Tuple[repo.Config, task.Config, Dict[str, Any]]:
root = Path(__file__).resolve().parent root = os.path.dirname(os.path.realpath(__file__))
repo_toml_path = root / case_name / "repo.toml" repo_toml_path = os.path.join(root, case_name, "repo.toml")
repo_toml = repo_toml_path.read_text() if repo_toml_path.exists() else "" with open(repo_toml_path) as f:
task_toml_path = root / case_name / "task.toml" repo_toml = f.read()
task_toml = task_toml_path.read_text() if task_toml_path.exists() else "" task_toml_path = os.path.join(root, case_name, "task.toml")
result = json.loads((root / case_name / "task.json").read_text()) with open(task_toml_path) as f:
return ( task_toml = f.read()
repo.Config(**rtoml.loads(repo_toml)), result_json_path = os.path.join(root, case_name, "task.json")
task.Config(**rtoml.loads(task_toml)), with open(result_json_path) as f:
result, result: Dict[str, Any] = json.load(f)
) repo_obj = rtoml.loads(repo_toml)
task_obj = rtoml.loads(task_toml)
return repo.Config(**repo_obj), task.Config(**task_obj), result
def load_case(case_name: str) -> None: def load_case(case_name: str) -> None:
repo, task, expected_result = read_convert_files(case_name) repo, task, expected_result = read_convert_files(case_name)
result = convert(repo, task).model_dump( result = convert(repo, task, repo_root=Path(".")).model_dump(
mode="json", by_alias=True, exclude_none=True mode="json", by_alias=True, exclude_none=True
) )
assert result == expected_result assert result == expected_result

View File

@ -1,4 +1,4 @@
from pathlib import Path import os
from typing import Any, Dict, Tuple from typing import Any, Dict, Tuple
import rtoml import rtoml
@ -9,12 +9,16 @@ from joj3_config_generator.models import joj1
def read_convert_joj1_files(case_name: str) -> Tuple[joj1.Config, Dict[str, Any]]: def read_convert_joj1_files(case_name: str) -> Tuple[joj1.Config, Dict[str, Any]]:
root = Path(__file__).resolve().parent root = os.path.dirname(os.path.realpath(__file__))
task_yaml_path = root / case_name / "task.yaml" task_yaml_path = os.path.join(root, case_name, "task.yaml")
task_yaml = task_yaml_path.read_text() with open(task_yaml_path) as f:
task_toml_path = root / case_name / "task.toml" task_yaml = f.read()
task_toml = task_toml_path.read_text() task_toml_path = os.path.join(root, case_name, "task.toml")
return joj1.Config(**yaml.safe_load(task_yaml)), rtoml.loads(task_toml) with open(task_toml_path) as f:
task_toml = f.read()
joj1_obj = yaml.safe_load(task_yaml)
task_obj = rtoml.loads(task_toml)
return joj1.Config(**joj1_obj), task_obj
def load_case(case_name: str) -> None: def load_case(case_name: str) -> None: