10
10
# Integration Tests (Real HF model)
11
11
# -----------------------------
12
12
skip_if_no_hf = pytest .mark .skipif (
13
- "HF_TOKEN" not in os .environ , reason = "Hugging Face token not available"
13
+ "HF_TOKEN" not in os .environ ,
14
+ reason = "Hugging Face token not available"
14
15
)
15
16
16
17
@@ -25,7 +26,10 @@ def detector_real() -> HallucinationDetector:
25
26
@skip_if_no_hf
26
27
@pytest .mark .requires ("integration" )
27
28
def test_extract_claims_integration (detector_real : HallucinationDetector ) -> None :
28
- text = "Barack Obama was the 44th President of the United States. He was born in Kenya."
29
+ text = (
30
+ "Barack Obama was the 44th President of the United States. "
31
+ "He was born in Kenya."
32
+ )
29
33
claims = detector_real .extract_claims (text )
30
34
# Check structure and basic logic
31
35
assert isinstance (claims , list )
@@ -39,9 +43,15 @@ def test_extract_claims_integration(detector_real: HallucinationDetector) -> Non
39
43
def test_compute_hallucination_rate_integration (
40
44
detector_real : HallucinationDetector ,
41
45
) -> None :
42
- text = "Barack Obama was the 44th President of the United States. He was born in Kenya."
46
+ text = (
47
+ "Barack Obama was the 44th President of the United States. "
48
+ "He was born in Kenya."
49
+ )
43
50
evidence = [
44
- "Barack Obama served as the 44th President of the United States from 2009 to 2017." ,
51
+ (
52
+ "Barack Obama served as the 44th President of the United States "
53
+ "from 2009 to 2017."
54
+ ),
45
55
"Barack Obama was born in Hawaii, not Kenya." ,
46
56
]
47
57
result = detector_real .compute_hallucination_rate (text , evidence )
@@ -78,15 +88,21 @@ def detector_mock() -> Generator[HallucinationDetector, None, None]:
78
88
79
89
80
90
def test_extract_claims_mock (detector_mock : HallucinationDetector ) -> None :
81
- text = "Barack Obama was the 44th President of the United States. He was born in Kenya."
91
+ text = (
92
+ "Barack Obama was the 44th President of the United States. "
93
+ "He was born in Kenya."
94
+ )
82
95
claims = detector_mock .extract_claims (text )
83
96
assert isinstance (claims , list )
84
97
assert len (claims ) == 2
85
98
86
99
87
100
def test_verify_claim_supported_mock (detector_mock : HallucinationDetector ) -> None :
88
101
claim = "Barack Obama was the 44th President of the United States"
89
- evidence = "Barack Obama served as the 44th President of the United States from 2009 to 2017."
102
+ evidence = (
103
+ "Barack Obama served as the 44th President of the United States "
104
+ "from 2009 to 2017."
105
+ )
90
106
assert detector_mock .verify_claim (claim , evidence ) is True
91
107
92
108
@@ -97,9 +113,15 @@ def test_verify_claim_unsupported_mock(detector_mock: HallucinationDetector) ->
97
113
98
114
99
115
def test_compute_hallucination_rate_mock (detector_mock : HallucinationDetector ) -> None :
100
- text = "Barack Obama was the 44th President of the United States. He was born in Kenya."
116
+ text = (
117
+ "Barack Obama was the 44th President of the United States. "
118
+ "He was born in Kenya."
119
+ )
101
120
evidence = [
102
- "Barack Obama served as the 44th President of the United States from 2009 to 2017." ,
121
+ (
122
+ "Barack Obama served as the 44th President of the United States "
123
+ "from 2009 to 2017." ,
124
+ ),
103
125
"Barack Obama was born in Hawaii, not Kenya." ,
104
126
]
105
127
result = detector_mock .compute_hallucination_rate (text , evidence )
0 commit comments