SPB Git forge

spb/rent-ka

Public
8commits 1branches 0releases
7.4 MBsize
maindefault branch
19 days agolast push
Python 68.8% TypeScript 18.6% CSS 8.7% JavaScript 3.3% HTML 0.6%
5.6 KB · 138 lines python
Raw Blame History
1# -----------------------------------------------------------------------------2# Rent-Ka — relevance-gate tests (quality.relevance_reason)3# Un stationnement/garage/local commercial à louer ne doit jamais être publié ;4# un logement qui INCLUT un stationnement doit rester publié.5# -----------------------------------------------------------------------------6from rentka.quality import evaluate, relevance_reason789def _reason(**kw):10    d = {"title": "", "description": "", "price": None, "unit_type": None,11         "bedrooms": None}12    d.update(kw)13    return relevance_reason(d)141516# ---- hors sujet : doivent être mis en quarantaine ---------------------------1718def test_parking_titre():19    assert _reason(title="Parking à louer", price=200.0)20    assert _reason(title="Stationnement extérieur privé à louer – près du métro",21                   price=100.0)22    assert _reason(title="Espace d'entreposage chauffé et éclairé", price=150.0)232425def test_garage_description_titre_trompeur():26    # logisquebec : « Appartement Garage à Louer » à 195 $ = un garage27    assert _reason(28        title="Costebelle-Banville Appartement Garage à Louer Duberger",29        description="Grand garage/entrepôt de 8 pieds par 20 pieds, situé au "30                    "cœur d'un quartier tranquille.",31        price=195.0, unit_type="3½")323334def test_stationnement_titre_adresse():35    # titre-adresse, la description révèle la case de stationnement36    assert _reason(title="P158 1400 Boul Rene Levesque O",37                   description="1 Stationnement intérieur #158 à vendre.",38                   price=250.0)394041def test_local_commercial():42    assert _reason(title="LOCAL COMMERCIAL À LOUER – CLÉ EN MAIN", price=3650.0)43    assert _reason(title="302 600 Rue Sherbrooke E",44                   description="Espace de bureau lumineux et fonctionnel de "45                               "290 pi², au centre-ville.", price=800.0)464748def test_prix_de_case_sans_signal_logement():49    assert _reason(title="1288 Rue St-Antoine O. app. P3-151",50                   description="Un dépot de $100 pour le ouvre garage.",51                   price=280.0, unit_type="Condo")525354def test_location_a_la_nuit():55    assert _reason(title="44, Perron O, Ste-Anne-Des-Monts à louer",56                   description="Location court terme seulement. Tarif par nuit "57                               "et non par mois.", price=210.0,58                   unit_type="Maison")596061# ---- logements légitimes : doivent rester publiés ---------------------------6263def test_logement_avec_stationnement_inclus():64    assert _reason(title="4½ NDG Stationnement + rangement inclus",65                   price=1150.0, unit_type="4½") is None66    assert _reason(title="Grand 2 1/2 avec électros/internet/stationnement",67                   price=995.0, unit_type="Studio") is None686970def test_logement_titre_garage_prix_plausible():71    # vrai 4½ dont le titre vante le garage72    assert _reason(title="Garage Intérieur Chauffé",73                   description="Magnifique logement 4 1/2, lumineux, doté d'un "74                               "balcon, d'un ascenseur.",75                   price=2250.0, unit_type="4½") is None767778def test_immeuble_mixte_residentiel():79    assert _reason(title="4 Boulevard Cartier O., app. 717",80                   description="Des résidences exquises et des espaces "81                               "commerciaux au rez-de-chaussée.",82                   price=2150.0, unit_type="4½") is None838485def test_nom_de_rue_bureau():86    assert _reason(title="3220 Av Jacques Bureau",87                   description="Magnifique logement de 2 chambres.",88                   price=1200.0) is None899091def test_chambre_pas_chere_reste_publiee():92    assert _reason(title="Grande Chambre ($600/mois), tout inclus + parking",93                   price=600.0, unit_type="Room") is None949596def test_evaluate_integre_la_pertinence():97    score, ok, reasons = evaluate({98        "title": "Parking à louer", "price": 200.0, "address": "123 rue X",99        "city": "Toronto", "province": "ON", "description": "Belle place de stationnement " * 10,100        "images": ["a.jpg"], "url": "https://x"})101    assert not ok102    assert any("off-topic" in r for r in reasons)103104105# ---- English vocabulary + territorial scope (Rent-Ka) ------------------------106107def test_parking_title_english():108    assert _reason(title="Parking spot for rent downtown", price=150.0)109    assert _reason(title="Storage locker available", price=90.0)110    assert _reason(title="Office space for lease", price=900.0)111112113def test_english_listing_stays_published():114    assert _reason(title="Bright 2 bedroom apartment with parking included",115                   price=1850.0, unit_type="2 bedrooms") is None116    assert _reason(title="Room in shared house near campus",117                   price=650.0, unit_type="Room") is None118119120def test_quebec_rows_are_quarantined():121    score, ok, reasons = evaluate({122        "title": "Grand 4½ lumineux", "price": 1200.0,123        "address": "555 rue Exemple", "city": "Montréal", "province": "QC",124        "description": "Superbe logement rénové avec balcon. " * 5,125        "images": ["a.jpg"], "url": "https://x"})126    assert not ok127    assert "outside-scope-quebec" in reasons128129130def test_ontario_rows_publish():131    score, ok, reasons = evaluate({132        "title": "2 bedroom apartment", "price": 1900.0,133        "address": "200 Bay St", "city": "Toronto", "province": "ON",134        "description": "Bright two bedroom apartment with balcony. " * 5,135        "images": ["a.jpg", "b.jpg"], "url": "https://x",136        "unit_type": "2 bedrooms"})137    assert ok, reasons138