StillWorking commited on
Commit
3bfeece
·
verified ·
1 Parent(s): 9bd0b72

Upload backend/tests/test_gemini_fallback.py with huggingface_hub

Browse files
backend/tests/test_gemini_fallback.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from core.gemini_agent import _keyword_extract, _keyword_filter, _parse_attributes
2
+
3
+
4
+ def test_female_query_does_not_add_male():
5
+ attrs = _keyword_extract("smiling woman with blond hair")
6
+ assert "Male" not in attrs
7
+ assert "Smiling" in attrs
8
+ assert "Blond_Hair" in attrs
9
+
10
+
11
+ def test_female_query_excludes_male():
12
+ attrs, excluded = _keyword_filter("young smiling woman with blond hair")
13
+ assert "Male" not in attrs
14
+ assert excluded == ["Male"]
15
+
16
+
17
+ def test_male_query_requires_male_and_does_not_exclude_it():
18
+ attrs, excluded = _keyword_filter("young man with glasses")
19
+ assert "Male" in attrs
20
+ assert "Eyeglasses" in attrs
21
+ assert "Male" not in excluded
22
+
23
+
24
+ def test_no_glasses_is_an_exclusion_not_a_requirement():
25
+ attrs, excluded = _keyword_filter("woman with no glasses")
26
+ assert "Eyeglasses" not in attrs
27
+ assert "Eyeglasses" in excluded
28
+ assert "Male" in excluded
29
+
30
+
31
+ def test_without_a_hat_is_an_exclusion():
32
+ attrs, excluded = _keyword_filter("man without a hat")
33
+ assert "Wearing_Hat" not in attrs
34
+ assert "Wearing_Hat" in excluded
35
+ assert "Male" in attrs
36
+
37
+
38
+ def test_clean_shaven_excludes_facial_hair():
39
+ attrs, excluded = _keyword_filter("clean-shaven man")
40
+ assert "No_Beard" in attrs
41
+ for attr in ("Mustache", "Goatee", "5_o_Clock_Shadow"):
42
+ assert attr in excluded
43
+
44
+
45
+ def test_not_a_man_excludes_male():
46
+ attrs, excluded = _keyword_filter("not a man")
47
+ assert "Male" not in attrs
48
+ assert "Male" in excluded
49
+
50
+
51
+ def test_old_query_does_not_add_young():
52
+ attrs = _keyword_extract("older person with gray hair and a goatee")
53
+ assert "Young" not in attrs
54
+ assert "Gray_Hair" in attrs
55
+ assert "Goatee" in attrs
56
+
57
+
58
+ def test_beard_is_not_mapped_to_no_beard():
59
+ attrs = _keyword_extract("person with beard and mustache")
60
+ assert "No_Beard" not in attrs
61
+ assert "Mustache" in attrs
62
+
63
+
64
+ def test_explicit_no_beard_is_kept():
65
+ attrs = _keyword_extract("beardless young man")
66
+ assert "No_Beard" in attrs
67
+ assert "Young" in attrs
68
+ assert "Male" in attrs
69
+
70
+
71
+ def test_parse_accepts_bare_array():
72
+ assert _parse_attributes('["Male", "Eyeglasses"]') == ["Male", "Eyeglasses"]
73
+
74
+
75
+ def test_parse_accepts_object_and_normalises_case():
76
+ assert _parse_attributes('{"attributes": ["male", "BLACK_HAIR"]}') == [
77
+ "Male",
78
+ "Black_Hair",
79
+ ]
80
+
81
+
82
+ def test_parse_strips_code_fences():
83
+ assert _parse_attributes('```json\n["Young", "Smiling"]\n```') == [
84
+ "Young",
85
+ "Smiling",
86
+ ]
87
+
88
+
89
+ def test_parse_rejects_unknown_attributes():
90
+ assert _parse_attributes('["Male", "Wings", "Smiling"]') == ["Male", "Smiling"]
91
+
92
+
93
+ def test_parse_garbage_returns_empty():
94
+ assert _parse_attributes("I cannot help with that.") == []