コード例 #1
0
def test__parse_time():
    """Test static function _parse_time()."""
    from datetime import time

    def test_TypeError(time):
        """Test TypeError raising during Appointment._parse_time()."""
        with pytest.raises(TypeError) as excinfo:
            Appointment._parse_time(time)
    def test_ValueError(time):
        """Test ValueError raising during Appointment._parse_time()."""
        with pytest.raises(ValueError) as excinfo:
            Appointment._parse_time(time)    

    test_TypeError(None)
    test_TypeError(object)
    test_ValueError("string")
    test_ValueError("1::00pm")
    test_ValueError("1:0pm")
    test_ValueError("110:0pm")
    test_ValueError("11:00")
    test_ValueError("13:00am")
    test_ValueError("-1:00am")
    test_ValueError("15:00pm")
    test_ValueError("1:15am")
    test_ValueError("1:07am")
    test_ValueError("1:00gm")
    test_ValueError("1:00m")

    assert Appointment._parse_time("12:00pm") == time(12, 0)
    assert Appointment._parse_time("0:00am") == time(0, 0)
    assert Appointment._parse_time("1:30am") == time(1, 30)
    assert Appointment._parse_time("1:30pm") == time(13, 30)
    assert Appointment._parse_time("11:30pm") == time(23, 30)
コード例 #2
0
def test___getitem__():
    """Test Test indexing for Calendar."""
    def test_TypeError(calendar, key):
        """Test TypeError raising during calendar[key]."""
        with pytest.raises(TypeError) as excinfo:
            calendar[key]
    def test_IndexError(calendar, key):
        """Test IndexError raising during calendar[key]."""
        with pytest.raises(IndexError) as excinfo:
            calendar[key]

    a1 = Appointment("yo","saturday","12:30pm","1:30pm", [1, 2, 3])
    a2 = Appointment("yerboi","saturday","1:30am","11:30am", [1, 4, 5])
    a3 = Appointment("we out here","saturday","11:30am","12:30pm", [1])

    c1 = Calendar(a1, a2, a3)

    test_TypeError(c1, None)
    test_TypeError(c1, "yo")
    test_IndexError(c1, 4)
    test_IndexError(c1, 1000000)

    assert c1[0] == a1
    assert c1[0] is a1
    c1[0]._name = "bbz"
    assert a1._name == "bbz"
    assert c1[1] == a2
    assert c1[1] is a2
    assert c1[2] == a3
    assert c1[2] is a3
コード例 #3
0
def test__key():
    """Test key function for Appointment."""
    from datetime import time
    name, day, start, end, participants = "a", "Friday", "1:00pm", "2:00pm", [1]
    A1 = Appointment(name, day, start, end, participants)

    assert A1._key() == (name, day, time(13, 0), time(14, 0), (1,))
コード例 #4
0
def test__is_calendar_conflicting():
    """Test Calendar's _is_calendar_conflicting() function."""
    def test_TypeError(calendar1, calendar2):
        """Test TypeError raising during calendar[key] = value."""
        with pytest.raises(TypeError) as excinfo:
            calendar1._is_calendar_conflicting(calendar2)

    a1 = Appointment("yo","saturday","12:30pm","1:30pm", [1, 2, 3])
    a2 = Appointment("yerboi","Friday","1:30am","11:30am", [1, 4, 5])
    a3 = Appointment("we out here","Tuesday","11:30am","12:30pm", [1])
    a4 = Appointment("bluv","Thursday","11:30am","12:30pm", [2, 6])
    a5 = Appointment("yo_conflict","saturday","12:30pm","1:30pm", [1, 2, 6])

    c1 = Calendar(a1, a2)
    c2 = Calendar(a3, a4)
    c3 = Calendar(a1, a3)
    c4 = Calendar(a4, a5)

    test_TypeError(c1, None)
    test_TypeError(c1, "Calendar")

    #test identity not conflicting
    assert not c1._is_calendar_conflicting(c1)
    #regular disjoint test
    assert not c1._is_calendar_conflicting(c2)
    assert not c2._is_calendar_conflicting(c1)
    #test shared (but equal) appointment not conflicting
    assert not c1._is_calendar_conflicting(c3)
    assert not c3._is_calendar_conflicting(c1)
    #test disjoint but conflicting calendars
    assert c1._is_calendar_conflicting(c4)
    assert c4._is_calendar_conflicting(c1)
