Пример #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)