Skip to content

Commit 65e8874

Browse files
committed
Expand test suite to cover null and empty list values in XLSXListField
1 parent 9a0f47f commit 65e8874

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test_fields.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,36 @@ def test_cell_complex_types(self, style: XLSXStyle, worksheet: Worksheet):
444444
assert isinstance(cell, Cell)
445445
assert cell.value == '[{"a": 1}, {"b": 2}]'
446446

447+
def test_cell_with_empty_list(self, style: XLSXStyle, worksheet: Worksheet):
448+
f = XLSXListField(
449+
list_sep=None,
450+
key="objs",
451+
value=[],
452+
field=ListField(),
453+
style=style,
454+
mapping="",
455+
cell_style=style,
456+
)
457+
assert f.original_value == f.value == []
458+
cell = f.cell(worksheet, 1, 1)
459+
assert isinstance(cell, Cell)
460+
assert cell.value == ""
461+
462+
def test_cell_with_null_value(self, style: XLSXStyle, worksheet: Worksheet):
463+
f = XLSXListField(
464+
list_sep=None,
465+
key="objs",
466+
value=None,
467+
field=ListField(allow_null=True),
468+
style=style,
469+
mapping="",
470+
cell_style=style,
471+
)
472+
assert f.original_value is f.value is None
473+
cell = f.cell(worksheet, 1, 1)
474+
assert isinstance(cell, Cell)
475+
assert cell.value is None
476+
447477

448478
class TestXLSXBooleanField:
449479
@pytest.mark.parametrize("value", [True, False])

0 commit comments

Comments
 (0)