test_easter.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. from dateutil.easter import easter
  2. from dateutil.easter import EASTER_WESTERN, EASTER_ORTHODOX, EASTER_JULIAN
  3. from datetime import date
  4. import pytest
  5. # List of easters between 1990 and 2050
  6. western_easter_dates = [
  7. date(1990, 4, 15), date(1991, 3, 31), date(1992, 4, 19), date(1993, 4, 11),
  8. date(1994, 4, 3), date(1995, 4, 16), date(1996, 4, 7), date(1997, 3, 30),
  9. date(1998, 4, 12), date(1999, 4, 4),
  10. date(2000, 4, 23), date(2001, 4, 15), date(2002, 3, 31), date(2003, 4, 20),
  11. date(2004, 4, 11), date(2005, 3, 27), date(2006, 4, 16), date(2007, 4, 8),
  12. date(2008, 3, 23), date(2009, 4, 12),
  13. date(2010, 4, 4), date(2011, 4, 24), date(2012, 4, 8), date(2013, 3, 31),
  14. date(2014, 4, 20), date(2015, 4, 5), date(2016, 3, 27), date(2017, 4, 16),
  15. date(2018, 4, 1), date(2019, 4, 21),
  16. date(2020, 4, 12), date(2021, 4, 4), date(2022, 4, 17), date(2023, 4, 9),
  17. date(2024, 3, 31), date(2025, 4, 20), date(2026, 4, 5), date(2027, 3, 28),
  18. date(2028, 4, 16), date(2029, 4, 1),
  19. date(2030, 4, 21), date(2031, 4, 13), date(2032, 3, 28), date(2033, 4, 17),
  20. date(2034, 4, 9), date(2035, 3, 25), date(2036, 4, 13), date(2037, 4, 5),
  21. date(2038, 4, 25), date(2039, 4, 10),
  22. date(2040, 4, 1), date(2041, 4, 21), date(2042, 4, 6), date(2043, 3, 29),
  23. date(2044, 4, 17), date(2045, 4, 9), date(2046, 3, 25), date(2047, 4, 14),
  24. date(2048, 4, 5), date(2049, 4, 18), date(2050, 4, 10)
  25. ]
  26. orthodox_easter_dates = [
  27. date(1990, 4, 15), date(1991, 4, 7), date(1992, 4, 26), date(1993, 4, 18),
  28. date(1994, 5, 1), date(1995, 4, 23), date(1996, 4, 14), date(1997, 4, 27),
  29. date(1998, 4, 19), date(1999, 4, 11),
  30. date(2000, 4, 30), date(2001, 4, 15), date(2002, 5, 5), date(2003, 4, 27),
  31. date(2004, 4, 11), date(2005, 5, 1), date(2006, 4, 23), date(2007, 4, 8),
  32. date(2008, 4, 27), date(2009, 4, 19),
  33. date(2010, 4, 4), date(2011, 4, 24), date(2012, 4, 15), date(2013, 5, 5),
  34. date(2014, 4, 20), date(2015, 4, 12), date(2016, 5, 1), date(2017, 4, 16),
  35. date(2018, 4, 8), date(2019, 4, 28),
  36. date(2020, 4, 19), date(2021, 5, 2), date(2022, 4, 24), date(2023, 4, 16),
  37. date(2024, 5, 5), date(2025, 4, 20), date(2026, 4, 12), date(2027, 5, 2),
  38. date(2028, 4, 16), date(2029, 4, 8),
  39. date(2030, 4, 28), date(2031, 4, 13), date(2032, 5, 2), date(2033, 4, 24),
  40. date(2034, 4, 9), date(2035, 4, 29), date(2036, 4, 20), date(2037, 4, 5),
  41. date(2038, 4, 25), date(2039, 4, 17),
  42. date(2040, 5, 6), date(2041, 4, 21), date(2042, 4, 13), date(2043, 5, 3),
  43. date(2044, 4, 24), date(2045, 4, 9), date(2046, 4, 29), date(2047, 4, 21),
  44. date(2048, 4, 5), date(2049, 4, 25), date(2050, 4, 17)
  45. ]
  46. # A random smattering of Julian dates.
  47. # Pulled values from http://www.kevinlaughery.com/east4099.html
  48. julian_easter_dates = [
  49. date( 326, 4, 3), date( 375, 4, 5), date( 492, 4, 5), date( 552, 3, 31),
  50. date( 562, 4, 9), date( 569, 4, 21), date( 597, 4, 14), date( 621, 4, 19),
  51. date( 636, 3, 31), date( 655, 3, 29), date( 700, 4, 11), date( 725, 4, 8),
  52. date( 750, 3, 29), date( 782, 4, 7), date( 835, 4, 18), date( 849, 4, 14),
  53. date( 867, 3, 30), date( 890, 4, 12), date( 922, 4, 21), date( 934, 4, 6),
  54. date(1049, 3, 26), date(1058, 4, 19), date(1113, 4, 6), date(1119, 3, 30),
  55. date(1242, 4, 20), date(1255, 3, 28), date(1257, 4, 8), date(1258, 3, 24),
  56. date(1261, 4, 24), date(1278, 4, 17), date(1333, 4, 4), date(1351, 4, 17),
  57. date(1371, 4, 6), date(1391, 3, 26), date(1402, 3, 26), date(1412, 4, 3),
  58. date(1439, 4, 5), date(1445, 3, 28), date(1531, 4, 9), date(1555, 4, 14)
  59. ]
  60. @pytest.mark.parametrize("easter_date", western_easter_dates)
  61. def test_easter_western(easter_date):
  62. assert easter_date == easter(easter_date.year, EASTER_WESTERN)
  63. @pytest.mark.parametrize("easter_date", orthodox_easter_dates)
  64. def test_easter_orthodox(easter_date):
  65. assert easter_date == easter(easter_date.year, EASTER_ORTHODOX)
  66. @pytest.mark.parametrize("easter_date", julian_easter_dates)
  67. def test_easter_julian(easter_date):
  68. assert easter_date == easter(easter_date.year, EASTER_JULIAN)
  69. def test_easter_bad_method():
  70. with pytest.raises(ValueError):
  71. easter(1975, 4)