Spaces:
Sleeping
Sleeping
Download tests/test_csv_import.py from Stephan86/pdf-csv-agent: direct link, hf CLI and curl.
- Browser
- Download file 2.98 kB
-
https://huggingface.co/spaces/Stephan86/pdf-csv-agent/resolve/main/tests/test_csv_import.py
- Command line
-
hf download hf://spaces/Stephan86/pdf-csv-agent/tests/test_csv_import.py
-
curl -L -o test_csv_import.py https://huggingface.co/spaces/Stephan86/pdf-csv-agent/resolve/main/tests/test_csv_import.py
2.98 kB
| """Tests de l'ingestion CSV + mapping (core.csv_import).""" | |
| import pandas as pd | |
| from core.csv_import import parse_price, guess_col, csv_to_articles, GUESS, NONE_COL | |
| # ββ parse_price βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def test_parse_price_virgule(): | |
| assert parse_price("70,92") == 70.92 | |
| def test_parse_price_euro_et_espace(): | |
| assert parse_price("1 234,50 β¬") == 1234.50 | |
| def test_parse_price_entier(): | |
| assert parse_price("45") == 45.0 | |
| def test_parse_price_vide(): | |
| assert parse_price("") == 0.0 | |
| assert parse_price(None) == 0.0 | |
| def test_parse_price_non_numerique(): | |
| assert parse_price("sur devis") == 0.0 | |
| # ββ guess_col βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def test_guess_col_reference(): | |
| cols = ["Code Article", "DΓ©signation", "Tarif"] | |
| assert guess_col(cols, GUESS["reference"]) == "Code Article" | |
| def test_guess_col_libelle(): | |
| cols = ["Ref", "DΓ©signation", "PU"] | |
| assert guess_col(cols, GUESS["libelle"]) == "DΓ©signation" | |
| def test_guess_col_aucun(): | |
| assert guess_col(["X", "Y"], GUESS["prix"]) is None | |
| # ββ csv_to_articles : unitΓ©s variables prΓ©servΓ©es ββββββββββββββββββββββββββββ | |
| def _df(): | |
| return pd.DataFrame({ | |
| "Ref": ["V1", "R1", "M1", "S1"], | |
| "Designation":["Velours bleu", "Voilage", "Mousse 35kg", "Simili cuir"], | |
| "Tarif": ["70,92", "30,00", "12,50 β¬", "45"], | |
| "Cond": ["ml", "M", "U", "mΒ²"], | |
| }) | |
| def test_csv_to_articles_basic(): | |
| arts = csv_to_articles(_df(), "Ref", "Designation", "Tarif", "Cond") | |
| assert len(arts) == 4 | |
| assert arts[0]["reference"] == "V1" | |
| assert arts[0]["nom_dessin"] == "Velours bleu" | |
| assert arts[0]["prix_conseille"] == 70.92 | |
| def test_csv_to_articles_unites_telles_quelles(): | |
| arts = csv_to_articles(_df(), "Ref", "Designation", "Tarif", "Cond") | |
| unites = [a["unite"] for a in arts] | |
| # chaque ligne garde son unitΓ© propre, aucune uniformisation | |
| assert unites == ["ml", "M", "U", "mΒ²"] | |
| def test_csv_to_articles_sans_colonne_unite(): | |
| arts = csv_to_articles(_df(), "Ref", "Designation", "Tarif", NONE_COL) | |
| assert all(a["unite"] == "" for a in arts) # vide, jamais une valeur imposΓ©e | |
| def test_csv_to_articles_sans_prix(): | |
| arts = csv_to_articles(_df(), "Ref", "Designation", NONE_COL, "Cond") | |
| assert all(a["prix_conseille"] == 0.0 for a in arts) | |
| def test_csv_to_articles_ignore_lignes_vides(): | |
| df = pd.DataFrame({"Ref": ["A", ""], "Designation": ["x", ""], "Tarif": ["1", ""], "Cond": ["ml", ""]}) | |
| arts = csv_to_articles(df, "Ref", "Designation", "Tarif", "Cond") | |
| assert len(arts) == 1 | |