Skip to content

Commit

Permalink
Improve coverage of the core.py module
Browse files Browse the repository at this point in the history
refs #546
  • Loading branch information
brunobord committed Oct 9, 2020
1 parent a17dfa0 commit b52c139
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -6,6 +6,7 @@
- Added all ISO codes for Spain regions (#531).
- Refactored Spain test modules (#531).
- Fix Catalonia calendar by removing *Sant Juan* day, which does not appear to be an official holiday (#531).
- Improve coverage of `workalendar/core.py` module (#546).

## v12.0.0 (2020-10-02)

Expand Down
2 changes: 0 additions & 2 deletions workalendar/core.py
Expand Up @@ -628,8 +628,6 @@ def add_working_days(self, day, delta,

days = 0
temp_day = day
if type(temp_day) is datetime and not keep_datetime:
temp_day = temp_day.date()
day_added = 1 if delta >= 0 else -1
delta = abs(delta)
while days < delta:
Expand Down
56 changes: 53 additions & 3 deletions workalendar/tests/test_core.py
@@ -1,3 +1,4 @@
from unittest.mock import patch
from datetime import date
from datetime import datetime
from unittest import TestCase
Expand All @@ -8,9 +9,9 @@
from ..core import (
MON, TUE, THU, FRI, WED, SAT, SUN,
Calendar, LunarMixin, WesternCalendar,
IslamicMixin, JalaliMixin
CalverterMixin, IslamicMixin, JalaliMixin
)
from ..exceptions import UnsupportedDateType
from ..exceptions import UnsupportedDateType, CalendarError


class CalendarTest(CoreCalendarTest):
Expand Down Expand Up @@ -254,6 +255,43 @@ def test_year_conversion(self):
self.assertEqual(len(days), 365)


class CalverterClassNoConversionMethod(CalverterMixin):
pass


class NoConversionMethodTest(TestCase):
def test_no_conversion_method(self):
with self.assertRaises(NotImplementedError):
CalverterClassNoConversionMethod()


class IncludeLaylatAlQadr(IslamicMixin):
include_laylat_al_qadr = True


class DoesNotIncludeLaylatAlQadr(IslamicMixin):
include_laylat_al_qadr = False


class LaylatAlQadrTest(TestCase):

def test_warning_laylat_al_qadr(self):
cal = IncludeLaylatAlQadr()
with patch('warnings.warn') as patched:
cal.get_islamic_holidays()
patched.assert_called_with(
'The Islamic holiday named Laylat al-Qadr is decided by the '
'religious authorities. It is not possible to compute it. '
"You'll have to add it manually."
)

def test_no_warning_laylat_al_qadr(self):
cal = DoesNotIncludeLaylatAlQadr()
with patch('warnings.warn') as patched:
cal.get_islamic_holidays()
patched.assert_not_called()


class MockChristianCalendar(WesternCalendar):
# WesternCalendar inherits from ChristianMixin
pass
Expand Down Expand Up @@ -469,7 +507,7 @@ class MultipleLineEmptyFirstDocstring(Calendar):
"""


class CalendarClassName(TestCase):
class CalendarClassNameTest(TestCase):
def test_no_docstring(self):
self.assertEqual(NoDocstring.name, "NoDocstring")

Expand Down Expand Up @@ -725,3 +763,15 @@ def test_unsupported_type_get_working_days_delta(self):
self.assertEqual(delta, 2)
delta = self.cal.get_working_days_delta(end, start)
self.assertEqual(delta, 2)


class MockCalendarNoFatTuesdayLabel(WesternCalendar):
fat_tuesday_label = None


class FatTuesdayLabelTest(TestCase):

def test_fat_tuesday_label(self):
cal = MockCalendarNoFatTuesdayLabel()
with self.assertRaises(CalendarError):
cal.get_fat_tuesday(2020)

0 comments on commit b52c139

Please sign in to comment.