Skip to content

Commit

Permalink
Pydantic v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Benyamin Ginzburg committed Oct 22, 2023
1 parent 878a086 commit 881f094
Show file tree
Hide file tree
Showing 14 changed files with 657 additions and 133 deletions.
519 changes: 519 additions & 0 deletions pdm.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ authors = [
{name = "Benyamin Ginzburg", email = "[email protected]"},
]
dependencies = [
"fastapi==0.95.0",
"pydantic==1.10.7",
"uvicorn==0.21.1",
"pytz==2023.3",
"fastapi==0.104.0",
"pydantic==2.4.2",
"uvicorn==0.23.2",
"arrow==1.2.3",
"timezonefinder==6.2.0",
"zmanim==0.3.1",
"betterlogging==0.2.1",
"sentry-sdk==1.19.1",
"sentry-sdk==1.32.0",
"tzdata"
]
requires-python = ">=3.11,<3.12"
readme = "README.md"
Expand All @@ -25,8 +25,8 @@ license = {text = "GPL-3.0"}

[tool.pdm.dev-dependencies]
test = [
"pytest==7.3.0",
"httpx==0.24.0",
"pytest==7.4.2",
"httpx==0.25.0",
"coverage==7.2.3",
]

Expand Down
Empty file removed src/example_package/__init__.py
Empty file.
14 changes: 7 additions & 7 deletions test/test_engine/test_fasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_regular_fast():
LNG,
ZERO_ELEVATION
)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_moved_fast_esther():
Expand All @@ -53,7 +53,7 @@ def test_moved_fast_esther():
LNG,
ZERO_ELEVATION
)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_moved_fast_tammuz_and_av():
Expand Down Expand Up @@ -100,8 +100,8 @@ def test_moved_fast_tammuz_and_av():
ZERO_ELEVATION,
)

assert actual_1.dict(exclude_none=True, by_alias=True) == expected_1
assert actual_2.dict(exclude_none=True, by_alias=True) == expected_2
assert actual_1.model_dump(exclude_none=True, by_alias=True) == expected_1
assert actual_2.model_dump(exclude_none=True, by_alias=True) == expected_2


def test_day_after_moved_fast_tammuz_and_av():
Expand Down Expand Up @@ -147,8 +147,8 @@ def test_day_after_moved_fast_tammuz_and_av():
ZERO_ELEVATION,
)

assert actual_1.dict(exclude_none=True, by_alias=True) == expected_1
assert actual_2.dict(exclude_none=True, by_alias=True) == expected_2
assert actual_1.model_dump(exclude_none=True, by_alias=True) == expected_1
assert actual_2.model_dump(exclude_none=True, by_alias=True) == expected_2


def test_9_of_av_in_north():
Expand All @@ -170,5 +170,5 @@ def test_9_of_av_in_north():
63.44563381372263,
13.49966869597185,
ZERO_ELEVATION,
).dict(exclude_none=True, by_alias=True)
).model_dump(exclude_none=True, by_alias=True)
assert actual == expected
26 changes: 13 additions & 13 deletions test/test_engine/test_holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_regular_holiday():
}

actual = get_simple_holiday(SimpleHolidayChoices.tu_bi_shvat.value, PY_DATE)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_yom_hashoah():
Expand All @@ -28,7 +28,7 @@ def test_yom_hashoah():
}

actual = get_simple_holiday(SimpleHolidayChoices.yom_hashoah.value, PY_DATE)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_yom_hashoah_on_friday():
Expand All @@ -41,7 +41,7 @@ def test_yom_hashoah_on_friday():
}

actual = get_simple_holiday(SimpleHolidayChoices.yom_hashoah.value, date(2021, 4, 1))
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_yom_hashoah_on_sunday():
Expand All @@ -54,7 +54,7 @@ def test_yom_hashoah_on_sunday():
}

