Skip to content

Commit 173a490

Browse files
Abel Milashclaude
andcommitted
Replace B shorthand with _MULTIPLE_BATCH_SIZE in chunking tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 61a9ee1 commit 173a490

1 file changed

Lines changed: 48 additions & 49 deletions

File tree

tests/unit/data/test_multiple_chunking.py

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def _mock_update_response():
5151
return resp
5252

5353

54-
B = _MULTIPLE_BATCH_SIZE # shorthand used throughout
5554

5655

5756
# ---------------------------------------------------------------------------
@@ -88,41 +87,41 @@ def test_one_record_single_request(self):
8887

8988
def test_batch_minus_one_single_request(self):
9089
"""B-1 records fit in one chunk."""
91-
ids = [f"id-{i}" for i in range(B - 1)]
92-
result = self._run(B - 1, [_mock_create_response(ids)])
90+
ids = [f"id-{i}" for i in range(_MULTIPLE_BATCH_SIZE - 1)]
91+
result = self._run(_MULTIPLE_BATCH_SIZE - 1, [_mock_create_response(ids)])
9392
self.od._execute_raw.assert_called_once()
94-
self.assertEqual(len(result), B - 1)
93+
self.assertEqual(len(result), _MULTIPLE_BATCH_SIZE - 1)
9594

9695
def test_exact_batch_size_single_request(self):
97-
"""Exactly B records → one chunk, one request."""
98-
ids = [f"id-{i}" for i in range(B)]
99-
result = self._run(B, [_mock_create_response(ids)])
96+
"""Exactly _MULTIPLE_BATCH_SIZE records → one chunk, one request."""
97+
ids = [f"id-{i}" for i in range(_MULTIPLE_BATCH_SIZE)]
98+
result = self._run(_MULTIPLE_BATCH_SIZE, [_mock_create_response(ids)])
10099
self.od._execute_raw.assert_called_once()
101-
self.assertEqual(len(result), B)
100+
self.assertEqual(len(result), _MULTIPLE_BATCH_SIZE)
102101

103102
def test_batch_plus_one_two_requests(self):
104103
"""B+1 records → two chunks, two requests."""
105-
ids1 = [f"id-{i}" for i in range(B)]
104+
ids1 = [f"id-{i}" for i in range(_MULTIPLE_BATCH_SIZE)]
106105
ids2 = ["id-last"]
107-
result = self._run(B + 1, [_mock_create_response(ids1), _mock_create_response(ids2)])
106+
result = self._run(_MULTIPLE_BATCH_SIZE + 1, [_mock_create_response(ids1), _mock_create_response(ids2)])
108107
self.assertEqual(self.od._execute_raw.call_count, 2)
109-
self.assertEqual(len(result), B + 1)
108+
self.assertEqual(len(result), _MULTIPLE_BATCH_SIZE + 1)
110109

111110
def test_two_full_batches(self):
112-
"""2*B records → two full chunks."""
113-
ids1 = [f"id-{i}" for i in range(B)]
114-
ids2 = [f"id-{i}" for i in range(B, 2 * B)]
115-
result = self._run(2 * B, [_mock_create_response(ids1), _mock_create_response(ids2)])
111+
"""2*_MULTIPLE_BATCH_SIZE records → two full chunks."""
112+
ids1 = [f"id-{i}" for i in range(_MULTIPLE_BATCH_SIZE)]
113+
ids2 = [f"id-{i}" for i in range(_MULTIPLE_BATCH_SIZE, 2 * _MULTIPLE_BATCH_SIZE)]
114+
result = self._run(2 * _MULTIPLE_BATCH_SIZE, [_mock_create_response(ids1), _mock_create_response(ids2)])
116115
self.assertEqual(self.od._execute_raw.call_count, 2)
117-
self.assertEqual(len(result), 2 * B)
116+
self.assertEqual(len(result), 2 * _MULTIPLE_BATCH_SIZE)
118117

