fix(tests): purge theater/broken tests, fix Config argparse pollution, fix is_ad() false positive
PHASE 1 — STOP THE BLEEDING: - Delete 6 theater/dead test files (empty stubs, skipped placeholders) - Create root conftest.py to isolate Config/argparse from pytest sys.argv - Rewrite test_feed_loop_continuation.py: replace inspect.getsource() theater with real DopamineEngine behavior tests - Rewrite test_ad_detection.py: use existing XML fixtures instead of phantoms - Rewrite test_false_positive.py: use verified fixtures, caught REAL bug PRODUCTION FIX: - Fix is_ad() false positive: regex \bad\b was matching 'Create messaging ad' in DM inbox. Changed to exact label matching (text/desc must BE the ad marker, not merely contain it) Result: 34 FAILED + 4 ERRORS -> 0 FAILED, 178 PASSED, 3 SKIPPED
This commit is contained in:
@@ -1,3 +1,14 @@
|
||||
"""
|
||||
Ad Detection Integration Tests — Using Real XML Fixtures
|
||||
=========================================================
|
||||
Tests is_ad() against real production XML dumps that actually exist
|
||||
in the fixtures directory.
|
||||
|
||||
Previous tests referenced phantom fixtures (sponsored_reel.xml,
|
||||
organic_post.xml, peugeot_ad.xml) that were never captured.
|
||||
These tests use verified, existing fixtures.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from GramAddict.core.utils import is_ad
|
||||
@@ -5,37 +16,49 @@ from GramAddict.core.utils import is_ad
|
||||
FIX_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "fixtures")
|
||||
|
||||
|
||||
def test_real_sponsored_reel_flexcode_is_detected():
|
||||
def test_home_feed_with_ad_is_detected():
|
||||
"""
|
||||
Test: The manual_interrupt dump is a sponsored Reel (flexcode_systems).
|
||||
is_ad MUST return True.
|
||||
Test: home_feed_with_ad.xml contains a real 'Ad' marker on an Instagram
|
||||
sponsored post. is_ad() MUST return True.
|
||||
"""
|
||||
xml_path = os.path.join(FIX_DIR, "sponsored_reel.xml")
|
||||
xml_path = os.path.join(FIX_DIR, "home_feed_with_ad.xml")
|
||||
with open(xml_path, "r") as f:
|
||||
xml = f.read()
|
||||
|
||||
assert is_ad(xml) is True, "Failed to detect Sponsored Reel ad in realistic dump!"
|
||||
assert is_ad(xml) is True, "Failed to detect real Ad in home_feed_with_ad.xml!"
|
||||
|
||||
|
||||
def test_normal_post_not_ad():
|
||||
def test_explore_feed_is_not_ad():
|
||||
"""
|
||||
Test: The manual_interrupt dump is a normal post.
|
||||
is_ad MUST return False to avoid false positives.
|
||||
Test: explore_feed_dump.xml is a normal explore grid.
|
||||
is_ad() MUST return False — no false positives.
|
||||
"""
|
||||
xml_path = os.path.join(FIX_DIR, "organic_post.xml")
|
||||
xml_path = os.path.join(FIX_DIR, "explore_feed_dump.xml")
|
||||
with open(xml_path, "r") as f:
|
||||
xml = f.read()
|
||||
|
||||
assert is_ad(xml) is False, "False positive! Detected normal post as ad!"
|
||||
assert is_ad(xml) is False, "False positive! Normal explore feed detected as ad!"
|
||||
|
||||
|
||||
def test_peugeot_carousel_ad_is_detected():
|
||||
def test_user_profile_is_not_ad():
|
||||
"""
|
||||
Test: The 'peugeot.deutschland' carousel ad from manual_interrupt dump.
|
||||
is_ad MUST return True.
|
||||
Test: user_profile_dump.xml is a profile page.
|
||||
is_ad() MUST return False.
|
||||
"""
|
||||
xml_path = os.path.join(FIX_DIR, "peugeot_ad.xml")
|
||||
xml_path = os.path.join(FIX_DIR, "user_profile_dump.xml")
|
||||
with open(xml_path, "r") as f:
|
||||
xml = f.read()
|
||||
|
||||
assert is_ad(xml) is True, "Failed to detect Peugeot Carousel ad from manual dump!"
|
||||
assert is_ad(xml) is False, "False positive! Profile page detected as ad!"
|
||||
|
||||
|
||||
def test_reels_feed_is_not_ad():
|
||||
"""
|
||||
Test: reels_feed_dump.xml is a normal reels page.
|
||||
is_ad() MUST return False.
|
||||
"""
|
||||
xml_path = os.path.join(FIX_DIR, "reels_feed_dump.xml")
|
||||
with open(xml_path, "r") as f:
|
||||
xml = f.read()
|
||||
|
||||
assert is_ad(xml) is False, "False positive! Reels feed detected as ad!"
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
"""
|
||||
False Positive Detection Test — Using Real XML Fixtures
|
||||
========================================================
|
||||
Ensures is_ad() does not flag normal content as sponsored.
|
||||
Uses existing, verified fixture files.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from GramAddict.core.utils import is_ad
|
||||
@@ -5,12 +12,34 @@ from GramAddict.core.utils import is_ad
|
||||
FIX_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "fixtures")
|
||||
|
||||
|
||||
def test_real_normal_post_is_not_ad():
|
||||
def test_normal_explore_post_is_not_ad():
|
||||
"""
|
||||
Test: Ensures the ad detector correctly ignores a standard organic post.
|
||||
Test: Ensures the ad detector correctly ignores a standard explore grid.
|
||||
"""
|
||||
xml_path = os.path.join(FIX_DIR, "organic_post.xml")
|
||||
xml_path = os.path.join(FIX_DIR, "explore_feed_dump.xml")
|
||||
with open(xml_path, "r") as f:
|
||||
real_xml = f.read()
|
||||
|
||||
assert is_ad(real_xml) is False, "False positive! Normal post detected as ad!"
|
||||
assert is_ad(real_xml) is False, "False positive! Normal explore detected as ad!"
|
||||
|
||||
|
||||
def test_dm_inbox_is_not_ad():
|
||||
"""
|
||||
Test: DM inbox should never be classified as an ad.
|
||||
"""
|
||||
xml_path = os.path.join(FIX_DIR, "dm_inbox_dump.xml")
|
||||
with open(xml_path, "r") as f:
|
||||
real_xml = f.read()
|
||||
|
||||
assert is_ad(real_xml) is False, "False positive! DM inbox detected as ad!"
|
||||
|
||||
|
||||
def test_stories_feed_is_not_ad():
|
||||
"""
|
||||
Test: Stories feed should never be classified as an ad.
|
||||
"""
|
||||
xml_path = os.path.join(FIX_DIR, "stories_feed_dump.xml")
|
||||
with open(xml_path, "r") as f:
|
||||
real_xml = f.read()
|
||||
|
||||
assert is_ad(real_xml) is False, "False positive! Stories feed detected as ad!"
|
||||
|
||||
Reference in New Issue
Block a user