Skip to content

Commit 7eac2a1

Browse files
committed
Change exception throwing of the sanitize_excel_sheet_name function
1 parent e9e6c5b commit 7eac2a1

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

pathvalidate/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,14 @@ def sanitize_excel_sheet_name(sheet_name, replacement_text=""):
221221
:param str replacement_text: Replacement text.
222222
:return: A replacement string.
223223
:rtype: str
224+
:raises ValueError: If the ``sheet_name`` is a invalid sheet name.
224225
"""
225226

226-
return __RE_INVALID_EXCEL_SHEET_NAME.sub(
227-
replacement_text, sheet_name.strip())
227+
try:
228+
return __RE_INVALID_EXCEL_SHEET_NAME.sub(
229+
replacement_text, sheet_name.strip())
230+
except AttributeError as e:
231+
raise ValueError(e)
228232

229233

230234
def replace_symbol(text, replacement_text=""):

test/test_pathvalidate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,9 @@ def test_normal(self, value, replace_text, expected):
345345
validate_excel_sheet_name(sanitized_name)
346346

347347
@pytest.mark.parametrize(["value", "expected"], [
348-
[None, AttributeError],
349-
[1, AttributeError],
350-
[True, AttributeError],
348+
[None, ValueError],
349+
[1, ValueError],
350+
[True, ValueError],
351351
])
352352
def test_exception_type(self, value, expected):
353353
with pytest.raises(expected):

0 commit comments

Comments
 (0)