119118
def test_two_batches_plus_one(self):
120-
"""2*B+1 records → three chunks."""
121-
se = [_mock_create_response([f"id-{j}" for j in range(B)]) for _ in range(2)]
119+
"""2*_MULTIPLE_BATCH_SIZE+1 records → three chunks."""
120+
se = [_mock_create_response([f"id-{j}" for j in range(_MULTIPLE_BATCH_SIZE)]) for _ in range(2)]
122121
se.append(_mock_create_response(["id-extra"]))
123-
result = self._run(2 * B + 1, se)
122+
result = self._run(2 * _MULTIPLE_BATCH_SIZE + 1, se)
124123
self.assertEqual(self.od._execute_raw.call_count, 3)
125-
self.assertEqual(len(result), 2 * B + 1)
124+
self.assertEqual(len(result), 2 * _MULTIPLE_BATCH_SIZE + 1)
126125

127126

128127
class TestCreateMultipleChunkPayloads(unittest.TestCase):
@@ -139,8 +138,8 @@ def _captured_targets(self, call_index):
139138
return None # handled in test below
140139

141140
def test_first_chunk_has_batch_size_records(self):
142-
"""The first chunk sent to the server has exactly B records."""
143-
records = [{"name": f"R{i}"} for i in range(B + 50)]
141+
"""The first chunk sent to the server has exactly _MULTIPLE_BATCH_SIZE records."""
142+
records = [{"name": f"R{i}"} for i in range(_MULTIPLE_BATCH_SIZE + 50)]
144143
self.od._execute_raw = MagicMock(return_value=_mock_create_response([]))
145144

146145
captured = []
@@ -154,12 +153,12 @@ def capturing_build(entity_set, table, chunk):
154153
self.od._build_create_multiple = capturing_build
155154
self.od._create_multiple("accounts", "account", records)
156155

157-
self.assertEqual(captured[0], B)
156+
self.assertEqual(captured[0], _MULTIPLE_BATCH_SIZE)
158157
self.assertEqual(captured[1], 50)
159158

160159
def test_chunks_cover_all_records_no_overlap(self):
161160
"""All input records appear in exactly one chunk, no duplicates or gaps."""
162-
n = B + 7
161+
n = _MULTIPLE_BATCH_SIZE + 7
163162
records = [{"name": f"R{i}", "idx": i} for i in range(n)]
164163
self.od._execute_raw = MagicMock(return_value=_mock_create_response([]))
165164

@@ -191,7 +190,7 @@ def test_sequential_ids_preserved_in_order(self):
191190
side_effect=[_mock_create_response(ids1), _mock_create_response(ids2)]
192191
)
193192
result = self.od._create_multiple(
194-
"accounts", "account", [{"name": f"R{i}"} for i in range(B + 1)]
193+
"accounts", "account", [{"name": f"R{i}"} for i in range(_MULTIPLE_BATCH_SIZE + 1)]
195194
)
196195
self.assertEqual(result[:2], ["a1", "a2"])
197196
self.assertIn("b1", result)
@@ -203,7 +202,7 @@ def test_empty_ids_from_chunk_still_aggregated(self):
203202
side_effect=[_mock_create_response([]), _mock_create_response(["id-1"])]
204203
)
205204
result = self.od._create_multiple(
206-
"accounts", "account", [{"name": f"R{i}"} for i in range(B + 1)]
205+
"accounts", "account", [{"name": f"R{i}"} for i in range(_MULTIPLE_BATCH_SIZE + 1)]
207206
)
208207
self.assertEqual(result, ["id-1"])
209208

@@ -220,7 +219,7 @@ def test_value_fallback_response_still_aggregated(self):
220219

221220
self.od._execute_raw = MagicMock(side_effect=[resp1, resp2])
222221
result = self.od._create_multiple(
223-
"accounts", "account", [{"name": f"R{i}"} for i in range(B + 1)]
222+
"accounts", "account", [{"name": f"R{i}"} for i in range(_MULTIPLE_BATCH_SIZE + 1)]
224223
)
225224
self.assertIn("a1", result)
226225

@@ -259,23 +258,23 @@ def test_one_record_single_request(self):
259258
self.od._execute_raw.assert_called_once()
260259

