add checks of the format of the paths in the database
Some checks failed
Ruff / ruff (push) Waiting to run
Mypy / mypy (push) Failing after 1m9s
Pytest / pytest (3.12) (push) Failing after 1m13s
Pytest / pytest (3.13) (push) Has been cancelled
Pytest / pytest (3.14) (push) Has been cancelled

This commit is contained in:
Justus Kuhlmann 2026-05-06 18:02:25 +02:00
commit 4c4a5fd670
Signed by: jkuhl
GPG key ID: 00ED992DD79B85A6
3 changed files with 40 additions and 5 deletions

View file

@ -7,7 +7,7 @@ from .tracker import get
import pyerrors.input.json as pj
import os
from configparser import ConfigParser
from .find import list_ensembles, list_projects
from typing import Any
@ -64,6 +64,31 @@ def are_keys_unique(db: Path, table: str, col: str) -> bool:
return bool(results[0] == results[1])
def check_path_format(result: pd.Series, ensembles: list[str], projects: list[str]) -> None:
"""
Check whether the path of the given result has the right format.
Parameters
----------
result: pd.Series
The result to be checked.
"""
p = result['path']
if not p.startswith('archive'):
raise ValueError(f'The path {p} does not start correctly')
meas_key = p.split('::')[1]
ensemble = p.split('/')[1]
project = p.split('/')[2].split('::')[0]
if not len(meas_key) == 64:
raise ValueError(f'meas_key of {p} is scrambled')
if ensemble not in ensembles:
raise ValueError(f'meas_key of {p} points to an unknown ensemble')
if project not in projects:
raise ValueError(f'meas_key of {p} points to an unknown project id')
def check_db_integrity(path: Path) -> None:
"""
Check intergrity of the database by checking the uniqueness of the record keys used to load the records
@ -82,10 +107,13 @@ def check_db_integrity(path: Path) -> None:
search_expr = "SELECT * FROM 'backlogs'"
conn = sqlite3.connect(path / db)
results = pd.read_sql(search_expr, conn)
ensembles = list_ensembles(path)
projects = [p[0] for p in list_projects(path)]
for _, result in results.iterrows():
if not has_valid_times(result):
raise ValueError(f"Result with id {result[id]} has wrong time signatures.")
check_path_format(result, ensembles, projects)
return