コード例 #1
0
 def test_interval_locator_with_two_pd_ts(self):
     clnd = tb_12_days()
     assert clnd._get_interval_locs_from_reference(
         (pd.Timestamp('02 Jan 2017 15:00'),
          pd.Timestamp('08 Jan 2017 15:00')), False,
         False) == [_Location(2, LOC_WITHIN),
                    _Location(8, LOC_WITHIN)]
コード例 #2
0
 def test_interval_locator_with_two_datettime_ts(self):
     clnd = tb_12_days()
     assert clnd._get_interval_locs_from_reference(
         (datetime.datetime(2017, 1, 2, 15, 0, 0),
          datetime.datetime(2017, 1, 8, 15, 0, 0)), False,
         False) == [_Location(2, LOC_WITHIN),
                    _Location(8, LOC_WITHIN)]
コード例 #3
0
 def test_interval_locator_with_two_ts(self):
     clnd = tb_12_days()
     assert clnd._get_interval_locs_from_reference(
         ('02 Jan 2017 15:00', '08 Jan 2017 15:00'), False,
         False) == [_Location(2, LOC_WITHIN),
                    _Location(8, LOC_WITHIN)]
     # reverse is ok; it is taken care later in 'get_interval'
     assert clnd._get_interval_locs_from_reference(
         ('08 Jan 2017 15:00', '02 Jan 2017 15:00'), False,
         False) == [_Location(8, LOC_WITHIN),
                    _Location(2, LOC_WITHIN)]
コード例 #4
0
 def test_locate(self):
     clnd = tb_12_days()
     loc = clnd._locate('31 Dec 2016')
     assert loc == _Location(0, LOC_WITHIN)
     loc = clnd._locate('01 Jan 2017')
     assert loc == _Location(0, LOC_WITHIN)
     loc = clnd._locate('04 Jan 2017')
     assert loc == _Location(3, LOC_WITHIN)
     loc = clnd._locate('11 Jan 2017')
     assert loc == _Location(8, LOC_WITHIN)
     loc = clnd._locate('12 Jan 2017')
     assert loc == _Location(8, LOC_WITHIN)
コード例 #5
0
    def test_interval_locator_from_pd_periods(self):
        clnd = tb_12_days()
        # if we could not directly Timestamp() a reference, we try to call its
        # `to_timestamp` method which would return reference's start time

        # First day of Jan is inside clnd
        assert clnd._get_interval_locs_from_reference(
            (pd.Period('02 Jan 2017', freq='M'), '11 Jan 2017 15:00'), False,
            False) == [_Location(1, LOC_WITHIN),
                       _Location(11, LOC_WITHIN)]
        # While 31 Dec is within clnd, the first day of Dec is outside
        assert clnd._get_interval_locs_from_reference(
            (pd.Period('31 Dec 2016', freq='M'), '11 Jan 2017 15:00'), False,
            False) == [_Location(None, OOB_LEFT),
                       _Location(11, LOC_WITHIN)]
        # freq=W begins weeks on Mon which is 02 Jan 2017
        assert clnd._get_interval_locs_from_reference(
            (pd.Period('05 Jan 2017', freq='W'), '11 Jan 2017 15:00'), False,
            False) == [_Location(2, LOC_WITHIN),
                       _Location(11, LOC_WITHIN)]
        # freq=W-MON ends weeks on Mondays, and 02 Jan is Monday,
        # but this week begins on Tue 27 Dec 2016 which is outside the timeboard
        assert clnd._get_interval_locs_from_reference(
            (pd.Period('02 Jan 2017', freq='W-MON'), '11 Jan 2017 15:00'),
            False,
            False) == [_Location(None, OOB_LEFT),
                       _Location(11, LOC_WITHIN)]
