コード例 #1
0
ファイル: test_recorder.py プロジェクト: txomon/py-wwe
def test_no_personal_holidays_used():
    bh = create_bank_holiday(date=datetime(2018, 1, 10))
    r = Recorder()
    r.add(bh)
    actual_result = r.personal_holidays_used()
    expected_result = 0

    assert expected_result == actual_result
コード例 #2
0
ファイル: test_recorder.py プロジェクト: txomon/py-wwe
def test_total_hours_to_work_no_holidays_no_weekend():
    start = datetime(2018, 3, 6)
    end = datetime(2018, 3, 8)
    r = Recorder()

    actual_result = r.total_hours_to_work(start, end)
    expected_result = 3 * 7.5

    assert expected_result == actual_result
コード例 #3
0
ファイル: test_recorder.py プロジェクト: txomon/py-wwe
def test_total_worked_hours_with_expected_date():
    start = datetime(2018, 1, 1)
    t = create_task()
    r = Recorder()
    r.add(t)

    actual_result = r.total_worked_hours(start)
    expected_result = 1.0

    assert expected_result == actual_result
コード例 #4
0
ファイル: test_recorder.py プロジェクト: txomon/py-wwe
def test_total_hours_to_work_with_holidays_and_weekend():
    start = datetime(2018, 3, 28)
    end = datetime(2018, 4, 4)
    bh = create_bank_holiday(date=datetime(2018, 4, 2))  # Easter Monday
    ph = create_personal_holiday(date=datetime(2018, 4, 3))  # Easter Monday
    r = Recorder()

    r.add(bh)
    r.add(ph)
    actual_result = r.total_hours_to_work(start, end)
    # 8 real days - (2 weekend days + 1 bank holiday + 1 personal holiday)
    expected_result = (8 - (2 + 1 + 1)) * 7.5

    assert expected_result == actual_result
コード例 #5
0
ファイル: test_recorder.py プロジェクト: txomon/py-wwe
def test_get_records_between_dates():
    start_date = datetime(2018, 1, 11)
    end_date = datetime(2018, 1, 14)
    bh1 = create_bank_holiday(date=datetime(2018, 1, 10))
    bh2 = create_bank_holiday(date=datetime(2018, 1, 12))
    bh3 = create_bank_holiday(date=datetime(2018, 1, 14))
    bh4 = create_bank_holiday(date=datetime(2018, 1, 16))
    r = Recorder()

    r.add(bh1, bh2, bh3, bh4)
    actual_result = r.records_between(start_date, end_date)
    expected_result = set()
    expected_result.add(bh2)
    expected_result.add(bh3)

    assert expected_result == actual_result
コード例 #6
0
ファイル: test_recorder.py プロジェクト: txomon/py-wwe
def test_personal_holidays_left_no_total_set():
    ph = create_personal_holiday(date=datetime(2018, 1, 11))
    r = Recorder()
    r.add(ph)

    with pytest.raises(Exception):
        r.personal_holidays_left()
コード例 #7
0
ファイル: test_recorder.py プロジェクト: txomon/py-wwe
def test_records_will_not_be_added_twice():
    recorder = Recorder()
    task = create_task()
    bank_holiday = create_bank_holiday()
    personal_holiday = create_personal_holiday()

    recorder.add(task)
    recorder.add(task)
    recorder.add(bank_holiday)
    recorder.add(bank_holiday)
    recorder.add(personal_holiday)
    recorder.add(personal_holiday)

    assert len(recorder.records) == 3
コード例 #8
0
ファイル: test_recorder.py プロジェクト: txomon/py-wwe
def test_total_worked_hours_with_future_start_date():
    start = datetime(2200, 1, 1)
    t = create_task()
    r = Recorder()
    r.add(t)

    with pytest.raises(Exception):
        r.total_worked_hours(start)
コード例 #9
0
ファイル: test_recorder.py プロジェクト: txomon/py-wwe
def test_total_worked_hours_with_null_start_date():
    start = None
    t = create_task()
    r = Recorder()
    r.add(t)

    with pytest.raises(Exception):
        r.total_worked_hours(start)
コード例 #10
0
ファイル: test_recorder.py プロジェクト: txomon/py-wwe
def test_personal_holidays_used():
    bh = create_bank_holiday(date=datetime(2018, 1, 10))
    ph1 = create_personal_holiday(date=datetime(2018, 1, 11))
    ph2 = create_personal_holiday(date=datetime(2018, 1, 12))
    r = Recorder()

    r.add(bh)
    r.add(ph1)
    r.add(ph2)
    actual_result = r.personal_holidays_used()
    expected_result = 2

    assert expected_result == actual_result
コード例 #11
0
ファイル: test_recorder.py プロジェクト: txomon/py-wwe
def test_only_add_records_to_recorder():
    recorder = Recorder()
    random_object = {}
    task = create_task()

    recorder.add(random_object)
    assert len(recorder.records) == 0

    recorder.add(task)
    assert len(recorder.records) == 1
コード例 #12
0
ファイル: test_recorder.py プロジェクト: txomon/py-wwe
def test_personal_holidays_left():
    ph1 = create_personal_holiday(date=datetime(2018, 1, 11))
    ph2 = create_personal_holiday(date=datetime(2018, 1, 12))
    r = Recorder()
    r.total_personal_holidays = 10

    r.add(ph1)
    r.add(ph2)
    actual_result = r.personal_holidays_left()
    expected_result = 8

    assert expected_result == actual_result
コード例 #13
0
ファイル: test_recorder.py プロジェクト: txomon/py-wwe
def test_total_worked_hours_without_record():
    start = datetime(2015, 1, 1)
    r = Recorder()

    with pytest.raises(Exception):
        r.total_worked_hours(start)