Fokko commented on code in PR #3454:
URL: https://github.com/apache/iceberg-python/pull/3454#discussion_r3360561702


##########
tests/utils/test_pagination.py:
##########
@@ -0,0 +1,229 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from collections.abc import Callable
+
+from pyiceberg.utils.pagination import PaginationList
+
+
+def _make_pages(pages: list[list[int]]) -> tuple[list[int], str | None, 
list[list[int]]]:
+    """Build (first_page, first_token, remaining_pages) for tests."""
+    tokens = [f"tok{i}" for i in range(len(pages))]
+    first = pages[0]
+    first_token = tokens[1] if len(pages) > 1 else None
+    remaining = pages[1:]
+    return first, first_token, remaining
+
+
+def _make_fetch(remaining: list[list[int]], tokens: list[str | None]) -> 
Callable[[str], tuple[list[int], str | None]]:
+    """Return a fetch callback that yields successive pages."""
+    idx = 0
+
+    def fetch(token: str) -> tuple[list[int], str | None]:
+        nonlocal idx
+        items = remaining[idx]
+        next_tok = tokens[idx]
+        idx += 1
+        return items, next_tok
+
+    return fetch
+
+
+def _simple_pagination_list(
+    pages: list[list[int]],
+) -> tuple[PaginationList[int], list[int]]:
+    """Build a PaginationList and return it with the full expected items."""
+    all_items = [item for page in pages for item in page]
+    next_tokens = [f"tok{i}" for i in range(1, len(pages))] + [None]
+
+    call_count = 0
+
+    def fetch(token: str) -> tuple[list[int], str | None]:
+        nonlocal call_count
+        # Pages are accessed in order starting from page index 1.
+        page_idx = int(token.replace("tok", ""))
+        call_count += 1
+        return pages[page_idx], next_tokens[page_idx]
+
+    first_token = "tok1" if len(pages) > 1 else None
+    pl = PaginationList(pages[0], first_token, fetch)
+    return pl, all_items
+
+
+class TestPaginationListSinglePage:

Review Comment:
   We don't use classes in the tests for the rest, and I think it would be good 
to keep that consistent



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to