예제 #1
0
def test_comprehensions_can_be_used_for_filtering_etc():
    start = Til(1, 2, 3, 4)
    assert til(x for x in start if x != 3) == Til(1, 2, 4)
예제 #2
0
def test_the_til_function_also_takes_elements():
    assert til(1, 2, 3) == Til(1, 2, 3)
예제 #3
0
def test_comprehension_style_construction():
    assert til(x for x in range(0, 3)) == Til(0, 1, 2)
예제 #4
0
def test_tils_have_a_length():
    assert len(Til(2, 7, 8)) == 3
예제 #5
0
def test_tils_are_reversible():
    assert reversed(Til(2, 7, 8)) == Til(8, 7, 2)
예제 #6
0
def test_tils_are_iterable():
    assert [x for x in Til(1, 2, 4)] == [1, 2, 4]
예제 #7
0
def test_tils_are_containers():
    assert 2 in Til(1, 2, 4)
예제 #8
0
def test_empty_lists_must_have_a_type():
    with pytest.raises(SyntaxError):
        Til()
예제 #9
0
def test_new_elements_are_type_checked():
    start = Til(3)
    with pytest.raises(TypeError):
        start.append("steve")
예제 #10
0
def test_child_types_may_be_fine_but_parent_types_arent():
    with pytest.raises(TypeError):
        Til(ParentType(), element_type=ChildType)
예제 #11
0
def test_the_type_of_the_list_can_be_set_explicitly():
    with pytest.raises(TypeError):
        Til("three", element_type=int)
예제 #12
0
def test_child_types_are_fine():
    child_element = ChildType()
    assert child_element in Til(ParentType(), child_element, ParentType())
예제 #13
0
def test_the_lists_are_homogenous():
    with pytest.raises(TypeError):
        Til(1, 2, "three")
예제 #14
0
def test_adding_elements_is_immutable():
    start = Til(3)
    end = start.append(5).append(7)
    assert start == Til(3)
    assert end == Til(3, 5, 7)
예제 #15
0
def test_conversion_to_list():
    assert Til(2, 7, 8).as_list() == [2, 7, 8]
예제 #16
0
def test_construction_from_numbers():
    assert Til(2, 7, 8) == Til(2, 7, 8)