예제 #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'