Skip to content

Commit 55a857d

Browse files
test: refactor report.to_html test to use parameterized embed values
- Updated the test for the RAGReport's to_html method to utilize pytest's parameterization for testing both embed=True and embed=False scenarios, enhancing test coverage and maintainability.
1 parent 7868cad commit 55a857d

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

‎tests/rag/test_report.py‎

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest.mock import Mock, patch
33

44
import numpy as np
5+
import pytest
56
from bokeh.plotting import figure
67

78
from giskard.rag import QATestset, RAGReport
@@ -98,34 +99,13 @@ def test_report_plots():
9899
assert len(histograms["Question"]["simple"]) == 4
99100

100101

101-
def test_report_to_html_with_embed():
102-
"""Test that to_html works correctly with embed=True parameter."""
102+
@pytest.mark.parametrize("embed", [False, True])
103+
def test_report_to_html(embed):
104+
"""Test that to_html works correctly with different embed parameter values."""
103105
testset, answers, metrics_results = _create_test_data()
104-
knowledge_base = Mock()
105-
106-
report = RAGReport(testset, answers, metrics_results, knowledge_base)
107-
108-
# Test to_html with embed=False (default behavior)
109-
html_output = report.to_html(embed=False)
110-
assert html_output is not None
111-
assert isinstance(html_output, str)
112-
assert html_output.startswith("<!DOCTYPE html>")
113106

114-
# Test to_html with embed=True
115-
embedded_output = report.to_html(embed=True)
116-
assert embedded_output is not None
117-
118-
# When embed=True, it should return an IPython HTML display object
119-
from IPython.core.display import HTML
120-
121-
assert isinstance(embedded_output, HTML)
122-
123-
# The embedded output should contain an iframe with the escaped HTML content
124-
iframe_html = embedded_output.data
125-
assert "<iframe" in iframe_html
126-
assert "srcdoc=" in iframe_html
127-
assert "width=100%" in iframe_html
128-
assert "height=800px" in iframe_html
107+
report = RAGReport(testset, answers, metrics_results)
108+
report.to_html(embed=embed)
129109

130110

131111
def test_report_save_load(tmp_path):

0 commit comments

Comments
 (0)