mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-12-17 08:00:13 +01:00
test: convert tests to pytest assertions; add server-availability skips; clean up warnings and minor syntax/indent issues
This commit is contained in:
parent
f07daaeb4a
commit
947adacfe2
21 changed files with 374 additions and 311 deletions
|
|
@ -2,66 +2,43 @@
|
|||
"""Test the improved fuzzy matching and modal styling"""
|
||||
|
||||
import requests
|
||||
import pytest
|
||||
|
||||
test_cases = [
|
||||
("lightn", "Should find Lightning cards"),
|
||||
("lightni", "Should find Lightning with slight typo"),
|
||||
("bolt", "Should find Bolt cards"),
|
||||
("bligh", "Should find Blightning"),
|
||||
("unknowncard", "Should trigger confirmation modal"),
|
||||
("ligth", "Should find Light cards"),
|
||||
("boltt", "Should find Bolt with typo")
|
||||
]
|
||||
|
||||
for input_text, description in test_cases:
|
||||
@pytest.mark.parametrize(
|
||||
"input_text,description",
|
||||
[
|
||||
("lightn", "Should find Lightning cards"),
|
||||
("lightni", "Should find Lightning with slight typo"),
|
||||
("bolt", "Should find Bolt cards"),
|
||||
("bligh", "Should find Blightning"),
|
||||
("unknowncard", "Should trigger confirmation modal"),
|
||||
("ligth", "Should find Light cards"),
|
||||
("boltt", "Should find Bolt with typo"),
|
||||
],
|
||||
)
|
||||
def test_final_fuzzy(input_text: str, description: str):
|
||||
# Skip if local server isn't running
|
||||
try:
|
||||
requests.get('http://localhost:8080/', timeout=0.5)
|
||||
except Exception:
|
||||
pytest.skip('Local web server is not running on http://localhost:8080; skipping HTTP-based test')
|
||||
|
||||
print(f"\n🔍 Testing: '{input_text}' ({description})")
|
||||
print("=" * 60)
|
||||
|
||||
test_data = {
|
||||
"include_cards": input_text,
|
||||
"exclude_cards": "",
|
||||
"commander": "",
|
||||
"enforcement_mode": "warn",
|
||||
"allow_illegal": "false",
|
||||
"fuzzy_matching": "true"
|
||||
"fuzzy_matching": "true",
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
"http://localhost:8080/build/validate/include_exclude",
|
||||
data=test_data,
|
||||
timeout=10
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
|
||||
# Check results
|
||||
if data.get("confirmation_needed"):
|
||||
print(f"🔄 Confirmation modal would show:")
|
||||
for item in data["confirmation_needed"]:
|
||||
print(f" Input: '{item['input']}'")
|
||||
print(f" Confidence: {item['confidence']:.1%}")
|
||||
print(f" Suggestions: {item['suggestions'][:3]}")
|
||||
elif data.get("includes", {}).get("legal"):
|
||||
legal = data["includes"]["legal"]
|
||||
fuzzy = data["includes"].get("fuzzy_matches", {})
|
||||
if input_text in fuzzy:
|
||||
print(f"✅ Auto-accepted fuzzy match: '{input_text}' → '{fuzzy[input_text]}'")
|
||||
else:
|
||||
print(f"✅ Exact match: {legal}")
|
||||
elif data.get("includes", {}).get("illegal"):
|
||||
print(f"❌ No matches found")
|
||||
else:
|
||||
print(f"❓ Unclear result")
|
||||
else:
|
||||
print(f"❌ HTTP {response.status_code}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ EXCEPTION: {e}")
|
||||
|
||||
print(f"\n🎯 Summary:")
|
||||
print("✅ Enhanced prefix matching prioritizes Lightning cards for 'lightn'")
|
||||
print("✅ Dark theme modal styling implemented")
|
||||
print("✅ Confidence threshold set to 95% for more confirmations")
|
||||
print("💡 Ready for user testing in web UI!")
|
||||
response = requests.post(
|
||||
"http://localhost:8080/build/validate/include_exclude",
|
||||
data=test_data,
|
||||
timeout=10,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert isinstance(data, dict)
|
||||
assert 'includes' in data or 'confirmation_needed' in data or 'invalid' in data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue