Coverage for tools / sel_tools / utils / student_config.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-02 18:55 +0000

1"""Student config utilities.""" 

2 

3import json 

4from pathlib import Path 

5 

6from sel_tools.config import GIT_MAIN_BRANCH 

7 

8 

9def get_branch_from_student_config(student_config: dict) -> str: 

10 """Get branch from student config.""" 

11 return str(student_config.get("branch", GIT_MAIN_BRANCH)) 

12 

13 

14def store_student_repo_info_to_config_file( 

15 repo_info_dir: Path, group_name: str, student_repo_infos: list[dict] 

16) -> Path: 

17 """Store repo infos into config file created from repo info dir and repo_base_name. 

18 

19 Existing config files will be overwritten. 

20 """ 

21 student_repos_file = repo_info_dir.joinpath(group_name).with_suffix(".json") 

22 student_repos_file.write_text(json.dumps(student_repo_infos, sort_keys=True, indent=2)) 

23 return student_repos_file 

24 

25 

26def read_student_repo_info_from_config_file(config_file: Path | str) -> list[dict]: 

27 """Read student repo info from config file.""" 

28 return json.loads(Path(config_file).read_text()) # type: ignore[no-any-return]