Skip to content

Commit 35b0d1d

Browse files
authored
TST: Increase test coverage for pandas.io.formats.excel.py (#61697)
* Added coverage 314-349 and change in excel.py * Adding further coverage for excel.py * Whitespace changes (whoops) * Whitespace changes (whoops) * Update .gitignore * Update test_common.py
1 parent 09f7cc0 commit 35b0d1d

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

pandas/io/formats/excel.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@ def _border_style(
303303
# 'slantDashDot'
304304
# 'thick'
305305
# 'thin'
306-
if width is None and style is None and color is None:
307-
# Return None will remove "border" from style dictionary
308-
return None
309-
310306
if width is None and style is None:
311-
# Return "none" will keep "border" in style dictionary
312-
return "none"
307+
if color is None:
308+
# Return None will remove "border" from style dictionary
309+
return None
310+
else:
311+
# Return "none" will keep "border" in style dictionary
312+
return "none"
313313

314314
if style in ("none", "hidden"):
315315
return "none"
@@ -411,11 +411,6 @@ def _get_decoration(self, props: Mapping[str, str]) -> Sequence[str]:
411411
else:
412412
return ()
413413

414-
def _get_underline(self, decoration: Sequence[str]) -> str | None:
415-
if "underline" in decoration:
416-
return "single"
417-
return None
418-
419414
def _get_shadow(self, props: Mapping[str, str]) -> bool | None:
420415
if "text-shadow" in props:
421416
return bool(re.search("^[^#(]*[1-9]", props["text-shadow"]))

pandas/tests/io/formats/test_to_excel.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@
156156
"border-top-style: solid; border-top-width: 4pt",
157157
{"border": {"top": {"style": "thick"}}},
158158
),
159+
(
160+
"border-top-style: solid; border-top-width: none",
161+
{"border": {"top": {"style": "none"}}},
162+
),
163+
(
164+
"border-top-style: solid; border-top-width: 0.000001pt",
165+
{"border": {"top": {"style": "none"}}},
166+
),
159167
(
160168
"border-top-style: dotted",
161169
{"border": {"top": {"style": "mediumDashDotDot"}}},
@@ -194,6 +202,10 @@
194202
"border-top-color: blue",
195203
{"border": {"top": {"color": "0000FF", "style": "none"}}},
196204
),
205+
(
206+
"border-top-style: slantDashDot; border-top-color: blue",
207+
{"border": {"top": {"style": "slantDashDot", "color": "0000FF"}}},
208+
),
197209
# ALIGNMENT
198210
# - horizontal
199211
("text-align: center", {"alignment": {"horizontal": "center"}}),
@@ -249,6 +261,20 @@ def test_css_to_excel_multiple():
249261
} == actual
250262

251263

264+
@pytest.mark.parametrize(
265+
"css",
266+
[
267+
"border-top-style: unhandled-border-style",
268+
"border-style: another-unhandled-style",
269+
],
270+
)
271+
def test_css_to_excel_unhandled_border_style_warns(css):
272+
"""Test that unhandled border styles raise a CSSWarning."""
273+
convert = CSSToExcelConverter()
274+
with tm.assert_produces_warning(CSSWarning, match="Unhandled border style format"):
275+
convert(css)
276+
277+
252278
@pytest.mark.parametrize(
253279
"css,inherited,expected",
254280
[
@@ -330,6 +356,23 @@ def test_css_to_excel_bad_colors(input_color):
330356
assert expected == convert(css)
331357

332358

359+
@pytest.mark.parametrize("input_color", ["#", "#1234567"])
360+
def test_css_to_excel_invalid_color_raises(input_color):
361+
"""Test that invalid colors raise a ValueError."""
362+
css = (
363+
f"border-top-color: {input_color}; "
364+
f"border-right-color: {input_color}; "
365+
f"border-bottom-color: {input_color}; "
366+
f"border-left-color: {input_color}; "
367+
f"background-color: {input_color}; "
368+
f"color: {input_color}"
369+
)
370+
371+
convert = CSSToExcelConverter()
372+
with pytest.raises(ValueError, match=f"Unexpected color {input_color}"):
373+
convert(css)
374+
375+
333376
def tests_css_named_colors_valid():
334377
upper_hexs = set(map(str.upper, string.hexdigits))
335378
for color in CSSToExcelConverter.NAMED_COLORS.values():

0 commit comments

Comments
 (0)