def test_append(): p = MockProperty() o = object() c = collection(p, o, str) c.append("s") assert p.values == [(o, "s")]
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
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
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
def test_select(): c = collection(None, None, int) c.items = [1, 2] # type: ignore[assignment] assert c.select(lambda e: e > 1) == [2]
def test_excludesAll(): c = collection(None, None, int) c.items = [1, 2] # type: ignore[assignment] assert not c.excludesAll([1]) assert c.excludesAll([3])
def test_includes(): c = collection(None, None, int) c.items = [1, 2] # type: ignore[assignment] assert c.includes(1) assert not c.includes(3)
def test_size(): c = collection(None, None, int) c.items = [1, 2] # type: ignore[assignment] assert c.size() == 2
def test_append_wrong_type(): c = collection(None, None, int) with pytest.raises(TypeError): c.append("s") # type: ignore[arg-type]
def test_not_empty(): c: collection[int] = collection(None, None, int) c.items = [1, 2, 3] # type: ignore[assignment] assert not c.isEmpty()
def test_empty(): c = collection(None, None, int) assert c.isEmpty()
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]