Skip to content

Commit

Permalink
addressing the reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
mrastgoo committed Dec 7, 2024
1 parent 15c7b06 commit 0debd0b
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions skrub/_reporting/tests/test_table_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,35 +128,39 @@ def test_duration(df_module):


@pytest.mark.parametrize("filename_type", ["str", "Path", "file_object"])
def test_write_html(pd_module, filename_path):
def test_write_html(pd_module, filename_type):
df = pd_module.make_dataframe({"a": [1, 2], "b": [3, 4]})
report = TableReport(df)

with TemporaryDirectory() as td:
f_name = Path(td) / Path("report.html")
tmp_file_path = Path(td) / Path("report.html")

if filename_path == "str":
report.write_html(f_name.absolute())
if filename_type == "str":
filename = str(tmp_file_path)
elif filename_type == "file_object":
filename = open(tmp_file_path, "w", encoding="utf-8")
else:
filename = tmp_file_path

if filename_path == "Path":
report.write_html(f_name)

if filename_path == "file_object":
file_object = open(f_name, "w", encoding="utf-8")
report.write_html(file_object)

assert f_name.exists()
report.write_html(filename)
assert tmp_file_path.exists()


def test_write_html_with_no_suffix(pd_module):
df = pd_module.make_dataframe({"a": [1, 2], "b": [3, 4]})
report = TableReport(df)
with TemporaryDirectory() as td:
f_name = Path(td) / Path("report")
with pytest.raises(ValueError, match="Not ending with .html"):
report.write_html(f_name)

assert not f_name.exists()
filename = Path(td) / Path("report.txt")
with pytest.raises(
ValueError,
match=(
"The filename does not end with the suffix `.html`. "
f"Instead, got {filename.suffix}"
),
):
report.write_html(filename)

assert not filename.exists()


def test_verbosity_parameter(df_module, capsys):
Expand Down

0 comments on commit 0debd0b

Please sign in to comment.