Spaces:
Sleeping
Sleeping
Download tests/test_coach_cli.py from shazhass/phytoevidence-api: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/spaces/shazhass/phytoevidence-api/resolve/main/tests/test_coach_cli.py
- Command line
-
hf download hf://spaces/shazhass/phytoevidence-api/tests/test_coach_cli.py
-
curl -L -o test_coach_cli.py https://huggingface.co/spaces/shazhass/phytoevidence-api/resolve/main/tests/test_coach_cli.py
1.88 kB
| import json | |
| import os | |
| import sqlite3 | |
| import subprocess | |
| import sys | |
| def run_cli(*args): | |
| env = {k: v for k, v in os.environ.items() if not k.startswith('COACH_')} | |
| return subprocess.run([sys.executable, '-m', 'coach', *map(str, args)], | |
| capture_output=True, text=True, env=env) | |
| def test_cli_reports_and_persists_without_loading_models(tmp_path): | |
| db = tmp_path / 'history.sqlite3' | |
| result = run_cli('--db', db) | |
| assert result.returncode == 0, result.stderr | |
| report = json.loads(result.stdout) | |
| assert report['advisor'] == 'deterministic' | |
| assert report['snapshot']['benchmark_cases'] == 16 | |
| with sqlite3.connect(db) as connection: | |
| saved = json.loads(connection.execute('SELECT report_json FROM coach_audits').fetchone()[0]) | |
| assert saved['audit_id'] == report['audit_id'] | |
| assert report['primary_action']['done_when'] | |
| def test_cli_invalid_input_does_not_create_history_or_echo_data(tmp_path): | |
| request = tmp_path / 'request.json' | |
| request.write_text('{"secret": "never-echo-this"}') | |
| db = tmp_path / 'history.sqlite3' | |
| result = run_cli('--db', db, '--input', request) | |
| assert result.returncode == 1 | |
| assert result.stderr.strip() == 'Audit impossible : vérifier les données et le stockage du coach.' | |
| assert not db.exists() | |
| assert not result.stdout | |
| assert 'never-echo-this' not in result.stderr | |
| def test_cli_corrupt_history_preserved_without_traceback(tmp_path): | |
| db = tmp_path / 'history.sqlite3' | |
| db.write_bytes(b'corrupt database private-data') | |
| result = run_cli('--db', db) | |
| assert result.returncode == 1 | |
| assert result.stderr.strip() == 'Audit impossible : vérifier les données et le stockage du coach.' | |
| assert db.read_bytes() == b'corrupt database private-data' | |
| assert 'Traceback' not in result.stderr | |
| assert 'private-data' not in result.stderr | |