actual = get_simple_holiday(SimpleHolidayChoices.yom_hashoah.value, date(2024, 4, 1))
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_yom_hazikaron():
Expand All @@ -67,7 +67,7 @@ def test_yom_hazikaron():
}

actual = get_simple_holiday(SimpleHolidayChoices.yom_hazikaron.value, PY_DATE)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_yom_hazikaron_friday_yom_haatzmaut_shabbat():
Expand All @@ -88,8 +88,8 @@ def test_yom_hazikaron_friday_yom_haatzmaut_shabbat():

actual_1 = get_simple_holiday(SimpleHolidayChoices.yom_hazikaron.value, date(2021, 4, 1))
actual_2 = get_simple_holiday(SimpleHolidayChoices.yom_haatzmaut.value, date(2021, 4, 1))
assert actual_1.dict(exclude_none=True, by_alias=True) == expected_1
assert actual_2.dict(exclude_none=True, by_alias=True) == expected_2
assert actual_1.model_dump(exclude_none=True, by_alias=True) == expected_1
assert actual_2.model_dump(exclude_none=True, by_alias=True) == expected_2


def test_yom_hazikaron_shabbat_yom_haatzmaut_sunday():
Expand All @@ -110,8 +110,8 @@ def test_yom_hazikaron_shabbat_yom_haatzmaut_sunday():

actual_1 = get_simple_holiday(SimpleHolidayChoices.yom_hazikaron.value, date(2024, 4, 1))
actual_2 = get_simple_holiday(SimpleHolidayChoices.yom_haatzmaut.value, date(2024, 4, 1))
assert actual_1.dict(exclude_none=True, by_alias=True) == expected_1
assert actual_2.dict(exclude_none=True, by_alias=True) == expected_2
assert actual_1.model_dump(exclude_none=True, by_alias=True) == expected_1
assert actual_2.model_dump(exclude_none=True, by_alias=True) == expected_2


def test_yom_hazikaron_wednesdey_yom_haatzmaut_thursday():
Expand All @@ -132,8 +132,8 @@ def test_yom_hazikaron_wednesdey_yom_haatzmaut_thursday():

actual_1 = get_simple_holiday(SimpleHolidayChoices.yom_hazikaron.value, date(2022, 4, 1))
actual_2 = get_simple_holiday(SimpleHolidayChoices.yom_haatzmaut.value, date(2022, 4, 1))
assert actual_1.dict(exclude_none=True, by_alias=True) == expected_1
assert actual_2.dict(exclude_none=True, by_alias=True) == expected_2
assert actual_1.model_dump(exclude_none=True, by_alias=True) == expected_1
assert actual_2.model_dump(exclude_none=True, by_alias=True) == expected_2


def test_holiday_ducing_holiday():
Expand All @@ -145,7 +145,7 @@ def test_holiday_ducing_holiday():
'date': date.fromisoformat('2021-11-29')
}

actual = get_simple_holiday(SimpleHolidayChoices.chanukah.value, date(2021, 12, 1)).dict(exclude_none=True, by_alias=True)
actual = get_simple_holiday(SimpleHolidayChoices.chanukah.value, date(2021, 12, 1)).model_dump(exclude_none=True, by_alias=True)
assert actual == expected


Expand All @@ -157,5 +157,5 @@ def test_purim_on_first_adar():
},
'date': date.fromisoformat('2022-03-17')
}
actual = get_simple_holiday(SimpleHolidayChoices.purim.value, date(2022, 3, 2)).dict(exclude_none=True, by_alias=True)
actual = get_simple_holiday(SimpleHolidayChoices.purim.value, date(2022, 3, 2)).model_dump(exclude_none=True, by_alias=True)
assert actual == expected
12 changes: 6 additions & 6 deletions test/test_engine/test_rosh_chodesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def test_regular_rosh_chodesh():
'month_name': 'iyar',
'days': [date.fromisoformat('2020-04-24'), date.fromisoformat('2020-04-25')],
'duration': 2,
'molad': (dt.fromisoformat('2020-04-22T22:58'), 12)
'molad': ('2020-04-22T22:58', 12)
}