コード例 #6
0
 def test_interval_locator_with_OOB_ts(self):
     clnd = tb_12_days()
     # only one end of the interval is OOB
     assert clnd._get_interval_locs_from_reference(
         ('02 Jan 2017 15:00', '13 Jan 2017 15:00'), False,
         False) == [_Location(2, LOC_WITHIN),
                    _Location(None, OOB_RIGHT)]
     assert clnd._get_interval_locs_from_reference(
         ('30 Dec 2016 15:00', '08 Jan 2017 15:00'), False,
         False) == [_Location(None, OOB_LEFT),
                    _Location(8, LOC_WITHIN)]
     # the interval spans over the timeboard
     assert clnd._get_interval_locs_from_reference(
         ('30 Dec 2016 15:00', '13 Jan 2017 15:00'), False,
         False) == [_Location(None, OOB_LEFT),
                    _Location(None, OOB_RIGHT)]
     assert clnd._get_interval_locs_from_reference(
         ('13 Jan 2017 15:00', '30 Dec 2016 15:00'), False,
         False) == [_Location(None, OOB_RIGHT),
                    _Location(None, OOB_LEFT)]
     # the interval is completely outside the timeboard
     assert clnd._get_interval_locs_from_reference(
         ('25 Dec 2016 15:00', '30 Dec 2016 15:00'), False,
         False) == [_Location(None, OOB_LEFT),
                    _Location(None, OOB_LEFT)]
     assert clnd._get_interval_locs_from_reference(
         ('30 Dec 2016 15:00', '25 Dec 2016 15:00'), False,
         False) == [_Location(None, OOB_LEFT),
                    _Location(None, OOB_LEFT)]
     assert clnd._get_interval_locs_from_reference(
         ('13 Jan 2017 15:00', '15 Jan 2017 15:00'), False,
         False) == [_Location(None, OOB_RIGHT),
                    _Location(None, OOB_RIGHT)]
     assert clnd._get_interval_locs_from_reference(
         ('15 Jan 2017 15:00', '13 Jan 2017 15:00'), False,
         False) == [_Location(None, OOB_RIGHT),
                    _Location(None, OOB_RIGHT)]
コード例 #7
0
 def test_interval_locator_with_with_excessive_item(self):
     clnd = tb_12_days()
     assert clnd._get_interval_locs_from_reference(
         ('02 Jan 2017 15:00', '08 Jan 2017 15:00', 'something'), False,
         False) == [_Location(2, LOC_WITHIN),
                    _Location(8, LOC_WITHIN)]
コード例 #8
0
 def test_interval_locator_default(self):
     clnd = tb_12_days()
     assert clnd._get_interval_locs_from_reference(None, False, False) == [
         _Location(0, LOC_WITHIN),
         _Location(12, LOC_WITHIN)
     ]
コード例 #9
0
 def test_interval_strip_locs_corner_cases(self):
     clnd = tb_12_days()
     assert clnd._strip_interval_locs(
         [_Location(0, 'anything'), _Location(0, 'whatever')], True, True) \
         == [_Location(1, 'anything'), _Location(-1, 'whatever')]
     assert clnd._strip_interval_locs(
         [_Location(-4, 'anything'), _Location(-2, 'whatever')], True, True) \
         == [_Location(-3, 'anything'), _Location(-3, 'whatever')]
     assert clnd._strip_interval_locs(
         [_Location(None,'anything'),_Location(2, 'whatever')], False, False) \
         == [_Location(None,'anything'),_Location(2, 'whatever')]
     assert clnd._strip_interval_locs(
         [_Location(None,'anything'),_Location(2, 'whatever')], True, False) \
         == [_Location(None,'anything'),_Location(2, 'whatever')]
     assert clnd._strip_interval_locs(
         [_Location(None,'anything'),_Location(2, 'whatever')], False, True) \
         == [_Location(None,'anything'),_Location(1, 'whatever')]
     assert clnd._strip_interval_locs(
         [_Location(2,'anything'),_Location(None, 'whatever')], True, True) \
         == [_Location(3,'anything'),_Location(None, 'whatever')]
     assert clnd._strip_interval_locs(
         [_Location(None,'anything'),_Location(None, 'whatever')], True, True) \
         == [_Location(None,'anything'),_Location(None, 'whatever')]
コード例 #10
0
 def test_interval_strip_locs_single_unit(self):
     clnd = tb_12_days()
     assert clnd._strip_interval_locs(
         [_Location(2,'anything'),_Location(2, 'whatever')], False, False) \
         == [_Location(2,'anything'),_Location(2, 'whatever')]
     assert clnd._strip_interval_locs(
         [_Location(2,'anything'),_Location(2, 'whatever')], True, False) \
         == [_Location(3,'anything'),_Location(2, 'whatever')]
     assert clnd._strip_interval_locs(
         [_Location(2,'anything'),_Location(2, 'whatever')], False, True) \
         == [_Location(2,'anything'),_Location(1, 'whatever')]
     assert clnd._strip_interval_locs(
         [_Location(2,'anything'),_Location(2, 'whatever')], True, True) \
         == [_Location(3,'anything'),_Location(1, 'whatever')]
コード例 #11
0
ファイル: test_workshift.py プロジェクト: yurj/timeboard
 def test_locate_outside(self):
     clnd = tb_12_days()
     loc = clnd._locate('13 Jan 2017')
     assert loc == _Location(None, OOB_RIGHT)
     loc = clnd._locate('30 Dec 2016')
     assert loc == _Location(None, OOB_LEFT)
コード例 #12
0
ファイル: test_workshift.py プロジェクト: yurj/timeboard
 def test_locate(self):
     clnd = tb_12_days()
     loc = clnd._locate('04 Jan 2017')
     assert loc == _Location(4, LOC_WITHIN)