261260
def test_batch_minus_one_single_request(self):
262-
self.od._update_multiple("accounts", "account", self._records(B - 1))
261+
self.od._update_multiple("accounts", "account", self._records(_MULTIPLE_BATCH_SIZE - 1))
263262
self.od._execute_raw.assert_called_once()
264263

265264
def test_exact_batch_single_request(self):
266-
self.od._update_multiple("accounts", "account", self._records(B))
265+
self.od._update_multiple("accounts", "account", self._records(_MULTIPLE_BATCH_SIZE))
267266
self.od._execute_raw.assert_called_once()
268267

269268
def test_batch_plus_one_two_requests(self):
270-
self.od._update_multiple("accounts", "account", self._records(B + 1))
269+
self.od._update_multiple("accounts", "account", self._records(_MULTIPLE_BATCH_SIZE + 1))
271270
self.assertEqual(self.od._execute_raw.call_count, 2)
272271

273272
def test_two_full_batches(self):
274-
self.od._update_multiple("accounts", "account", self._records(2 * B))
273+
self.od._update_multiple("accounts", "account", self._records(2 * _MULTIPLE_BATCH_SIZE))
275274
self.assertEqual(self.od._execute_raw.call_count, 2)
276275

277276
def test_two_batches_plus_one(self):
278-
self.od._update_multiple("accounts", "account", self._records(2 * B + 1))
277+
self.od._update_multiple("accounts", "account", self._records(2 * _MULTIPLE_BATCH_SIZE + 1))
279278
self.assertEqual(self.od._execute_raw.call_count, 3)
280279

281280

@@ -287,8 +286,8 @@ def setUp(self):
287286
self.od._execute_raw = MagicMock(return_value=_mock_update_response())
288287

289288
def test_first_chunk_size_is_batch_size(self):
290-
"""First chunk has exactly B records."""
291-
n = B + 17
289+
"""First chunk has exactly _MULTIPLE_BATCH_SIZE records."""
290+
n = _MULTIPLE_BATCH_SIZE + 17
292291
records = [{"accountid": f"id-{i}", "name": f"N{i}"} for i in range(n)]
293292
captured = []
294293
original = self.od._build_update_multiple_from_records
@@ -299,12 +298,12 @@ def capturing(entity_set, table, chunk):
299298

300299
self.od._build_update_multiple_from_records = capturing
301300
self.od._update_multiple("accounts", "account", records)
302-
self.assertEqual(captured[0], B)
301+
self.assertEqual(captured[0], _MULTIPLE_BATCH_SIZE)
303302
self.assertEqual(captured[1], 17)
304303

305304
def test_records_are_not_duplicated_or_dropped(self):
306305
"""All input IDs appear exactly once across all chunks."""
307-
n = B + 3
306+
n = _MULTIPLE_BATCH_SIZE + 3
308307
records = [{"accountid": f"id-{i}", "name": f"N{i}"} for i in range(n)]
309308
seen_ids = []
310309
original = self.od._build_update_multiple_from_records
@@ -366,26 +365,26 @@ def test_one_record_single_request(self):
366365
self.od._request.assert_called_once()
367366

368367
def test_batch_minus_one_single_request(self):
369-
n = B - 1
368+
n = _MULTIPLE_BATCH_SIZE - 1
370369
self.od._upsert_multiple("accounts", "account", _alt_keys(n), _upsert_records(n))
371370
self.od._request.assert_called_once()
372371

373372
def test_exact_batch_single_request(self):
374-
self.od._upsert_multiple("accounts", "account", _alt_keys(B), _upsert_records(B))
373+
self.od._upsert_multiple("accounts", "account", _alt_keys(_MULTIPLE_BATCH_SIZE), _upsert_records(_MULTIPLE_BATCH_SIZE))
375374
self.od._request.assert_called_once()
376375

377376
def test_batch_plus_one_two_requests(self):
378-
n = B + 1
377+
n = _MULTIPLE_BATCH_SIZE + 1
379378
self.od._upsert_multiple("accounts", "account", _alt_keys(n), _upsert_records(n))
380379
self.assertEqual(self.od._request.call_count, 2)
381380

