code: def test_scan_efficient_limiting(
      monkeypatch: pytest.MonkeyPatch,
      limit,
      gutenberg_spacy_ner,
      load_method,
  ):
      method = load_method()
      batch_size = 10
  
      # Monkeypatch the .post() call to track with what URLs the server is called
      called_paths = []
      original_post = active_api().http_client.post
  
      def tracked_post(path, *args, **kwargs):
          called_paths.append(path)
          return original_post(path, *args, **kwargs)
  
      monkeypatch.setattr(
          active_api().http_client, "post", tracked_post
      )
  
      # Try to fetch `limit` samples from the 100
      data = method(
          name=gutenberg_spacy_ner, limit=limit, batch_size=10
      )
      data = list(data)
  
      # Ensure that `limit` samples were indeed fetched
      assert len(data) == limit
      # Ensure that the samples were fetched in the expected number of requests
      # Equivalent to math.upper(limit / batch_size):
      assert len(called_paths) == (limit - 1) // batch_size + 1
  
      if limit % batch_size == 0:
          # If limit is divisible by batch_size, then we expect all calls to have a limit of batch_size
          assert all(
              path.endswith(f"?limit={batch_size}")
              for path in called_paths
          )
      else:
          # Otherwise, expect all calls except for the last one to have a limit of batch_size
          # while the last one has limit limit % batch_size
          assert all(
              path.endswith(f"?limit={batch_size}")
              for path in called_paths[:-1]
          )
          assert called_paths[-1].endswith(
              f"?limit={limit % batch_size}"
          )
  
file_path: argilla/tests/integration/client/test_scan_raw_records.py
imports: import pytest
  from argilla.client.api import load
  from argilla.client.sdk.token_classification.models import TokenClassificationRecord
  from argilla.client.singleton import active_api
label_desc: Use image node_id 5 for calling a global function with example usage: test_scan_efficient_limiting(monkeypatch, limit, gutenberg_spacy_ner, load_method) and returns: original_post