Skip to content

Commit

Permalink
make ResultContainer iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed May 23, 2024
1 parent 2a9695e commit 708b178
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bfabric/results/result_container.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import logging
from typing import Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING, Iterable

import bfabric.results.response_format_dict as formatter

Expand Down Expand Up @@ -30,6 +30,9 @@ def __init__(
def __getitem__(self, idx: int) -> dict[str, Any]:
return self.results[idx]

def __iter__(self) -> Iterable[dict[str, Any]]:
return iter(self.results)

def __repr__(self) -> str:
return self.__str__()

Expand Down
4 changes: 4 additions & 0 deletions bfabric/tests/unit/test_result_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def test_repr(self):
self.assertEqual("[1, 2, 3]", repr(self.res1))
self.assertEqual("[4, 5]", repr(self.res2))

def test_iter(self):
items = list(iter(self.res1))
self.assertListEqual([1, 2, 3], items)

def test_len(self):
self.assertEqual(3, len(self.res1))
self.assertEqual(2, len(self.res2))
Expand Down

0 comments on commit 708b178

Please sign in to comment.