Skip to content

Commit b00e82e

Browse files
Revert empty filename check when extracting text
1 parent 32cfc58 commit b00e82e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

cardinal_pythonlib/extract_text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def get_filelikeobject(filename: str = None, blob: bytes = None) -> BinaryIO:
358358
Returns:
359359
a :class:`BinaryIO` object
360360
"""
361-
if filename is None and blob is None:
361+
if not filename and blob is None:
362362
raise ValueError("no filename and no blob")
363363
if filename and blob:
364364
raise ValueError("specify either filename or blob")
@@ -1425,7 +1425,7 @@ def document_to_text(
14251425
Raises an exception for malformed arguments, missing files, bad
14261426
filetypes, etc.
14271427
"""
1428-
if filename is None and blob is None:
1428+
if not filename and blob is None:
14291429
raise ValueError("document_to_text: no filename and no blob")
14301430
if filename and blob:
14311431
raise ValueError("document_to_text: specify either filename or blob")

cardinal_pythonlib/tests/extract_text_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ def test_raises_when_no_filename_or_blob(self) -> None:
101101

102102
self.assertIn("no filename and no blob", str(cm.exception))
103103

104+
def test_raises_when_filename_empty(self) -> None:
105+
with self.assertRaises(ValueError) as cm:
106+
document_to_text(filename="")
107+
108+
self.assertIn("no filename and no blob", str(cm.exception))
109+
104110
def test_raises_when_filename_and_blob(self) -> None:
105111
with self.assertRaises(ValueError) as cm:
106112
document_to_text(filename="foo", blob="bar")

0 commit comments

Comments
 (0)