Spaces:
Running
Running
Delete tests
Browse files
tests/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
# This can be empty
|
|
|
|
tests/__pycache__/__init__.cpython-313.pyc
DELETED
Binary file (148 Bytes)
|
|
tests/__pycache__/test_recommender.cpython-313-pytest-8.3.4.pyc
DELETED
Binary file (25.1 kB)
|
|
tests/test_recommender.py
DELETED
@@ -1,136 +0,0 @@
|
|
1 |
-
import pytest
|
2 |
-
from src.recommender import GiftRecommender
|
3 |
-
from src.utils.text_processors import (
|
4 |
-
extract_age,
|
5 |
-
extract_gender,
|
6 |
-
extract_interests,
|
7 |
-
extract_dislikes
|
8 |
-
)
|
9 |
-
|
10 |
-
@pytest.fixture
|
11 |
-
def recommender():
|
12 |
-
"""Create a recommender instance for testing."""
|
13 |
-
return GiftRecommender()
|
14 |
-
|
15 |
-
@pytest.fixture
|
16 |
-
def sample_text():
|
17 |
-
"""Provide sample text for testing."""
|
18 |
-
return """I'm looking for a gift for my 25-year-old sister.
|
19 |
-
She loves painting and traveling, especially in Japan.
|
20 |
-
She hates loud noises and doesn't like spicy food."""
|
21 |
-
|
22 |
-
class TestTextProcessors:
|
23 |
-
"""Tests for text processing utility functions."""
|
24 |
-
|
25 |
-
def test_extract_age(self):
|
26 |
-
"""Test age extraction from text."""
|
27 |
-
test_cases = [
|
28 |
-
("25-year-old sister", 25),
|
29 |
-
("my sister is 30", 30),
|
30 |
-
("she is 25 years old", 25),
|
31 |
-
("no age here", None),
|
32 |
-
("age is 150 years", None), # Invalid age
|
33 |
-
]
|
34 |
-
|
35 |
-
for text, expected in test_cases:
|
36 |
-
assert extract_age(text) == expected
|
37 |
-
|
38 |
-
def test_extract_gender(self):
|
39 |
-
"""Test gender extraction from text."""
|
40 |
-
test_cases = [
|
41 |
-
("my sister likes", "female"),
|
42 |
-
("his brother wants", "male"),
|
43 |
-
("they like", "unknown"),
|
44 |
-
("my mother enjoys", "female"),
|
45 |
-
("dad loves", "male"),
|
46 |
-
]
|
47 |
-
|
48 |
-
for text, expected in test_cases:
|
49 |
-
assert extract_gender(text) == expected
|
50 |
-
|
51 |
-
def test_extract_interests(self):
|
52 |
-
"""Test interest extraction and categorization."""
|
53 |
-
text = "She loves painting and enjoys traveling"
|
54 |
-
categories = ["art", "travel", "music"]
|
55 |
-
|
56 |
-
interests = extract_interests(text, categories)
|
57 |
-
|
58 |
-
assert len(interests) == 2
|
59 |
-
assert any(i['phrase'] == 'painting' for i in interests)
|
60 |
-
assert any(i['phrase'] == 'traveling' for i in interests)
|
61 |
-
assert all('confidence' in i for i in interests)
|
62 |
-
assert all('sentiment' in i for i in interests)
|
63 |
-
|
64 |
-
def test_extract_dislikes(self):
|
65 |
-
"""Test dislike extraction from text."""
|
66 |
-
text = "She hates loud noises and doesn't like spicy food"
|
67 |
-
dislikes = extract_dislikes(text)
|
68 |
-
|
69 |
-
assert len(dislikes) == 2
|
70 |
-
assert "loud noises" in dislikes
|
71 |
-
assert "spicy food" in dislikes
|
72 |
-
|
73 |
-
class TestGiftRecommender:
|
74 |
-
"""Tests for main GiftRecommender class."""
|
75 |
-
|
76 |
-
def test_get_recommendations(self, recommender, sample_text):
|
77 |
-
"""Test the complete recommendation process."""
|
78 |
-
results = recommender.get_gift_recommendations(sample_text)
|
79 |
-
|
80 |
-
# Check if results contain all required fields
|
81 |
-
assert 'profile' in results
|
82 |
-
assert 'recommendations' in results
|
83 |
-
|
84 |
-
# Check profile data
|
85 |
-
profile = results['profile']
|
86 |
-
assert profile['age'] == 25
|
87 |
-
assert profile['gender'] == 'female'
|
88 |
-
assert len(profile['interests']) > 0
|
89 |
-
assert len(profile['dislikes']) > 0
|
90 |
-
|
91 |
-
# Check recommendations
|
92 |
-
recommendations = results['recommendations']
|
93 |
-
assert len(recommendations) > 0
|
94 |
-
assert all('gift' in r for r in recommendations)
|
95 |
-
assert all('reason' in r for r in recommendations)
|
96 |
-
|
97 |
-
def test_recommendation_relevance(self, recommender):
|
98 |
-
"""Test if recommendations are relevant to interests."""
|
99 |
-
text = "My brother loves gaming and technology"
|
100 |
-
results = recommender.get_gift_recommendations(text)
|
101 |
-
|
102 |
-
recommendations = results['recommendations']
|
103 |
-
assert any('gaming' in r['category'].lower() for r in recommendations)
|
104 |
-
assert any('technology' in r['category'].lower() for r in recommendations)
|
105 |
-
|
106 |
-
def test_format_recommendations(self, recommender, sample_text):
|
107 |
-
"""Test recommendation formatting."""
|
108 |
-
results = recommender.get_gift_recommendations(sample_text)
|
109 |
-
formatted = recommender.format_recommendations(results)
|
110 |
-
|
111 |
-
assert isinstance(formatted, str)
|
112 |
-
assert "Profile Summary" in formatted
|
113 |
-
assert "Top Recommendations" in formatted
|
114 |
-
assert "Age: 25" in formatted
|
115 |
-
assert "Gender: Female" in formatted
|
116 |
-
|
117 |
-
def test_empty_input(self, recommender):
|
118 |
-
"""Test handling of empty input."""
|
119 |
-
results = recommender.get_gift_recommendations("")
|
120 |
-
|
121 |
-
assert results['profile']['age'] is None
|
122 |
-
assert results['profile']['gender'] == 'unknown'
|
123 |
-
assert len(results['recommendations']) == 0
|
124 |
-
|
125 |
-
@pytest.mark.parametrize("text,expected_count", [
|
126 |
-
("She loves art and music", 2),
|
127 |
-
("He likes gaming", 1),
|
128 |
-
("They enjoy reading, cooking, and traveling", 3),
|
129 |
-
])
|
130 |
-
def test_interest_count(self, recommender, text, expected_count):
|
131 |
-
"""Test counting of extracted interests."""
|
132 |
-
results = recommender.get_gift_recommendations(text)
|
133 |
-
assert len(results['profile']['interests']) == expected_count
|
134 |
-
|
135 |
-
if __name__ == '__main__':
|
136 |
-
pytest.main([__file__])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|