Skip to content

Commit

Permalink
Test exceptions and parser type errors more specific
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Dec 6, 2024
1 parent f908cd5 commit c24cd34
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ def test_parse_error(self):
with pytest.raises(ValueError):
HebrewDateConverter().parse("")

# non-string input should raise a type error
with pytest.raises(TypeError):
HebrewDateConverter().parse(42)

with pytest.raises(TypeError):
HebrewDateConverter().parse({"foo": "bar"})

def test_partially_known(self):
# hebrew dates get existing partially unknown behavior

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pytest
from lark.exceptions import UnexpectedCharacters, UnexpectedEOF

from undate.converters.calendars.hebrew.parser import hebrew_parser


Expand Down Expand Up @@ -41,23 +43,23 @@ def test_should_parse(date_string):

error_cases = [
# invalid days
"0 Tammuz 5403",
"31 Tishri 5403",
("0 Tammuz 5403", UnexpectedCharacters),
("31 Tishri 5403", UnexpectedCharacters),
# month alone
"Tishri",
("Tishri", UnexpectedEOF),
# month day only
"12 Heshvan",
("12 Heshvan", UnexpectedEOF),
# invalid month
"Foo 383",
("Foo 383", UnexpectedCharacters),
# wrong format
"2024-10-02",
("2024-10-02", UnexpectedCharacters),
# year month day not supported
"5403 Adar",
"5403 Adar 14",
("5403 Adar", UnexpectedCharacters),
("5403 Adar 14", UnexpectedCharacters),
]


@pytest.mark.parametrize("date_string", error_cases)
def test_should_error(date_string):
with pytest.raises(Exception):
@pytest.mark.parametrize("date_string,exception", error_cases)
def test_should_error(date_string, exception):
with pytest.raises(exception):
hebrew_parser.parse(date_string)

0 comments on commit c24cd34

Please sign in to comment.