示例#1
0
def test_append():
    p = MockProperty()
    o = object()
    c = collection(p, o, str)
    c.append("s")

    assert p.values == [(o, "s")]
示例#2
0
def test_count():
    c = collection(None, None, int)
    c.items = [1, 2, 2]  # type: ignore[assignment]

    assert c.count(1) == 1
    assert c.count(2) == 2
    assert c.count(3) == 0
示例#3
0
def test_swap():
    o = MockElement()
    c: collection[str] = collection(None, o, str)
    c.items = ["a", "b", "c"]  # type: ignore[assignment]
    c.swap("a", "c")
    assert c.items == ["c", "b", "a"]
    assert o.events
示例#4
0
 def _get_many(self, obj) -> collection[T]:
     v: Optional[collection[T]] = getattr(obj, self._name, None)
     if v is None:
         # Create the empty collection here since it might
         # be used to add.
         v = collection(self, obj, self.type)
         setattr(obj, self._name, v)
     return v
示例#5
0
def test_select():
    c = collection(None, None, int)
    c.items = [1, 2]  # type: ignore[assignment]

    assert c.select(lambda e: e > 1) == [2]
示例#6
0
def test_excludesAll():
    c = collection(None, None, int)
    c.items = [1, 2]  # type: ignore[assignment]

    assert not c.excludesAll([1])
    assert c.excludesAll([3])
示例#7
0
def test_includes():
    c = collection(None, None, int)
    c.items = [1, 2]  # type: ignore[assignment]

    assert c.includes(1)
    assert not c.includes(3)
示例#8
0
def test_size():
    c = collection(None, None, int)
    c.items = [1, 2]  # type: ignore[assignment]

    assert c.size() == 2
示例#9
0
def test_append_wrong_type():
    c = collection(None, None, int)

    with pytest.raises(TypeError):
        c.append("s")  # type: ignore[arg-type]
示例#10
0
def test_not_empty():
    c: collection[int] = collection(None, None, int)
    c.items = [1, 2, 3]  # type: ignore[assignment]

    assert not c.isEmpty()
示例#11
0
def test_empty():
    c = collection(None, None, int)

    assert c.isEmpty()
示例#12
0
def test_collect():
    c = collection(None, None, int)
    c.items = [1, 2, 3]  # type: ignore[assignment]

    assert c.collect(lambda e: e * e) == [1, 4, 9]