Skip to content

Commit 29612a5

Browse files
following pep8
1 parent 6814cc7 commit 29612a5

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

libs/langchain/tests/integration_tests/evaluation/hallucination/test_detector.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
# Integration Tests (Real HF model)
1111
# -----------------------------
1212
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"
1415
)
1516

1617

@@ -25,7 +26,10 @@ def detector_real() -> HallucinationDetector:
2526
@skip_if_no_hf
2627
@pytest.mark.requires("integration")
2728
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+
)
2933
claims = detector_real.extract_claims(text)
3034
# Check structure and basic logic
3135
assert isinstance(claims, list)
@@ -39,9 +43,15 @@ def test_extract_claims_integration(detector_real: HallucinationDetector) -> Non
3943
def test_compute_hallucination_rate_integration(
4044
detector_real: HallucinationDetector,
4145
) -> 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+
)
4350
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+
),
4555
"Barack Obama was born in Hawaii, not Kenya.",
4656
]
4757
result = detector_real.compute_hallucination_rate(text, evidence)
@@ -78,15 +88,21 @@ def detector_mock() -> Generator[HallucinationDetector, None, None]:
7888

7989

8090
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+
)
8295
claims = detector_mock.extract_claims(text)
8396
assert isinstance(claims, list)
8497
assert len(claims) == 2
8598

8699

87100
def test_verify_claim_supported_mock(detector_mock: HallucinationDetector) -> None:
88101
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+
)
90106
assert detector_mock.verify_claim(claim, evidence) is True
91107

92108

@@ -97,9 +113,15 @@ def test_verify_claim_unsupported_mock(detector_mock: HallucinationDetector) ->
97113

98114

99115
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+
)
101120
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+
),
103125
"Barack Obama was born in Hawaii, not Kenya.",
104126
]
105127
result = detector_mock.compute_hallucination_rate(text, evidence)

0 commit comments

Comments
 (0)