Skip to content

Commit

Permalink
Merge pull request #41 from essel-dev/dev
Browse files Browse the repository at this point in the history
fix: Set Hadlokas Haneiros if after nightfall
  • Loading branch information
essel-dev authored Jul 26, 2024
2 parents 2acd9c5 + ff8c46a commit a388653
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Local Development
## Install
### Project code
```sh
cd && git clone # path-to-this-repository.git
```

### Python
Verify if Python is installed.
```sh
Expand All @@ -13,11 +18,6 @@ To activate:
pyenv local 3.10 3.11 3.12
```

### Project code
```sh
cd && git clone # path-to-this-repository.git
```

### Virtual environment
```sh
cd # path-to-downloaded-repository
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dynamic = ['version']
keywords = [
'jewish calendar',
'hebrew calendar',
'zmanim',
]
license = {file = 'LICENSE'}
name = 'jewcal'
Expand Down
2 changes: 1 addition & 1 deletion src/jewcal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(
use_tzeis_hakochavim=location.use_tzeis_hakochavim,
):
gregorian += timedelta(days=1)
self._zmanim = Zmanim(gregorian, location)
self._zmanim = Zmanim(gregorian, location, set_hadlokas_haneiros=True)

absdate = gregorian_to_absdate(gregorian.year, gregorian.month, gregorian.day)
year, month, day = absdate_to_jewish(absdate)
Expand Down
1 change: 0 additions & 1 deletion src/jewcal/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def _is_erev_yomtov(self) -> bool:
self.yomtov and 'Pesach 6' in self.yomtov,
],
),
self.action == Action.CANDLES.value,
],
)

Expand Down
26 changes: 25 additions & 1 deletion tests/jewcal/test_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Unittests for jewcal.core."""

from datetime import date
from datetime import date, datetime, timezone
from doctest import NORMALIZE_WHITESPACE, DocTestSuite
from typing import no_type_check
from unittest import TestCase
Expand Down Expand Up @@ -221,6 +221,30 @@ def test_hadlokas_haneiros_is_set(self, mock_today: Mock) -> None:
raise TypeError
self.assertIsNotNone(jewcal.zmanim.hadlokas_haneiros)

@patch('src.jewcal.models.zmanim.datetime_now', autospec=True)
@patch('src.jewcal.models.zmanim.date_today', autospec=True)
@patch('src.jewcal.core.date_today', autospec=True)
def test_hadlokas_haneiros_is_set_and_after_nightfall(
self,
mock_core_today: Mock,
mock_today: Mock,
mock_now: Mock,
) -> None:
"""Test has Hadlokas Haneiros, is after nightfall, has next Gregorian date."""
lat, lon = 51.22047, 4.40026 # Antwerpen
location = Location(latitude=lat, longitude=lon)

date_ = date(2024, 7, 25)
now_ = datetime(2024, 7, 25, 20, 42, tzinfo=timezone.utc)
mock_core_today.return_value = date_
mock_today.return_value = date_
mock_now.return_value = now_
jewcal = JewCal(date_, location)
if not jewcal.zmanim:
raise TypeError

self.assertIsNotNone(jewcal.zmanim.hadlokas_haneiros)

@patch('src.jewcal.core.date_today', autospec=True)
def test_hadlokas_haneiros_is_not_set(self, mock_today: Mock) -> None:
"""Test Hadlokas Haneiros is not set."""
Expand Down
9 changes: 3 additions & 6 deletions tests/jewcal/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
from io import StringIO
from unittest import TestCase
from unittest.mock import patch

from src.jewcal.__main__ import main

Expand All @@ -12,12 +13,8 @@ class MainTestCase(TestCase):

def test_main(self) -> None:
"""Test main()."""
# capture standard output by temporarily redirecting sys.stdout to a StringIO
# https://stackoverflow.com/a/34738440
output = StringIO() # Create StringIO.
sys.stdout = output # Redirect stdout.
main() # Call function.
sys.stdout = sys.__stdout__ # Reset redirect.
with patch.object(sys, 'stdout', StringIO()) as output:
main() # Call function.

self.assertIn('Today is', output.getvalue())
self.assertIn('JewCal(jewish_date=JewishDate(year=', output.getvalue())
Expand Down

0 comments on commit a388653

Please sign in to comment.