コード例 #1
0
def test_30s_printed():
    """Check ClockTime imprint()"""
    ct = ClockTime(0, 0, 30,
                   context={'h': 'h', 'min': '', 's': '',
                            'display_0h': False, 'display_0min': False,
                            'min_if_0h': ' min ', 's_if_0h_0min': ' s'})
    assert ct.printed == '30 s'
コード例 #2
0
def test_instanciation_error():
    """Check the ClockTime class initialization"""
    with pytest.raises(TypeError) as excinfo:
        ClockTime(15.2, 24, 16)
    assert str(excinfo.value) == 'hour, minute and second must be '\
        '<class \'int\'>. Found <class \'float\'>, <class \'int\'> and '\
        '<class \'int\'> instead.'
コード例 #3
0
def test_1h_04min_printed():
    """Check ClockTime imprint()"""
    ct = ClockTime(1, 4, 0,
                   context={'h': 'h', 'min': '', 's': '',
                            'display_0h': False, 'display_0min': True,
                            'display_s': False,
                            'min_if_0h': ' min ', 's_if_0h_0min': ' s'})
    assert ct.printed == '1h04'
コード例 #4
0
def test_custom_context_clocktime_printed():
    """Check ClockTime imprint()"""
    ct = ClockTime(15, 24, 16, context={'h': 'h ', 'min': '', 's': '',
                                        'display_s': False})
    assert ct.printed == '15h 24'
コード例 #5
0
def test_0h_24min_30s_printed():
    """Check ClockTime imprint()"""
    ct = ClockTime(0, 24, 30)
    assert ct.printed == '0:24:30'
コード例 #6
0
def test_subtraction():
    """Check ClockTime __sub__()"""
    assert ClockTime(6, 39, 25) - ClockTime(2, 41, 26) \
        == ClockTime(3, 57, 59)
コード例 #7
0
def test_exceeding_day_subtraction():
    """Check ClockTime __sub__()"""
    assert ClockTime(5, 20, 40) - ClockTime(21, 30, 0) \
        == ClockTime(7, 50, 40)
コード例 #8
0
def test_negative_minute_and_second_instanciation():
    """Check the ClockTime class initialization"""
    t = ClockTime(15, -24, -16)
    assert str(t) == '14:35:44'
コード例 #9
0
def test_repr():
    """Check ClockTime __repr__()"""
    assert repr(ClockTime(23, 6, 3)) == 'ClockTime(23:06:03)'
コード例 #10
0
def ct(): return ClockTime(15, 24, 16)


def test_config_global_context():
コード例 #11
0
def test_greater_than():
    """Check ClockTime __gt__()"""
    t1 = ClockTime(23, 6, 3)
    t2 = ClockTime(23, 6, 4)
    assert t2 > t1
コード例 #12
0
def test_addition_error():
    """Check ClockTime __add__()"""
    with pytest.raises(TypeError) as excinfo:
        ClockTime(6, 39, 25) + (3, 50, 44)
    assert str(excinfo.value) == 'Only a ClockTime can be added to a '\
        'ClockTime. Found <class \'tuple\'> instead.'
コード例 #13
0
def test_regular_addition():
    """Check ClockTime __add__()"""
    assert ClockTime(6, 39, 25) + ClockTime(0, 11, 12) \
        == ClockTime(6, 50, 37)
コード例 #14
0
def test_lower_or_equal():
    """Check ClockTime __le__()"""
    t1 = ClockTime(23, 6, 3)
    t2 = ClockTime(23, 6, 4)
    assert t1 <= t2
コード例 #15
0
def test_greater_or_equal():
    """Check ClockTime __ge__()"""
    t1 = ClockTime(23, 6, 3)
    t2 = ClockTime(23, 6, 4)
    assert t2 >= t1
コード例 #16
0
def test_lower_than():
    """Check ClockTime __lt__()"""
    t1 = ClockTime(23, 6, 3)
    t2 = ClockTime(23, 6, 4)
    assert t1 < t2
コード例 #17
0
def test_inequality():
    """Check ClockTime __eq__()"""
    assert ClockTime(23, 6, 3) != 'ClockTime(23:06:03)'
コード例 #18
0
def test_instanciation_from_another_clocktime(ct):
    """Check the ClockTime class initialization"""
    ct2 = ClockTime(ct)
    assert str(ct2) == '15:24:16'
コード例 #19
0
def test_addition():
    """Check ClockTime __add__()"""
    assert ClockTime(6, 39, 25) + ClockTime(3, 50, 44) \
        == ClockTime(10, 30, 9)
コード例 #20
0
def test_equality():
    """Check ClockTime __eq__()"""
    t1 = ClockTime(23, 6, 3)
    t2 = ClockTime(23, 6, 3)
    assert t1 == t2
コード例 #21
0
def test_exceeding_day_addition():
    """Check ClockTime __add__()"""
    assert ClockTime(21, 30, 0) + ClockTime(5, 20, 40) \
        == ClockTime(2, 50, 40)
コード例 #22
0
def test_subtraction_error():
    """Check ClockTime __sub__()"""
    with pytest.raises(TypeError) as excinfo:
        ClockTime(6, 39, 25) - (3, 50, 44)
    assert str(excinfo.value) == 'Only a ClockTime can be subtracted from a '\
        'ClockTime. Found <class \'tuple\'> instead.'
コード例 #23
0
def test_negative_second_instanciation():
    """Check the ClockTime class initialization"""
    t = ClockTime(15, 24, -16)
    assert str(t) == '15:23:44'
コード例 #24
0
def test_regular_subtraction():
    """Check ClockTime __sub__()"""
    assert ClockTime(6, 39, 25) - ClockTime(0, 11, 12) \
        == ClockTime(6, 28, 13)
コード例 #25
0
def test_negative_instanciation():
    """Check the ClockTime class initialization"""
    t = ClockTime(-15, -24, -16)
    assert str(t) == '08:35:44'
コード例 #26
0
def test_leading_zeros():
    """Check leading zeros"""
    assert str(ClockTime(1, 2, 9)) == '01:02:09'