Skip to content

Commit

Permalink
Added a warning for Scotland calendars
Browse files Browse the repository at this point in the history
refs #31
  • Loading branch information
brunobord committed Feb 7, 2019
1 parent 55720dc commit 07ccb88
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Expand Up @@ -4,6 +4,8 @@

### New calendars

**WARNING** Scotland (sub)calendars are highly experimental and because of their very puzzling rules, may be false. Please use them with care.

- Added Scotland calendars, i.e. Scotland, Aberdeen, Angus, Arbroath, Ayr, Carnoustie & Monifieth, Clydebank, Dumfries & Galloway, Dundee, East Dunbartonshire, Edinburgh, Elgin, Falkirk, Fife, Galashiels, Glasgow, Hawick, Inverclyde, Inverness, Kilmarnock, Lochaber, Monifieth, North Lanarkshire, Paisley, Perth, Scottish Borders, South Lanarkshire, Stirling, and West Dunbartonshire (#31).

### Bugfixes
Expand Down
15 changes: 15 additions & 0 deletions workalendar/europe/scotland/__init__.py
Expand Up @@ -23,6 +23,7 @@
# Since Scotland territories have a lot of different variations, it has become
# necessary to split this module and associated tests
from datetime import date, timedelta
import warnings
from workalendar.core import WesternCalendar, ChristianMixin
from workalendar.core import MON, THU, FRI
from .mixins import (
Expand Down Expand Up @@ -64,6 +65,20 @@ class Scotland(WesternCalendar, ChristianMixin):
include_saint_andrew = False
include_victoria_day = False

def __init__(self, *args, **kwargs):
super(Scotland, self).__init__(*args, **kwargs)
warnings.warn(
"""
Please bear in mind that every Scotland (sub)calendar is highly experimental.
It appeared throughout out searches that Scottish calendars have many
exceptions and somes sources of information contradicts with each other.
As a consequence, we advise our user to treat this Scotland submodule with
as much care as possible.
"""
)

def get_may_day(self, year):
"""
May Day is the first Monday in May
Expand Down
3 changes: 2 additions & 1 deletion workalendar/tests/__init__.py
Expand Up @@ -9,6 +9,7 @@ class GenericCalendarTest(TestCase):
cal_class = Calendar

def setUp(self):
warnings.simplefilter("ignore")
super(GenericCalendarTest, self).setUp()
warnings.simplefilter('ignore')
self.year = date.today().year
self.cal = self.cal_class()
23 changes: 22 additions & 1 deletion workalendar/tests/test_scotland.py
@@ -1,5 +1,7 @@
from datetime import date
from unittest import TestCase
from unittest import TestCase, skipIf
import sys
import warnings

from workalendar.tests import GenericCalendarTest
from workalendar.europe import (
Expand All @@ -11,6 +13,9 @@
)


PY2 = sys.version_info[0] == 2


class GoodFridayTestMixin(object):
def test_good_friday(self):
holidays = self.cal.holidays_set(2018)
Expand Down Expand Up @@ -270,6 +275,22 @@ class ScotlandTest(GenericCalendarTest):
"""
cal_class = Scotland

# For some reason, the Python 2 warnings module doesn't trigger a warning
# at each call of constructor ; skipping if we're in a Python2 env.
@skipIf(PY2, "Python 2 warnings unsupported")
def test_init_warning(self):
warnings.simplefilter("always")
with warnings.catch_warnings(record=True) as w:
# Cause all warnings to always be triggered.
# Trigger a warning.
self.cal_class()
# Verify some things
assert len(w) == 1
assert issubclass(w[-1].category, UserWarning)
assert "experimental" in str(w[-1].message)
# Back to normal filtering
warnings.simplefilter("ignore")

def test_year_2018(self):
holidays = self.cal.holidays_set(2018)
self.assertIn(date(2018, 1, 1), holidays) # New year's day
Expand Down

0 comments on commit 07ccb88

Please sign in to comment.