Exemple Python
Un exemple simple en Python.
Objectifs:
- Comparer 2 fichiers texte
- Produire un rapport HTML qui présente les erreurs détectées lors de la comparaison
- Utiliser le retour d'exécution
1. Créer les Fichiers
Sources on GithubStructure de fichiers
/mytest
/reference
data.txt
/test
data.txt
scilens.yml
run.py
reference/data.txt
Value A: 1
Value B: 2
Value C: 3
test/data.txt
Value A: 1
Value B: 2
Value C: 9
scilens.yml
processor: Compare
report:
title: "Get Started !"
output:
export_html: true
run.py
import os
from scilens import StandaloneTaskRunner
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
runner = StandaloneTaskRunner(f"{SCRIPT_DIR}/scilens.yml")
results = runner.process(SCRIPT_DIR, origin_working_dir=SCRIPT_DIR)
if results.error:
raise Exception(results.error)
else:
# here we expect no errors and no warnings
# but this demo will raise an AssertionError
assert not results.processor_results.errors and not results.processor_results.warnings
2. Exécuter le script python
Dans le répertoire mytest
python run.py
Cela générera :
- une exception
AssertionError
sera levée - un fichier
scilens_report.html
que vous pouvez ouvrir dans un navigateur web qui:- présente les erreurs détectés