actual = get_next_rosh_chodesh(PY_DATE)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_rosh_chodesh_during_rosh_chodesh():
Expand All @@ -23,11 +23,11 @@ def test_rosh_chodesh_during_rosh_chodesh():
'month_name': 'iyar',
'days': [date.fromisoformat('2020-04-24'), date.fromisoformat('2020-04-25')],
'duration': 2,
'molad': (dt.fromisoformat('2020-04-22T22:58'), 12)
'molad': ('2020-04-22T22:58', 12)
}

actual = get_next_rosh_chodesh(date(2020, 4, 25))
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_rosh_chodesh_before_rosh_hashana():
Expand All @@ -36,8 +36,8 @@ def test_rosh_chodesh_before_rosh_hashana():
'month_name': 'cheshvan',
'days': [date.fromisoformat('2020-10-18'), date.fromisoformat('2020-10-19')],
'duration': 2,
'molad': (dt.fromisoformat('2020-10-17T03:23'), 0)
'molad': ('2020-10-17T03:23', 0)
}

actual = get_next_rosh_chodesh(date(2020, 9, 1))
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected
18 changes: 9 additions & 9 deletions test/test_engine/test_shabbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_regular_shabbat():
}

resp = get_shabbat(LAT, LNG, ZERO_ELEVATION, CL_OFFSET, HavdalaChoices.tzeis_8_5_degrees, PY_DATE)
assert resp.dict(exclude_none=True, by_alias=True) == expected
assert resp.model_dump(exclude_none=True, by_alias=True) == expected


def test_shabbat_with_late_cl_warning():
Expand All @@ -41,7 +41,7 @@ def test_shabbat_with_late_cl_warning():

resp = get_shabbat(55.5, 37.7, ZERO_ELEVATION, CL_OFFSET, HavdalaChoices.tzeis_8_5_degrees,
date(2020, 6, 15))
assert resp.dict(exclude_none=True, by_alias=True) == expected
assert resp.model_dump(exclude_none=True, by_alias=True) == expected


def test_shabbat_with_tzeit_by_chatzot_layla():
Expand All @@ -61,7 +61,7 @@ def test_shabbat_with_tzeit_by_chatzot_layla():

resp = get_shabbat(69.77, 25.01, ZERO_ELEVATION, CL_OFFSET, HavdalaChoices.tzeis_8_5_degrees,
date(2021, 7, 24))
assert resp.dict(exclude_none=True, by_alias=True) == expected
assert resp.model_dump(exclude_none=True, by_alias=True) == expected


def test_shabbat_with_polar_daynight():
Expand All @@ -79,7 +79,7 @@ def test_shabbat_with_polar_daynight():

resp = get_shabbat(76.60, 103.45, ZERO_ELEVATION, CL_OFFSET, HavdalaChoices.tzeis_8_5_degrees,
date(2021, 7, 25))
assert resp.dict(exclude_none=True, by_alias=True) == expected
assert resp.model_dump(exclude_none=True, by_alias=True) == expected


def test_shabbat_with_different_parsha():
Expand Down Expand Up @@ -113,8 +113,8 @@ def test_shabbat_with_different_parsha():
resp_1 = get_shabbat(LAT, LNG, ZERO_ELEVATION, CL_OFFSET, HavdalaChoices.tzeis_8_5_degrees, date.fromisoformat('2020-05-30'))
resp_2 = get_shabbat(37.7, LNG, ZERO_ELEVATION, CL_OFFSET, HavdalaChoices.tzeis_8_5_degrees, date.fromisoformat('2020-05-30'))

assert resp_1.dict(exclude_none=True, by_alias=True) == expected_1
assert resp_2.dict(exclude_none=True, by_alias=True) == expected_2
assert resp_1.model_dump(exclude_none=True, by_alias=True) == expected_1
assert resp_2.model_dump(exclude_none=True, by_alias=True) == expected_2


