Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions test/test_hebrew_date_formatter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"""Test formatting of the hebrew date"""

import unittest
from datetime import datetime as dt

from zmanim.hebrew_calendar.hebrew_date_formatter import HebrewDateFormatter
from zmanim.hebrew_calendar.jewish_calendar import JewishCalendar


class TestHebrewDateFormatter(unittest.TestCase):
def formatting_tests(self):
return (
(dt(2019, 4, 8), u"ג' ניסן ה' תשע\"ט", "3 Nissan, 5779"),
(dt(2019, 4, 1), u"כ\"ה אדר ב' ה' תשע\"ט", "25 Adar II, 5779"),
(dt(2019, 3, 1), u"כ\"ד אדר א' ה' תשע\"ט", "24 Adar I, 5779"),
)

def number_tests(self):
return (
(0, u"אפס", u"אפס"),
(1, u"א'", u"א"),
(15, u"ט\"ו", u"טו"),
(16, u"ט\"ז", u"טז"),
(20, u"כ'", u"כ"),
(120, u"ק\"ך", u"קך"),
(1000, u"א' אלפים", u"א אלפים"),
(5780, u"ה' תש\"ף", u"ה תשף")
)

def omer_tests(self):
return (
(dt(2019, 4, 29), u"ט' בעומר", "Omer 9"),
(dt(2019, 4, 1), u"", ""),
(dt(2019, 5, 23), u"ל\"ג בעומר", "Lag BaOmer"),
)

def yom_tov_tests(self):
return (
(dt(2019, 4, 1), u"", ""),
(dt(2019, 4, 26), u"פסח", "Pesach"),
(dt(2018, 12, 3), u"א' חנוכה", "Chanukah 1"),
)

def testFormatHebrew(self):
"""Test JewishDate with formatter set to Hebrew"""
formatter = HebrewDateFormatter(hebrew_format=True)
for case in self.formatting_tests():
actual = formatter.format(JewishCalendar(case[0]))
self.assertEqual(actual, case[1])

def testFormatEnglish(self):
"""Test JewishDate with formatter set to English"""
formatter = HebrewDateFormatter(hebrew_format=False)
for case in self.formatting_tests():
actual = formatter.format(JewishCalendar(case[0]))
self.assertEqual(actual, case[2])

def testFormatNumber(self):
"""Test numbers formatting with geresh"""
formatter = HebrewDateFormatter()
for case in self.number_tests():
actual = formatter.format_hebrew_number(case[0])
self.assertEqual(actual, case[1])

def testFormatNumberNoGereshGershayim(self):
"""Test numbers formatting without geresh"""
formatter = HebrewDateFormatter(use_geresh_gershayim=False)
for case in self.number_tests():
actual = formatter.format_hebrew_number(case[0])
self.assertEqual(actual, case[2])

def testFormatNumberOutOfBounds(self):
"""Check for out of bounds number formatting"""
formatter = HebrewDateFormatter()
for number in [-1, 10000, 99999]:
self.assertRaises(
ValueError, formatter.format_hebrew_number, number)

def testFormatOmerHebrew(self):
"""Test Omer count in Hebrew"""
formatter = HebrewDateFormatter(hebrew_format=True)
for case in self.omer_tests():
actual = formatter.format_omer(JewishCalendar(case[0]))
self.assertEqual(actual, case[1])

def testFormatOmerEnglish(self):
"""Test Omer count in English"""
formatter = HebrewDateFormatter(hebrew_format=False)
for case in self.omer_tests():
actual = formatter.format_omer(JewishCalendar(case[0]))
self.assertEqual(actual, case[2])

def testFormatYomTovHebrew(self):
"""Test Yom Tov in Hebrew"""
formatter = HebrewDateFormatter(hebrew_format=True)
for case in self.yom_tov_tests():
actual = formatter.format_yom_tov(JewishCalendar(case[0]))
self.assertEqual(actual, case[1])

def testFormatYomTovEnglish(self):
"""Test YomTov in English"""
formatter = HebrewDateFormatter(hebrew_format=False)
for case in self.yom_tov_tests():
actual = formatter.format_yom_tov(JewishCalendar(case[0]))
self.assertEqual(actual, case[2])
38 changes: 19 additions & 19 deletions test/test_jewish_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def chanukah_for_chaseirim(self):
def leap_purim(self):
return {'purim_katan': ['12-14'],
'shushan_purim_katan': ['12-15'],
'taanis_esther': ['13-13'],
'fast_of_esther': ['13-13'],
'purim': ['13-14'],
'shushan_purim': ['13-15']}

Expand All @@ -50,7 +50,7 @@ def standard_significant_days(self):
'tu_beav': ['5-15'],
'erev_rosh_hashana': ['6-29'],
'rosh_hashana': ['7-1', '7-2'],
'tzom_gedalyah': ['7-3'],
'fast_of_gedalyah': ['7-3'],
'erev_yom_kippur': ['7-9'],
'yom_kippur': ['7-10'],
'erev_succos': ['7-14'],
Expand All @@ -62,7 +62,7 @@ def standard_significant_days(self):
'chanukah': ['9-25', '9-26', '9-27', '9-28', '9-29', '9-30', '10-1', '10-2'],
'tenth_of_teves': ['10-10'],
'tu_beshvat': ['11-15'],
'taanis_esther': ['12-13'],
'fast_of_esther': ['12-13'],
'purim': ['12-14'],
'shushan_purim': ['12-15']
}
Expand Down Expand Up @@ -112,13 +112,13 @@ def test_significant_days_for_standard_monday_chaseirim(self):
result = test.test_helper.all_days_matching(year, lambda c: c.significant_day())
expected = {**self.standard_significant_days(),
'chanukah': self.chanukah_for_chaseirim(),
'taanis_esther': ['12-11']}
'fast_of_esther': ['12-11']}
self.assertEqual(result, expected)

