Skip to content

Commit 55b0723

Browse files
committed
Add targeted failure and tests for empty and null inputs
1 parent ab6c413 commit 55b0723

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

edtf/parser/grammar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ def f(toks):
346346
def parse_edtf(input_string, parseAll=True, fail_silently=False, debug=None):
347347
if debug is None:
348348
debug = DEBUG_PYPARSING
349+
if not input_string:
350+
raise EDTFParseException("You must supply some input text")
349351
try:
350-
if not input_string:
351-
raise ParseException("You must supply some input text")
352352
p = edtfParser.parseString(input_string.strip(), parseAll)
353353
if p:
354354
return p[0]

edtf/parser/tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,14 @@ def test_non_parsing(bad_input):
347347
parse(bad_input)
348348

349349

350+
@pytest.mark.parametrize("bad_input", [None, ""])
351+
def test_empty_input(bad_input):
352+
"""Test that empty input raises a specific exception."""
353+
with pytest.raises(EDTFParseException) as exc_info:
354+
parse(bad_input)
355+
assert "You must supply some input text" in str(exc_info.value)
356+
357+
350358
def test_comparisons():
351359
"""Test comparisons between parsed EDTF objects and standard dates."""
352360
d1 = parse("1979-08~")

0 commit comments

Comments
 (0)