コード例 #5
0
def test___ne__():
    """Test == operator of Calendar object."""
    def test_TypeError(self, other):
        """Test TypeError raising during != of Calendar objects."""
        with pytest.raises(TypeError) as excinfo:
            self == other

    a1 = Appointment("yo","saturday","12:30pm","1:30pm", [1, 2, 3])
    a2 = Appointment("yerboi","saturday","1:30am","11:30am", [1, 4, 5])
    a3 = Appointment("we out here","saturday","11:30am","12:30pm", [1])

    c1 = Calendar(a1, a2, a3)
    c2 = Calendar(a1, a1, a2, a2, a3, a3)
    c3 = Calendar(a3, a1, a2)
    c4 = Calendar(a3, a1)
    c5 = Calendar(a1)
    
    test_TypeError(c1, None)
    test_TypeError(c1, a1)
    assert not c1 != c1
    assert not c1 != c2
    assert not c1 != c3
    assert not c1 != c2 != c3
    assert c1 != c4
    assert c1 != c5
    assert c4 != c5
    assert c1 != c4 != c5
コード例 #6
0
def test___len__():
    """Test len(Calendar)."""

    a1 = Appointment("yo","saturday","12:30pm","1:30pm", [1, 2, 3])
    a2 = Appointment("yerboi","saturday","1:30am","11:30am", [1, 4, 5])
    a3 = Appointment("we out here","saturday","11:30am","12:30pm", [1])

    c0 = Calendar()
    c1 = Calendar(a1, a2, a3)
    c2 = Calendar(a1, a1, a2, a2, a3, a3)
    assert len(c0) == 0
    assert len(c1) == 3
    assert len(c2) == 3
コード例 #7
0
def test___contains__():
    """
    Test 'in' and 'not in' operators for Calendar.
    
    Appointment class catches TypeErrors so ignore here.
    """
    
    a1 = Appointment("yo","saturday","12:30pm","1:30pm", [1, 2, 3])
    a2 = Appointment("yerboi","saturday","1:30am","11:30am", [1, 4, 5])
    a3 = Appointment("we out here","saturday","11:30am","12:30pm", [1])

    c1 = Calendar(a1, a2)

    assert a1 in c1
    assert a2 in c1
    assert a3 not in c1
コード例 #8
0
def test___deepcopy__():
    """Implement copy.deepcopy for Calendar object."""
    from copy import deepcopy
    a1 = Appointment("yo","saturday","12:30pm","1:30pm", [1, 2, 3])
    a2 = Appointment("yerboi","Friday","1:30am","11:30am", [1, 4, 5])
    a3 = Appointment("we out here","Tuesday","11:30am","12:30pm", [1])
    a4 = Appointment("bluv","Thursday","11:30am","12:30pm", [2, 6])

    c = Calendar(a1, a2, a3, a4)
    c_copy = deepcopy(c)
    assert c == c_copy
    assert c is not c_copy
    appts = c._appointments
    appts_copy = c_copy._appointments
    for i in range(len(appts)):
        assert appts[i] == appts_copy[i]
        assert appts[i] is not appts_copy[i]
コード例 #9
0
def test__is_appointment_conflicting():
    """Test Calendar's _is_appointment_conflicting() function."""
    def test_TypeError(calendar, appointment):
        """Test TypeError raising during _is_appointment_conflicting()."""
        with pytest.raises(TypeError) as excinfo:
            calendar._is_appointment_conflicting(appointment)

    a1 = Appointment("yo","saturday","12:30pm","1:30pm", [1, 2, 3])
    a1_copy = Appointment("yo_copy","saturday","12:30pm","1:30pm", [1, 2, 3])
    a2 = Appointment("yerboi","saturday","1:30am","11:30am", [1, 4, 5])
    a3 = Appointment("we out here","saturday","11:30am","12:30pm", [1])

    c1 = Calendar(a1, a2)

    test_TypeError(c1, None)
    test_TypeError(c1, "Appointment")

    assert not c1._is_appointment_conflicting(a1)
    assert c1._is_appointment_conflicting(a1_copy)
    assert not c1._is_appointment_conflicting(a3)
コード例 #10
0
def test___iter__():
    """Test iterator for Calendar object."""
    
    a1 = Appointment("yo","saturday","12:30pm","1:30pm", [1, 2, 3])
    a2 = Appointment("yerboi","saturday","1:30am","11:30am", [1, 4, 5])
    a3 = Appointment("we out here","saturday","11:30am","12:30pm", [1])

    c1 = Calendar(a1, a2, a3)

    assert [appt for appt in c1] == c1._appointments
    assert [i for i in iter(c1)] == c1._appointments
    
    for i, appt in enumerate(c1):
        if i == 0: 
            assert appt == a1
            assert appt is a1
        if i == 1: 
            assert appt == a2
            assert appt is a2
        if i == 2: 
            assert appt == a3
            assert appt is a3