382381
def test_two_full_batches(self):
383-
n = 2 * B
382+
n = 2 * _MULTIPLE_BATCH_SIZE
384383
self.od._upsert_multiple("accounts", "account", _alt_keys(n), _upsert_records(n))
385384
self.assertEqual(self.od._request.call_count, 2)
386385

387386
def test_two_batches_plus_one(self):
388-
n = 2 * B + 1
387+
n = 2 * _MULTIPLE_BATCH_SIZE + 1
389388
self.od._upsert_multiple("accounts", "account", _alt_keys(n), _upsert_records(n))
390389
self.assertEqual(self.od._request.call_count, 3)
391390

@@ -398,25 +397,25 @@ def setUp(self):
398397
self.od._request.return_value = MagicMock()
399398

400399
def test_first_chunk_has_batch_size_targets(self):
401-
"""First POST body has exactly B Targets."""
402-
n = B + 10
400+
"""First POST body has exactly _MULTIPLE_BATCH_SIZE Targets."""
401+
n = _MULTIPLE_BATCH_SIZE + 10
403402
self.od._upsert_multiple("accounts", "account", _alt_keys(n), _upsert_records(n))
404403
first_call = self.od._request.call_args_list[0]
405404
targets = first_call.kwargs["json"]["Targets"]
406-
self.assertEqual(len(targets), B)
405+
self.assertEqual(len(targets), _MULTIPLE_BATCH_SIZE)
407406

408407
def test_last_chunk_has_remainder_targets(self):
409408
"""Last POST body has the remainder."""
410409
remainder = 7
411-
n = B + remainder
410+
n = _MULTIPLE_BATCH_SIZE + remainder
412411
self.od._upsert_multiple("accounts", "account", _alt_keys(n), _upsert_records(n))
413412
last_call = self.od._request.call_args_list[-1]
414413
targets = last_call.kwargs["json"]["Targets"]
415414
self.assertEqual(len(targets), remainder)
416415

417416
def test_all_targets_sent_no_duplicates(self):
418417
"""All accountnumber values appear exactly once across all chunks."""
419-
n = B + 5
418+
n = _MULTIPLE_BATCH_SIZE + 5
420419
self.od._upsert_multiple("accounts", "account", _alt_keys(n), _upsert_records(n))
421420
all_numbers = []
422421
for c in self.od._request.call_args_list:
@@ -428,7 +427,7 @@ def test_all_targets_sent_no_duplicates(self):
428427

429428
def test_odata_type_injected_in_each_target(self):
430429
"""@odata.type is injected into every target in every chunk."""
431-
n = B + 2
430+
n = _MULTIPLE_BATCH_SIZE + 2
432431
self.od._upsert_multiple("accounts", "account", _alt_keys(n), _upsert_records(n))
433432
for c in self.od._request.call_args_list:
434433
for t in c.kwargs["json"]["Targets"]:
@@ -437,7 +436,7 @@ def test_odata_type_injected_in_each_target(self):
437436

438437
def test_post_url_uses_upsert_multiple_action(self):
439438
"""Every chunk is POSTed to the UpsertMultiple action URL."""
440-
n = B + 1
439+
n = _MULTIPLE_BATCH_SIZE + 1
441440
self.od._upsert_multiple("accounts", "account", _alt_keys(n), _upsert_records(n))
442441
for c in self.od._request.call_args_list:
443442
self.assertIn("UpsertMultiple", c.args[1])
@@ -468,7 +467,7 @@ def test_key_conflict_raises_value_error(self):
468467

469468
def test_large_batch_with_conflict_in_second_chunk_raises(self):
470469
"""Conflict detection happens before chunking so it catches errors in any position."""
471-
n = B + 1
470+
n = _MULTIPLE_BATCH_SIZE + 1
472471
alt_keys = _alt_keys(n)
473472
records = _upsert_records(n)
474473
# Inject a conflict in the last record (would be in the second chunk)

0 commit comments

Comments
 (0)