Cassius1Morbant's picture
Upload 17 files
90355ac verified
# test_is_calculator.py
import json
from IS_taux import calculate_is
# === CHARGEMENT DU JSON (pour affichage clair) ===
with open("IS_taux.json", "r", encoding="utf-8") as f:
RATES = json.load(f)
print("Barème IS 2025 chargé :\n")
print(f" Taux normal : {RATES['standard_rate']*100}%")
print(f" Taux réduit PME : 15% jusqu'à {RATES['reduced_rates'][0]['profit_max']:,} €")
print(f" Éligibilité PME : CA < {RATES['eligibility']['turnover_max']:,} € HT, capital libéré, ≥{RATES['eligibility']['ownership_min_individuals']}% détenu par personnes physiques")
print("-" * 80)
# === FONCTION D'AFFICHAGE FORMATÉ ===
def print_result(title, result):
print(f"\n{title}")
print(f" → Bénéfice imposable : {result['taxable_profit']:,.2f} €")
print(f" → Impôt IS : {result['tax']:,.2f} €")
print(f" → PME éligible : {'Oui' if result['eligible_sme'] else 'Non'}")
if not result['eligible_sme']:
print(f" Raison : {result['reason']}")
print(f" → Note : {result['note']}")
# === TESTS COMPLETS ===
print("TESTS DE VÉRIFICATION IS 2025\n")
# Test 1 : PME, régime réel, bénéfice 540 000 € → TON CAS
result = calculate_is(
profit=540000, company_type="SASU", turnover_prev_year=8000000,
ownership_percentage=100, capital_fully_paid=True, bic_regime='real'
)
print_result("1. PME SASU – Bénéfice 540 000 € (ton cas)", result)
assert result['tax'] == 130750.0, "ERREUR : impôt doit être 130 750 €"
assert result['eligible_sme'] is True
# Test 2 : PME, bénéfice juste au seuil 42 500 €
result = calculate_is(
profit=42500, company_type="EURL", turnover_prev_year=5000000,
ownership_percentage=100, capital_fully_paid=True, bic_regime='real'
)
print_result("2. PME – Bénéfice pile 42 500 €", result)
assert result['tax'] == 6375.0
# Test 3 : PME, bénéfice 100 000 € → 15% + 25%
result = calculate_is(
profit=100000, company_type="SARL", turnover_prev_year=9000000,
ownership_percentage=80, capital_fully_paid=True, bic_regime='real'
)
print_result("3. PME – Bénéfice 100 000 €", result)
assert result['tax'] == 6375 + (100000 - 42500) * 0.25 # 6 375 + 14 375 = 20 750
# Test 4 : NON PME (CA trop élevé)
result = calculate_is(
profit=200000, company_type="SAS", turnover_prev_year=12000000,
ownership_percentage=100, capital_fully_paid=True, bic_regime='real'
)
print_result("4. NON PME – CA > 10 M€", result)
assert result['tax'] == 200000 * 0.25
assert result['eligible_sme'] is False
# Test 5 : NON PME (capital non libéré)
result = calculate_is(
profit=50000, company_type="SASU", turnover_prev_year=5000000,
ownership_percentage=100, capital_fully_paid=False, bic_regime='real'
)
print_result("5. NON PME – Capital non libéré", result)
assert result['eligible_sme'] is False
# Test 6 : Régime simplifié BIC – vente de marchandises
result = calculate_is(
profit=150000, company_type="SARL", turnover_prev_year=9000000,
ownership_percentage=100, capital_fully_paid=True,
bic_regime='simplified', activity_type='sales_goods'
)
print_result("6. Simplifié BIC – Vente marchandises (abattement 71%)", result)
expected_profit = 150000 * (1 - 0.71)
assert abs(result['taxable_profit'] - expected_profit) < 1
# Test 7 : Micro-BIC dépassé → rejet
result = calculate_is(
profit=200000, company_type="EURL", turnover_prev_year=5000000,
ownership_percentage=100, capital_fully_paid=True,
bic_regime='simplified', activity_type='sales_goods'
)
print_result("7. Micro-BIC dépassé (200k > 188.7k)", result)
assert result['taxable_profit'] == 0
assert "exceeds micro threshold" in result['reason']
# Test 8 : Bénéfice nul
result = calculate_is(
profit=0, company_type="SASU", turnover_prev_year=1000000,
ownership_percentage=100, capital_fully_paid=True, bic_regime='real'
)
print_result("8. Bénéfice nul", result)
assert result['tax'] == 0
# Test 9 : Activité libérale (BNC) → abattement 34%
result = calculate_is(
profit=70000, company_type="SELARL", turnover_prev_year=6000000,
ownership_percentage=75, capital_fully_paid=True,
bic_regime='simplified', activity_type='liberal_professions_bnc'
)
print_result("9. Simplifié BNC – Profession libérale", result)
expected = 70000 * (1 - 0.34)
assert abs(result['taxable_profit'] - expected) < 1
# Test 10 : Type société non listé → rejet éligibilité
result = calculate_is(
profit=100000, company_type="GIE", turnover_prev_year=5000000,
ownership_percentage=100, capital_fully_paid=True, bic_regime='real'
)
print_result("10. Société non listée (GIE)", result)
assert result['eligible_sme'] is False
print("\nTOUS LES TESTS SONT PASSÉS !")
print("Ton calculateur IS 2025 est 100% conforme au barème officiel.")