| |
| |
| |
|
|
| import json |
| import sys |
| from pathlib import Path |
|
|
| |
| |
| |
| TEST_DIR = Path(__file__).parent |
| sys.path.insert(0, str(TEST_DIR)) |
|
|
| |
| |
| |
| from calc_TVA import calculate_tva |
| import calc_TVA |
|
|
| JSON_PATH = TEST_DIR / "VAT_2025.json" |
| if not JSON_PATH.exists(): |
| print(f"ERROR: {JSON_PATH} not found!") |
| sys.exit(1) |
|
|
| calc_TVA.__dict__["_JSON_PATH"] = str(JSON_PATH) |
|
|
| |
| |
| |
| TESTS = [ |
| |
| (15000, "restauration", 1500.0, "10%"), |
| (15000, "restaurant", 1500.0, "10%"), |
| (15000, "repas", 1500.0, "10%"), |
| (1200, "livre", 66.0, "5.5%"), |
| (1200, "livres", 66.0, "5.5%"), |
| (1200, "produits alimentaires", 66.0, "5.5%"), |
| (1200, "cantine scolaire", 66.0, "5.5%"), |
| (1200, "cinΓ©ma", 66.0, "5.5%"), |
| (1200, "travaux Γ©nergΓ©tiques", 66.0, "5.5%"), |
| (1200, "logements sociaux", 66.0, "5.5%"), |
| (500, "mΓ©dicaments remboursables", 10.5, "2.1%"), |
| (500, "presse", 10.5, "2.1%"), |
| (500, "animaux de boucherie", 10.5, "2.1%"), |
| (10000, "voiture", 2000.0, "20%"), |
| (10000, "tΓ©lΓ©phone", 2000.0, "20%"), |
| (10000, "meuble", 2000.0, "20%"), |
| (10000, "default", 2000.0, "20%"), |
| (10000, "corse", None, "variable"), |
| (10000, "dom", None, "variable"), |
| (10000, "guadeloupe", None, "variable"), |
| (10000, "outre-mer", None, "variable"), |
| (0, "restauration", 0.0, "10%"), |
| (99.99, "livre", 5.5, "5.5%"), |
| ] |
|
|
| |
| |
| |
| def run_tests(): |
| passed = 0 |
| failed = 0 |
| print(f"{'='*60}") |
| print(f" TVA 2025 TEST SUITE β {len(TESTS)} CASES") |
| print(f"{'='*60}") |
|
|
| for i, (amount, category, exp_tva, exp_hint) in enumerate(TESTS, 1): |
| try: |
| result = calculate_tva(amount, category) |
| tva = result.get("result") |
| expl = result.get("explanation", "") |
| src = result.get("source", "") |
|
|
| |
| if exp_hint == "variable": |
| if tva is None and "variable" in expl.lower(): |
| status = "PASSED" |
| passed += 1 |
| else: |
| status = "FAILED" |
| failed += 1 |
| |
| else: |
| expected_rate = float(exp_hint.strip("%")) / 100 |
| expected_tva_calc = round(amount * expected_rate, 2) |
| if abs((tva or 0) - expected_tva_calc) <= 0.01: |
| status = "PASSED" |
| passed += 1 |
| else: |
| status = "FAILED" |
| failed += 1 |
|
|
| |
| print(f"[{status}] Test {i:02d}") |
| print(f" β {amount:,.2f} β¬ | '{category}'") |
| if tva is not None: |
| print(f" β TVA = {tva:,.2f} β¬ | {expl}") |
| else: |
| print(f" β {expl}") |
| print(f" β Source: {src}") |
| print() |
|
|
| except Exception as e: |
| print(f"[ERROR] Test {i:02d} crashed: {e}\n") |
| failed += 1 |
|
|
| |
| print(f"{'='*60}") |
| print(f" SUMMARY: {passed} PASSED, {failed} FAILED") |
| if failed == 0: |
| print(f" ALL TESTS PASSED! calc_TVA.py is 100% correct.") |
| else: |
| print(f" FIX THE FAILED CASES ABOVE.") |
| print(f"{'='*60}") |
|
|
| |
| |
| |
| if __name__ == "__main__": |
| run_tests() |