Skip to content

Commit 72f1a5f

Browse files
tommyoddafeda
authored andcommitted
Add test of function that checks for merged cells
1 parent 0b1d466 commit 72f1a5f

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

tests/fmudesign/test_excel2dict.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import os
44

55
import numpy as np
6+
import openpyxl
67
import pandas as pd
78
import pytest
89

910
from semeio.fmudesign import excel2dict_design, inputdict_to_yaml
10-
from semeio.fmudesign._excel2dict import _has_value
11+
from semeio.fmudesign._excel2dict import _assert_no_merged_cells, _has_value
1112

1213
MOCK_GENERAL_INPUT = pd.DataFrame(
1314
data=[
@@ -226,3 +227,24 @@ def test_background_sheet(tmpdir, monkeypatch):
226227
]
227228
assert dict_design["repeats"] == 3
228229
assert dict_design["defaultvalues"]["extraseed"] == 0
230+
231+
232+
def test_assert_no_merged_cells(tmpdir, monkeypatch):
233+
"""Test that assert_no_merged_cells detects merged cells"""
234+
monkeypatch.chdir(tmpdir)
235+
236+
# Create Excel file with merged cells
237+
test_data = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
238+
writer = pd.ExcelWriter("test_file.xlsx", engine="openpyxl")
239+
test_data.to_excel(writer, sheet_name="sheet1", index=False)
240+
writer.close()
241+
242+
# Add merged cells
243+
workbook = openpyxl.load_workbook("test_file.xlsx")
244+
workbook["sheet1"].merge_cells("A1:B1")
245+
workbook.save("test_file.xlsx")
246+
workbook.close()
247+
248+
# Should raise exception
249+
with pytest.raises(Exception, match="Merged cells"):
250+
_assert_no_merged_cells("test_file.xlsx")

0 commit comments

Comments
 (0)