def test_shabbat_with_yomtov():
Expand Down Expand Up @@ -162,6 +162,6 @@ def test_shabbat_with_yomtov():
resp_2 = get_shabbat(37.7, LNG, ZERO_ELEVATION, CL_OFFSET, HavdalaChoices.tzeis_8_5_degrees, date.fromisoformat('2020-05-29'))
resp_3 = get_shabbat(37.7, LNG, ZERO_ELEVATION, CL_OFFSET, HavdalaChoices.tzeis_8_5_degrees, date.fromisoformat('2020-04-10'))

assert resp_1.dict(exclude_none=True, by_alias=True) == expected_1
assert resp_2.dict(exclude_none=True, by_alias=True) == expected_2
assert resp_3.dict(exclude_none=True, by_alias=True) == expected_3
assert resp_1.model_dump(exclude_none=True, by_alias=True) == expected_1
assert resp_2.model_dump(exclude_none=True, by_alias=True) == expected_2
assert resp_3.model_dump(exclude_none=True, by_alias=True) == expected_3
20 changes: 10 additions & 10 deletions test/test_engine/test_yomtov.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_regular_yomtov_in_istael():
18,
HavdalaChoices.tzeis_8_5_degrees
)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_regular_yomtov_in_diaspora():
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_regular_yomtov_in_diaspora():
18,
HavdalaChoices.tzeis_8_5_degrees
)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_past_yomtov():
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_past_yomtov():
18,
HavdalaChoices.tzeis_8_5_degrees
)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_rosh_hashana_in_diaspora():
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_rosh_hashana_in_diaspora():
18,
HavdalaChoices.tzeis_8_5_degrees
)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_pre_shabbat_in_israel():
Expand Down Expand Up @@ -160,7 +160,7 @@ def test_pre_shabbat_in_israel():
18,
HavdalaChoices.tzeis_8_5_degrees
)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_pre_shabbat_in_diaspora():
Expand Down Expand Up @@ -197,7 +197,7 @@ def test_pre_shabbat_in_diaspora():
18,
HavdalaChoices.tzeis_8_5_degrees
)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_post_shabbat_in_israel():
Expand Down Expand Up @@ -230,7 +230,7 @@ def test_post_shabbat_in_israel():
18,
HavdalaChoices.tzeis_8_5_degrees
)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_post_shabbat_in_diaspora():
Expand Down Expand Up @@ -278,7 +278,7 @@ def test_post_shabbat_in_diaspora():
18,
HavdalaChoices.tzeis_8_5_degrees
)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_second_yt_is_shabbat():
Expand Down Expand Up @@ -322,7 +322,7 @@ def test_second_yt_is_shabbat():
18,
HavdalaChoices.tzeis_8_5_degrees
)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected


def test_peesach_part_2_post_shabbat_in_istael():
Expand Down Expand Up @@ -362,4 +362,4 @@ def test_peesach_part_2_post_shabbat_in_istael():
18,
HavdalaChoices.tzeis_8_5_degrees
)
assert actual.dict(exclude_none=True, by_alias=True) == expected
assert actual.model_dump(exclude_none=True, by_alias=True) == expected
9 changes: 2 additions & 7 deletions test/test_routers/test_main_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,14 @@ def test_shabbat_endpoint():
def test_rosh_chodesh_endpoint():
params = {'date': DATE}
expected = {
'settings': {
'date': '2020-04-15'
},
'settings': {'date': '2020-04-15'},
'month_name': 'iyar',
'days': [
'2020-04-24',
'2020-04-25'
],
'duration': 2,
'molad': [
'2020-04-22T22:58',
12
]
'molad': ['2020-04-22T22:58', 12]
}

resp = client.get('/rosh_chodesh', params=params)
Expand Down
Loading

0 comments on commit 881f094

Please sign in to comment.