コード例 #11
0
def test___setitem__():
    """Test Calendar[key] = value."""
    def test_TypeError(calendar, key, value):
        """Test TypeError raising during calendar[key] = value."""
        with pytest.raises(TypeError) as excinfo:
            calendar[key] = value
    def test_IndexError(calendar, key, value):
        """Test IndexError raising during calendar[key] = value."""
        with pytest.raises(IndexError) as excinfo:
            calendar[key] = value
    def test_ValueError(calendar, key, value):
        """Test ValueError raising during calendar[key] = value."""
        with pytest.raises(ValueError) as excinfo:
            calendar[key] = value

    a1 = Appointment("yo","saturday","12:30pm","1:30pm", [1, 2, 3])
    a1_copy = Appointment("yo_copy","saturday","12:30pm","1:30pm", [1, 2, 3])
    a2 = Appointment("yerboi","saturday","1:30am","11:30am", [1, 4, 5])
    a3 = Appointment("we out here","saturday","11:30am","12:30pm", [1])

    c1 = Calendar(a1, a2)

    #Test non Appointment object value
    test_TypeError(c1, 0, None)
    test_TypeError(c1, 0, c1)
    #Test non int index
    test_TypeError(c1, None, a3)
    test_TypeError(c1, "", a3)
    #test bad index
    test_IndexError(c1, 4, a3)
    test_IndexError(c1, 10000, a3)
    #test conflicted addition
    test_ValueError(c1, 1, a1_copy)
    #test duplicate entry
    test_ValueError(c1, 1, a1)

    c1[1] = a3
    assert c1[1] == a3
    assert c1[1] is a3
コード例 #12
0
def test___init__():
    """Test construction of Calendar object."""
    def test_TypeError(*appointments):
        """Test TypeError raising during Calendar object construction."""
        with pytest.raises(TypeError) as excinfo:
            Calendar(*appointments)
    def test_ValueError(*appointments):
        """Test ValueError raising during Calendar object construction."""
        with pytest.raises(ValueError) as excinfo:
            Calendar(*appointments)

    a1 = Appointment("yo","saturday","12:30pm","1:30pm", [1, 2, 3])
    a1_copy = Appointment("yo_copy","saturday","12:30pm","1:30pm", [1, 2, 3])
    a2 = Appointment("yerboi","saturday","1:30am","11:30am", [1, 4, 5])
    a3 = Appointment("we out here","saturday","11:30am","12:30pm", [1])

    test_TypeError(a1, None)
    test_TypeError(None)
    test_TypeError(a1, None, a2)
    test_ValueError(a1, a1_copy)

    #test implicit duplicate removal
    c = Calendar(a1, a1, a2, a2, a3, a3)
    assert len(c) == 3
コード例 #13
0
def test___deepcopy__():
    """Test deepcopy for Appointment object."""
    from copy import deepcopy
    name, day, start, end, participants = "a", "Friday", "1:00pm", "2:00pm", [1]
    A = Appointment(name, day, start, end, participants)
    A_copy = deepcopy(A)
    assert A_copy == A
    assert A_copy is not A
    A_copy._name = "lol"
    assert A_copy._name != A._name
    A_copy._day = "lol"
    assert A_copy._day != A._day
    A_copy._start is not A._start
    A_copy._end is not A._end
    A_copy._participants is not A._participants
コード例 #14
0
def test___ne__():
    """Test == operator for Appointment objects."""
    def test_TypeError(self, other):
        """Test TypeError raising during != of Appointment objects."""
        with pytest.raises(TypeError) as excinfo:
            self == other

    name, day, start, end, participants = "a", "Friday", "1:00pm", "2:00pm", [1]
    A1 = Appointment(name, day, start, end, participants)
    test_TypeError(A1, None)
    assert not A1 != A1
    A2 = Appointment('b', day, start, end, participants)
    assert A1 != A2
    A3 = Appointment(name, "Saturday", start, end, participants)
    assert A1 != A3
    A4 = Appointment(name, day, "11:00am", end, participants)
    assert A1 != A4
    A5 = Appointment(name, day, start, "3:00pm", participants)
    assert A1 != A5
    A6 = Appointment(name, day, start, end, [2])
    assert A1 != A6
    A7 = Appointment(name, day, start, end, [1,2])
    assert A1 != A7
