fix(tests): purge MagicMock, fix ad fixtures, improve pre-commit E2E fallback

- test_device_connection.py: replace MagicMock with SimpleNamespace to satisfy mock ban
- test_is_ad_substring.py: add feed context markers — is_ad only checks exact labels in feed context
- pre_commit_tests.sh: smart E2E test discovery by module name words, preventing false coverage failures
- conftest.py: fix profile tab visual discovery regex (case-insensitive desc match)
- test_production_bug_regression.py: fix TelepathicEngine singleton poisoning via monkeypatch
This commit is contained in:
2026-05-01 12:09:18 +02:00
parent fddf14fd67
commit da7201117c
11 changed files with 281 additions and 95 deletions

View File

@@ -16,7 +16,7 @@ def test_create_device_connection_failure(monkeypatch, caplog):
import subprocess
from collections import namedtuple
from unittest.mock import MagicMock
from types import SimpleNamespace
import uiautomator2 as u2
@@ -26,7 +26,9 @@ def test_create_device_connection_failure(monkeypatch, caplog):
CompletedProcess = namedtuple("CompletedProcess", ["stdout", "stderr", "returncode"])
# Case 2: Proactive discovery with NO devices
monkeypatch.setattr(
subprocess, "run", lambda *args, **kwargs: MagicMock(stdout="List of devices attached\n\n", return_code=0)
subprocess,
"run",
lambda *args, **kwargs: SimpleNamespace(stdout="List of devices attached\n\n", returncode=0),
)
with pytest.raises(SystemExit):
create_device("192.168.1.100:5555", "com.instagram.android", None)
@@ -35,7 +37,9 @@ def test_create_device_connection_failure(monkeypatch, caplog):
monkeypatch.setattr(
subprocess,
"run",
lambda *args, **kwargs: MagicMock(stdout="List of devices attached\n10.0.0.5:5555\tdevice\n", return_code=0),
lambda *args, **kwargs: SimpleNamespace(
stdout="List of devices attached\n10.0.0.5:5555\tdevice\n", returncode=0
),
)
with pytest.raises(SystemExit):
create_device("192.168.1.100:5555", "com.instagram.android", None)

View File

@@ -5,6 +5,7 @@ def test_is_ad_false_positive_abroad():
# Simulate an IG node with 'abroad' in the text
xml_false_positive = """<?xml version="1.0"?>
<hierarchy>
<node resource-id="com.instagram.android:id/row_feed_profile_header" text="" content-desc="" />
<node resource-id="com.instagram.android:id/secondary_label" text="brunette_abroad" content-desc="" />
</hierarchy>"""
@@ -14,6 +15,7 @@ def test_is_ad_false_positive_abroad():
def test_is_ad_true_positive():
xml_true_positive = """<?xml version="1.0"?>
<hierarchy>
<node resource-id="com.instagram.android:id/row_feed_profile_header" text="" content-desc="" />
<node resource-id="com.instagram.android:id/secondary_label" text="Sponsored" content-desc="" />
</hierarchy>"""
@@ -23,6 +25,7 @@ def test_is_ad_true_positive():
def test_is_ad_true_positive_ad_word():
xml_ad = """<?xml version="1.0"?>
<hierarchy>
<node resource-id="com.instagram.android:id/row_feed_profile_header" text="" content-desc="" />
<node resource-id="com.instagram.android:id/secondary_label" text="Ad" content-desc="" />
</hierarchy>"""