israel_result = test.test_helper.all_days_matching(year, lambda c: c.significant_day(), in_israel=True)
expected = {**self.israel_standard_significant_days(),
'chanukah': self.chanukah_for_chaseirim(),
'taanis_esther': ['12-11']}
'fast_of_esther': ['12-11']}
self.assertEqual(israel_result, expected)

def test_significant_days_for_standard_monday_shelaimim(self):
Expand Down Expand Up @@ -148,15 +148,15 @@ def test_significant_days_for_standard_thursday_kesidran(self):

result = test.test_helper.all_days_matching(year, lambda c: c.significant_day())
expected = {**self.standard_significant_days(),
'tzom_gedalyah': ['7-4'],
'fast_of_gedalyah': ['7-4'],
'seventeen_of_tammuz': ['4-18'],
'tisha_beav': ['5-10']
}
self.assertEqual(result, expected)

israel_result = test.test_helper.all_days_matching(year, lambda c: c.significant_day(), in_israel=True)
expected = {**self.israel_standard_significant_days(),
'tzom_gedalyah': ['7-4'],
'fast_of_gedalyah': ['7-4'],
'seventeen_of_tammuz': ['4-18'],
'tisha_beav': ['5-10']
}
Expand All @@ -167,13 +167,13 @@ def test_significant_days_for_standard_thursday_shelaimim(self):

result = test.test_helper.all_days_matching(year, lambda c: c.significant_day())
expected = {**self.standard_significant_days(),
'tzom_gedalyah': ['7-4']
'fast_of_gedalyah': ['7-4']
}
self.assertEqual(result, expected)

israel_result = test.test_helper.all_days_matching(year, lambda c: c.significant_day(), in_israel=True)
expected = {**self.israel_standard_significant_days(),
'tzom_gedalyah': ['7-4']
'fast_of_gedalyah': ['7-4']
}
self.assertEqual(israel_result, expected)

Expand All @@ -197,13 +197,13 @@ def test_significant_days_for_standard_shabbos_shelaimim(self):

result = test.test_helper.all_days_matching(year, lambda c: c.significant_day())
expected = {**self.standard_significant_days(),
'taanis_esther': ['12-11']
'fast_of_esther': ['12-11']
}
self.assertEqual(result, expected)

israel_result = test.test_helper.all_days_matching(year, lambda c: c.significant_day(), in_israel=True)
expected = {**self.israel_standard_significant_days(),
'taanis_esther': ['12-11']
'fast_of_esther': ['12-11']
}
self.assertEqual(israel_result, expected)

Expand Down Expand Up @@ -261,14 +261,14 @@ def test_significant_days_for_leap_thursday_chaseirim(self):

result = test.test_helper.all_days_matching(year, lambda c: c.significant_day())
expected = {**self.leap_significant_days(),
'tzom_gedalyah': ['7-4'],
'fast_of_gedalyah': ['7-4'],
'chanukah': self.chanukah_for_chaseirim()
}
self.assertEqual(result, expected)

israel_result = test.test_helper.all_days_matching(year, lambda c: c.significant_day(), in_israel=True)
expected = {**self.israel_leap_significant_days(),
'tzom_gedalyah': ['7-4'],
'fast_of_gedalyah': ['7-4'],
'chanukah': self.chanukah_for_chaseirim()
}
self.assertEqual(israel_result, expected)
Expand All @@ -278,15 +278,15 @@ def test_significant_days_for_leap_thursday_shelaimim(self):

result = test.test_helper.all_days_matching(year, lambda c: c.significant_day())
expected = {**self.leap_significant_days(),
'tzom_gedalyah': ['7-4'],
'taanis_esther': ['13-11']
'fast_of_gedalyah': ['7-4'],
'fast_of_esther': ['13-11']
}
self.assertEqual(result, expected)

israel_result = test.test_helper.all_days_matching(year, lambda c: c.significant_day(), in_israel=True)
expected = {**self.israel_leap_significant_days(),
'tzom_gedalyah': ['7-4'],
'taanis_esther': ['13-11']
'fast_of_gedalyah': ['7-4'],
'fast_of_esther': ['13-11']
}
self.assertEqual(israel_result, expected)

Expand All @@ -296,14 +296,14 @@ def test_significant_days_for_leap_shabbos_chaseirim(self):
result = test.test_helper.all_days_matching(year, lambda c: c.significant_day())
expected = {**self.leap_significant_days(),
'chanukah': self.chanukah_for_chaseirim(),
'taanis_esther': ['13-11']
'fast_of_esther': ['13-11']
}
self.assertEqual(result, expected)

israel_result = test.test_helper.all_days_matching(year, lambda c: c.significant_day(), in_israel=True)
expected = {**self.israel_leap_significant_days(),
'chanukah': self.chanukah_for_chaseirim(),
'taanis_esther': ['13-11']
'fast_of_esther': ['13-11']
}
self.assertEqual(israel_result, expected)

Expand Down
Loading