コード例 #15
0
def test___iadd__():
    """Test += operator for Calendar object."""
    def test_TypeError(self, other):
        """Test TypeError raising during += operator of Calendar."""
        with pytest.raises(TypeError) as excinfo:
            self += other
    def test_ValueError(self, other):
        """Test ValueError raising during += operator of Calendar."""
        with pytest.raises(ValueError) as excinfo:
            self += other

    a1 = Appointment("yo","saturday","12:30pm","1:30pm", [1, 2, 3])
    a2 = Appointment("yerboi","Friday","1:30am","11:30am", [1, 4, 5])
    a3 = Appointment("we out here","Tuesday","11:30am","12:30pm", [1])
    a4 = Appointment("bluv","Thursday","11:30am","12:30pm", [2, 6])
    a5 = Appointment("blarg","wedneSdaY","11:30am","12:30pm", [1, 2, 3, 4, 5])
    a1_conf = Appointment("yo_conf","saturday","12:30pm","1:30pm", [1, 2, 3])

    c1 = Calendar(a1, a2)
    c2 = Calendar(a3, a4)
    c1_conf = Calendar(a3, a1_conf)

    test_TypeError(c1, None)
    test_TypeError(c1, "")
    test_ValueError(c1, a1_conf)
    test_ValueError(c1, c1_conf)

    #test duplicates get dropped durring addition
    c1 += a1
    assert len(c1) == 2
    c1 += c1
    assert len(c1) == 2
    c1 += c2
    assert c1 == Calendar(a1, a2, a3, a4)
    assert c1 == Calendar(a4, a3, a2, a1)
    c1 += a5
    assert c1 == Calendar(a4, a3, a5, a2, a1)
コード例 #16
0
def test__is_conflicting():
    """Test Appointment._is_conflicting() static function."""
    def test_TypeError(appt1, appt2):
        """Test TypeError raising during Appointment._is_conflicting()."""
        with pytest.raises(TypeError) as excinfo:
            Appointment._is_conflicting(appt1, appt2)

    name, day, start, end, participants = "a", "Friday", "1:00pm", "2:00pm", [1]
    A1 = Appointment(name, day, start, end, participants)
    A2 = Appointment('b', day, start, end, participants)
    A3 = Appointment(name, "Saturday", start, end, participants)
    A4 = Appointment(name, day, "11:00am", end, participants)
    A5 = Appointment(name, day, start, "3:00pm", participants)
    A6 = Appointment(name, day, start, end, [2])
    A7 = Appointment(name, day, start, end, [1,2])
    A8 = Appointment(name, day, "11:00am", "3:00pm", participants)
    
    test_TypeError(A1, None)
    test_TypeError(None, A1)
    #appointment does not conflict with itself
    assert not Appointment._is_conflicting(A1, A1)
    assert Appointment._is_conflicting(A1, A2)
    assert Appointment._is_conflicting(A2, A1)
    assert not Appointment._is_conflicting(A1, A3)
    assert not Appointment._is_conflicting(A3, A1)
    assert Appointment._is_conflicting(A1, A4)
    assert Appointment._is_conflicting(A4, A1)
    assert Appointment._is_conflicting(A1, A5)
    assert Appointment._is_conflicting(A5, A1)
    assert not Appointment._is_conflicting(A1, A6)
    assert not Appointment._is_conflicting(A6, A1)
    assert Appointment._is_conflicting(A1, A7)
    assert Appointment._is_conflicting(A7, A1)
    assert Appointment._is_conflicting(A1, A8)
    assert Appointment._is_conflicting(A8, A1)
コード例 #17
0
def test___repr__():
    """Test ."""
    name, day, start, end, participants = "a", "Friday", "1:00pm", "2:00pm", [1]
    A1 = Appointment(name, day, start, end, participants)
    assert A1.__repr__() == "Appointment \"a\" on Friday from 13:00 to 14:00 with 1"
コード例 #18
0
 def test_TypeError(appt1, appt2):
     """Test TypeError raising during Appointment._is_conflicting()."""
     with pytest.raises(TypeError) as excinfo:
         Appointment._is_conflicting(appt1, appt2)
コード例 #19
0
 def test_TypeError(time):
     """Test TypeError raising during Appointment._parse_time()."""
     with pytest.raises(TypeError) as excinfo:
         Appointment._parse_time(time)
コード例 #20
0
def test___hash__():
    """Test hashing for Appointment object."""
    name, day, start, end, participants = "a", "Friday", "1:00pm", "2:00pm", [1]
    A1 = Appointment(name, day, start, end, participants)
    A2 = Appointment(name, day, start, end, participants)
    assert hash(A1) == hash(A2)
コード例 #21
0
 def test_TypeError(n, d, s, e, p):
     """Test TypeError raising during Appointment object construction."""
     with pytest.raises(TypeError) as excinfo:
         Appointment(n, d, s, e, p)