예제 #1
0
    def test_calendar_RU_week8x5_select_years(self):

        clnd = RU.Weekly8x5('01 Jan 2010', '31 Dec 2015')
        assert clnd.start_time == datetime.datetime(2010, 1, 1, 0, 0, 0)
        assert clnd.end_time > datetime.datetime(2015, 12, 31, 23, 59, 59)
        assert clnd.end_time < datetime.datetime(2016, 1, 1, 0, 0, 0)
        # if only year is given, the 1st of Jan is implied at the both ends
        clnd = RU.Weekly8x5('2010', '2015')
        assert clnd.start_time == datetime.datetime(2010, 1, 1, 0, 0, 0)
        assert clnd.end_time > datetime.datetime(2015, 1, 1, 23, 59, 59)
        assert clnd.end_time < datetime.datetime(2015, 1, 2, 0, 0, 0)
예제 #2
0
 def test_calendar_RU_week8x5_custom_amds(self):
     clnd = RU.Weekly8x5(custom_amendments={'22 Feb 2017 00:00': 0,
                                          '23.02.2017': 8})
     assert clnd('21 Feb 2017').is_on_duty()
     assert clnd('22 Feb 2017').is_off_duty()
     assert clnd('23 Feb 2017').is_on_duty()
     assert clnd('24 Feb 2017').is_off_duty()
     assert clnd('01 May 2017').is_off_duty()
예제 #3
0
 def test_calendar_RU_week8x5_no_amds(self):
     clnd = RU.Weekly8x5(do_not_amend=True,
                         only_custom_amendments=True,
                         custom_amendments={'22 Feb 2017': 0,
                                          '23 Feb 2017': 8}
                         )
     assert clnd('21 Feb 2017').is_on_duty()
     assert clnd('22 Feb 2017').is_on_duty()
     assert clnd('23 Feb 2017').is_on_duty()
     assert clnd('24 Feb 2017').is_on_duty()
     assert clnd('01 May 2017').is_on_duty()
예제 #4
0
 def test_calendar_RU_week8x5_custom_amds_ambiguous(self):
     # We already have timestamps of 22.02.17 00:00:00 and 23.02.17 00:00:00
     # in amendments dict which is to be update by custom amds.
     # Applying the custom amds below would result in ambiguous keys (two
     # keys referring to the same day) but we preprocess custom_amedndments
     # to align them at the start_time of days in the same manner as
     # in amendments dict
     clnd = RU.Weekly8x5(custom_amendments={'22 Feb 2017 13:00': 0,
                                          '23 Feb 2017 15:00': 8})
     assert clnd('21 Feb 2017').is_on_duty()
     assert clnd('22 Feb 2017').is_off_duty()
     assert clnd('23 Feb 2017').is_on_duty()
     assert clnd('24 Feb 2017').is_off_duty()
     assert clnd('01 May 2017').is_off_duty()
예제 #5
0
    def test_calendar_RU_week8x5(self):

        start = RU.Weekly8x5.parameters()['start']
        end = RU.Weekly8x5.parameters()['end']
        freq = RU.Weekly8x5.parameters()['base_unit_freq']
        clnd = RU.Weekly8x5()
        assert clnd.start_time == get_period(start, freq=freq).start_time
        assert clnd.end_time == get_period(end, freq=freq).end_time

        bdays_in_year = {
            2005: 248, 2006: 248, 2007: 249,
            2008: 250, 2009: 249, 2010: 249, 2011: 248, 2012: 249, 2013: 247,
            2014: 247, 2015: 247, 2016: 247, 2017: 247, 2018: 247
        }
        for year, bdays in bdays_in_year.items():
            assert clnd.get_interval('01 Jan {}'.format(year),
                                     period='A').count() == bdays

        # a regular week
        for day in range(20, 25):
            ws = clnd("{} Nov 2017".format(day))
            assert ws.is_on_duty()
            assert ws.label == 8
        for day in range(25, 27):
            ws = clnd("{} Nov 2017".format(day))
            assert ws.is_off_duty()
            assert ws.label == 0
        assert clnd(('20 Nov 2017', '26 Nov 2017')).worktime() == 40

        # standard holidays
        assert clnd('01 Jan 2008').is_off_duty()
        assert clnd('23 Feb 2017').is_off_duty()
        # week day made a day off
        assert clnd('24 Feb 2017').is_off_duty()
        # weekend made a working day
        assert clnd('05 May 2012').is_on_duty()
        # by default 31 Dec is a working day if not a weekend
        assert clnd('31 Dec 2015').is_on_duty()
        # by default a holiday eve has shorter hours
        assert clnd('22 Feb 2017').label == 7
예제 #6
0
 def test_calendar_RU_week8x5_no_short_eves(self):
     clnd = RU.Weekly8x5(short_eves=False)
     assert clnd('22 Feb 2017').label == 8
예제 #7
0
 def test_calendar_RU_week8x5_31dec_off(self):
     clnd = RU.Weekly8x5(work_on_dec31=False)
     for y in range(2008,2019):
         assert clnd("31 Dec {}".format(y)).is_off_duty()
예제 #8
0
 def test_calendar_RU_week8x5_OOB(self):
     with pytest.raises(OutOfBoundsError):
         RU.Weekly8x5('1990')
     with pytest.raises(OutOfBoundsError):
         RU.Weekly8x5('2008', '31 Dec 2019')