def test_void_interval_with_ws(self): clnd = tb_12_days() ivl = _VoidInterval(clnd, (Workshift(clnd, 8), Workshift(clnd, 2)), clnd.default_schedule) assert pd.isnull(ivl.start_time) assert pd.isnull(ivl.end_time) assert ivl._loc == (8, 2) assert len(ivl) == 0
def test_interval_direct_with_ws(self): clnd = tb_12_days() ivl = Interval(clnd, (Workshift(clnd, 2), Workshift(clnd, 8)), clnd.default_schedule) assert ivl.start_time == datetime.datetime(2017, 1, 2, 0, 0, 0) assert ivl.end_time > datetime.datetime(2017, 1, 8, 23, 59, 59) assert ivl.end_time < datetime.datetime(2017, 1, 9, 0, 0, 0) assert ivl._loc == (2, 8) assert len(ivl) == 7
def test_ws_worktime_in_label(self): clnd = tb.Timeboard(base_unit_freq='D', start='31 Dec 2016', end='12 Jan 2017', layout=[0, 1, 0, 0, 2, 0], worktime_source='labels') ws = Workshift(clnd, 4) assert ws.worktime() == 2 assert ws.worktime(duty='off') == 0 assert ws.worktime(duty='any') == 2
def test_direct_workshift_constructor_with_bad_loc(self): clnd = tb_12_days() #with pytest.raises(KeyError): get_timestamp(Workshift(clnd, -1, clnd.default_schedule) ) == datetime.datetime(2017, 1, 12, 0, 0, 0) with pytest.raises(OutOfBoundsError): Workshift(clnd, 500000000, clnd.default_schedule) with pytest.raises(TypeError): Workshift(clnd, 10.5, clnd.default_schedule) with pytest.raises(TypeError): Workshift(clnd, '05 Jan 2017', clnd.default_schedule)
def test_direct_workshift_constructor(self): clnd = tb_12_days() ws = Workshift(clnd, 4) assert ws._loc == 4 assert ws.start_time == datetime.datetime(2017, 1, 4, 0, 0, 0) assert ws.end_time > datetime.datetime(2017, 1, 4, 23, 59, 59) assert ws.end_time < datetime.datetime(2017, 1, 5, 0, 0, 0) assert ws.label == 2 assert ws.schedule == clnd.default_schedule assert ws.is_on_duty() assert not ws.is_off_duty() assert ws.duration == 1
def test_ws_worktime_default(self): clnd = tb_12_days() ws = Workshift(clnd, 4) assert ws.worktime() == 1 assert ws.worktime(duty='off') == 0 assert ws.worktime(duty='any') == 1 ws = Workshift(clnd, 5) assert ws.worktime() == 0 assert ws.worktime(duty='off') == 1 assert ws.worktime(duty='any') == 1
def test_ws_worktime_in_labels_strings(self): clnd = tb.Timeboard(base_unit_freq='D', start='31 Dec 2016', end='12 Jan 2017', layout=[0, 1, 0, 0, 'a', 0], worktime_source='labels') ws = Workshift(clnd, 4) with pytest.raises(TypeError): ws.worktime() with pytest.raises(TypeError): ws.worktime(duty='any') assert ws.worktime(duty='off') == 0
def test_ws_worktime_other_schedule(self): clnd = tb_12_days() other_sdl = clnd.add_schedule('other', lambda label: label < 2) ws = Workshift(clnd, 4) assert ws.worktime(schedule=other_sdl) == 0 assert ws.worktime(duty='off', schedule=other_sdl) == 1 assert ws.worktime(duty='any', schedule=other_sdl) == 1 clnd = tb.Timeboard(base_unit_freq='D', start='31 Dec 2016', end='12 Jan 2017', layout=[0, 1, 0, 0, 2, 0], worktime_source='labels') ws = Workshift(clnd, 4) assert ws.worktime(schedule=other_sdl) == 0 assert ws.worktime(duty='off', schedule=other_sdl) == 2 assert ws.worktime(duty='any', schedule=other_sdl) == 2
def test_ws_worktime_bad_duty(self): clnd = tb_12_days() ws = Workshift(clnd, 4) with pytest.raises(ValueError): ws.worktime(duty='bad_duty')