File size: 2,741 Bytes
3bfeece
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from core.gemini_agent import _keyword_extract, _keyword_filter, _parse_attributes


def test_female_query_does_not_add_male():
    attrs = _keyword_extract("smiling woman with blond hair")
    assert "Male" not in attrs
    assert "Smiling" in attrs
    assert "Blond_Hair" in attrs


def test_female_query_excludes_male():
    attrs, excluded = _keyword_filter("young smiling woman with blond hair")
    assert "Male" not in attrs
    assert excluded == ["Male"]


def test_male_query_requires_male_and_does_not_exclude_it():
    attrs, excluded = _keyword_filter("young man with glasses")
    assert "Male" in attrs
    assert "Eyeglasses" in attrs
    assert "Male" not in excluded


def test_no_glasses_is_an_exclusion_not_a_requirement():
    attrs, excluded = _keyword_filter("woman with no glasses")
    assert "Eyeglasses" not in attrs
    assert "Eyeglasses" in excluded
    assert "Male" in excluded


def test_without_a_hat_is_an_exclusion():
    attrs, excluded = _keyword_filter("man without a hat")
    assert "Wearing_Hat" not in attrs
    assert "Wearing_Hat" in excluded
    assert "Male" in attrs


def test_clean_shaven_excludes_facial_hair():
    attrs, excluded = _keyword_filter("clean-shaven man")
    assert "No_Beard" in attrs
    for attr in ("Mustache", "Goatee", "5_o_Clock_Shadow"):
        assert attr in excluded


def test_not_a_man_excludes_male():
    attrs, excluded = _keyword_filter("not a man")
    assert "Male" not in attrs
    assert "Male" in excluded


def test_old_query_does_not_add_young():
    attrs = _keyword_extract("older person with gray hair and a goatee")
    assert "Young" not in attrs
    assert "Gray_Hair" in attrs
    assert "Goatee" in attrs


def test_beard_is_not_mapped_to_no_beard():
    attrs = _keyword_extract("person with beard and mustache")
    assert "No_Beard" not in attrs
    assert "Mustache" in attrs


def test_explicit_no_beard_is_kept():
    attrs = _keyword_extract("beardless young man")
    assert "No_Beard" in attrs
    assert "Young" in attrs
    assert "Male" in attrs


def test_parse_accepts_bare_array():
    assert _parse_attributes('["Male", "Eyeglasses"]') == ["Male", "Eyeglasses"]


def test_parse_accepts_object_and_normalises_case():
    assert _parse_attributes('{"attributes": ["male", "BLACK_HAIR"]}') == [
        "Male",
        "Black_Hair",
    ]


def test_parse_strips_code_fences():
    assert _parse_attributes('```json\n["Young", "Smiling"]\n```') == [
        "Young",
        "Smiling",
    ]


def test_parse_rejects_unknown_attributes():
    assert _parse_attributes('["Male", "Wings", "Smiling"]') == ["Male", "Smiling"]


def test_parse_garbage_returns_empty():
    assert _parse_attributes("I cannot help with that.") == []