Skip to content

Commit 5efc206

Browse files
committed
update literal data.draw_bytes calls in tests
1 parent ace043f commit 5efc206

12 files changed

+74
-72
lines changed

hypothesis-python/tests/common/strategies.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class _Slow(SearchStrategy):
2121
def do_draw(self, data):
2222
time.sleep(1.01)
23-
data.draw_bytes(2)
23+
data.draw_bytes(2, 2)
2424

2525

2626
SLOW = _Slow()

hypothesis-python/tests/conjecture/test_data_tree.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def runner(data):
123123
def test_novel_prefixes_are_novel():
124124
def tf(data):
125125
for _ in range(4):
126-
data.draw_bytes(1, forced=b"\0")
126+
data.draw_bytes(1, 1, forced=b"\0")
127127
data.draw_integer(0, 3)
128128

129129
runner = ConjectureRunner(tf, settings=TEST_SETTINGS, random=Random(0))
@@ -137,7 +137,7 @@ def tf(data):
137137

138138
def test_overruns_if_not_enough_bytes_for_block():
139139
runner = ConjectureRunner(
140-
lambda data: data.draw_bytes(2), settings=TEST_SETTINGS, random=Random(0)
140+
lambda data: data.draw_bytes(2, 2), settings=TEST_SETTINGS, random=Random(0)
141141
)
142142
runner.cached_test_function(b"\0\0")
143143
assert runner.tree.rewrite(b"\0")[1] == Status.OVERRUN
@@ -328,8 +328,8 @@ def test_truncates_if_seen():
328328
b = bytes([1, 2, 3, 4])
329329

330330
data = ConjectureData.for_buffer(b, observer=tree.new_observer())
331-
data.draw_bytes(1)
332-
data.draw_bytes(1)
331+
data.draw_bytes(1, 1)
332+
data.draw_bytes(1, 1)
333333
data.freeze()
334334

335335
assert tree.rewrite(b) == (b[:2], Status.VALID)
@@ -338,13 +338,13 @@ def test_truncates_if_seen():
338338
def test_child_becomes_exhausted_after_split():
339339
tree = DataTree()
340340
data = ConjectureData.for_buffer([0, 0], observer=tree.new_observer())
341-
data.draw_bytes(1)
342-
data.draw_bytes(1, forced=b"\0")
341+
data.draw_bytes(1, 1)
342+
data.draw_bytes(1, 1, forced=b"\0")
343343
data.freeze()
344344

345345
data = ConjectureData.for_buffer([1, 0], observer=tree.new_observer())
346-
data.draw_bytes(1)
347-
data.draw_bytes(1)
346+
data.draw_bytes(1, 1)
347+
data.draw_bytes(1, 1)
348348
data.freeze()
349349

350350
assert not tree.is_exhausted
@@ -359,7 +359,7 @@ def test_will_generate_novel_prefix_to_avoid_exhausted_branches():
359359

360360
data = ConjectureData.for_buffer([0, 1], observer=tree.new_observer())
361361
data.draw_integer(0, 1)
362-
data.draw_bytes(1)
362+
data.draw_bytes(1, 1)
363363
data.freeze()
364364

365365
prefix = list(tree.generate_novel_prefix(Random(0)))

hypothesis-python/tests/conjecture/test_engine.py

+39-39
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
def test_can_index_results():
5959
@run_to_buffer
6060
def f(data):
61-
data.draw_bytes(5)
61+
data.draw_bytes(5, 5)
6262
data.mark_interesting()
6363

6464
assert f.index(0) == 0
@@ -68,8 +68,8 @@ def f(data):
6868
def test_non_cloneable_intervals():
6969
@run_to_buffer
7070
def x(data):
71-
data.draw_bytes(10)
72-
data.draw_bytes(9)
71+
data.draw_bytes(10, 10)
72+
data.draw_bytes(9, 9)
7373
data.mark_interesting()
7474

7575
assert x == bytes(19)
@@ -79,7 +79,7 @@ def test_deletable_draws():
7979
@run_to_buffer
8080
def x(data):
8181
while True:
82-
x = data.draw_bytes(2)
82+
x = data.draw_bytes(2, 2)
8383
if x[0] == 255:
8484
data.mark_interesting()
8585

@@ -97,7 +97,7 @@ def test_can_load_data_from_a_corpus():
9797
db.save(key, value)
9898

9999
def f(data):
100-
if data.draw_bytes(len(value)) == value:
100+
if data.draw_bytes(len(value), len(value)) == value:
101101
data.mark_interesting()
102102

103103
runner = ConjectureRunner(f, settings=settings(database=db), database_key=key)
@@ -148,7 +148,7 @@ def test_detects_flakiness():
148148
count = [0]
149149

150150
def tf(data):
151-
data.draw_bytes(1)
151+
data.draw_bytes(1, 1)
152152
count[0] += 1
153153
if not failed_once[0]:
154154
failed_once[0] = True
@@ -183,9 +183,9 @@ def draw_list(data):
183183
result = []
184184
while True:
185185
data.start_example(SOME_LABEL)
186-
d = data.draw_bytes(1)[0] & 7
186+
d = data.draw_bytes(1, 1)[0] & 7
187187
if d:
188-
result.append(data.draw_bytes(d))
188+
result.append(data.draw_bytes(d, d))
189189
data.stop_example()
190190
if not d:
191191
break
@@ -204,8 +204,8 @@ def b(data):
204204
def test_draw_to_overrun():
205205
@run_to_buffer
206206
def x(data):
207-
d = (data.draw_bytes(1)[0] - 8) & 0xFF
208-
data.draw_bytes(128 * d)
207+
d = (data.draw_bytes(1, 1)[0] - 8) & 0xFF
208+
data.draw_bytes(128 * d, 128 * d)
209209
if d >= 2:
210210
data.mark_interesting()
211211

@@ -214,8 +214,8 @@ def x(data):
214214

215215
def test_can_navigate_to_a_valid_example():
216216
def f(data):
217-
i = int_from_bytes(data.draw_bytes(2))
218-
data.draw_bytes(i)
217+
i = int_from_bytes(data.draw_bytes(2, 2))
218+
data.draw_bytes(i, i)
219219
data.mark_interesting()
220220

221221
runner = ConjectureRunner(f, settings=settings(max_examples=5000, database=None))
@@ -234,7 +234,7 @@ def test_stops_after_max_examples_when_reading():
234234
seen = []
235235

236236
def f(data):
237-
seen.append(data.draw_bytes(1))
237+
seen.append(data.draw_bytes(1, 1))
238238

239239
runner = ConjectureRunner(
240240
f, settings=settings(max_examples=1, database=db), database_key=key
@@ -247,7 +247,7 @@ def test_stops_after_max_examples_when_generating():
247247
seen = []
248248

249249
def f(data):
250-
seen.append(data.draw_bytes(1))
250+
seen.append(data.draw_bytes(1, 1))
251251

252252
runner = ConjectureRunner(f, settings=settings(max_examples=1, database=None))
253253
runner.run()
@@ -285,10 +285,10 @@ def test_interleaving_engines():
285285

286286
@run_to_buffer
287287
def x(data):
288-
rnd = Random(data.draw_bytes(1))
288+
rnd = Random(data.draw_bytes(1, 1))
289289

290290
def g(d2):
291-
d2.draw_bytes(1)
291+
d2.draw_bytes(1, 1)
292292
data.mark_interesting()
293293

294294
runner = ConjectureRunner(g, random=rnd)
@@ -306,7 +306,7 @@ def test_phases_can_disable_shrinking():
306306
seen = set()
307307

308308
def f(data):
309-
seen.add(bytes(data.draw_bytes(32)))
309+
seen.add(bytes(data.draw_bytes(32, 32)))
310310
data.mark_interesting()
311311

312312
runner = ConjectureRunner(
@@ -342,8 +342,8 @@ def test_erratic_draws():
342342

343343
@run_to_buffer
344344
def x(data):
345-
data.draw_bytes(n[0])
346-
data.draw_bytes(255 - n[0])
345+
data.draw_bytes(n[0], n[0])
346+
data.draw_bytes(255 - n[0], 255 - n[0])
347347
if n[0] == 255:
348348
data.mark_interesting()
349349
else:
@@ -368,10 +368,10 @@ def test_one_dead_branch():
368368

369369
@run_to_buffer
370370
def x(data):
371-
i = data.draw_bytes(1)[0]
371+
i = data.draw_bytes(1, 1)[0]
372372
if i > 0:
373373
data.mark_invalid()
374-
i = data.draw_bytes(1)[0]
374+
i = data.draw_bytes(1, 1)[0]
375375
if len(seen) < 255:
376376
seen.add(i)
377377
elif i not in seen:
@@ -398,7 +398,7 @@ def test_returns_written():
398398

399399
@run_to_buffer
400400
def written(data):
401-
data.draw_bytes(len(value), forced=value)
401+
data.draw_bytes(len(value), len(value), forced=value)
402402
data.mark_interesting()
403403

404404
assert value == written
@@ -424,21 +424,21 @@ def accept(f):
424424
def test_fails_health_check_for_all_invalid():
425425
@fails_health_check(HealthCheck.filter_too_much)
426426
def _(data):
427-
data.draw_bytes(2)
427+
data.draw_bytes(2, 2)
428428
data.mark_invalid()
429429

430430

431431
def test_fails_health_check_for_large_base():
432432
@fails_health_check(HealthCheck.large_base_example)
433433
def _(data):
434-
data.draw_bytes(10**6)
434+
data.draw_bytes(10**6, 10**6)
435435

436436

437437
def test_fails_health_check_for_large_non_base():
438438
@fails_health_check(HealthCheck.data_too_large)
439439
def _(data):
440440
if data.draw_integer(0, 2**8 - 1):
441-
data.draw_bytes(10**6)
441+
data.draw_bytes(10**6, 10**6)
442442

443443

444444
def test_fails_health_check_for_slow_draws():
@@ -537,8 +537,8 @@ def test_can_write_bytes_towards_the_end():
537537

538538
def f(data):
539539
if data.draw_boolean():
540-
data.draw_bytes(5)
541-
data.draw_bytes(len(buf), forced=buf)
540+
data.draw_bytes(5, 5)
541+
data.draw_bytes(len(buf), len(buf), forced=buf)
542542
assert data.buffer[-len(buf) :] == buf
543543

544544
with buffer_size_limit(10):
@@ -549,7 +549,7 @@ def test_uniqueness_is_preserved_when_writing_at_beginning():
549549
seen = set()
550550

551551
def f(data):
552-
data.draw_bytes(1, forced=bytes(1))
552+
data.draw_bytes(1, 1, forced=bytes(1))
553553
n = data.draw_integer(0, 2**3 - 1)
554554
assert n not in seen
555555
seen.add(n)
@@ -601,7 +601,7 @@ def test_detects_too_small_block_starts():
601601
def f(data):
602602
assert call_count[0] == 0
603603
call_count[0] += 1
604-
data.draw_bytes(8)
604+
data.draw_bytes(8, 8)
605605
data.mark_interesting()
606606

607607
runner = ConjectureRunner(f, settings=settings(database=None))
@@ -952,7 +952,7 @@ def test_cached_test_function_does_not_reinvoke_on_prefix():
952952
def test_function(data):
953953
call_count[0] += 1
954954
data.draw_integer(0, 2**8 - 1)
955-
data.draw_bytes(1, forced=bytes([7]))
955+
data.draw_bytes(1, 1, forced=bytes([7]))
956956
data.draw_integer(0, 2**8 - 1)
957957

958958
with deterministic_PRNG():
@@ -971,7 +971,7 @@ def test_will_evict_entries_from_the_cache(monkeypatch):
971971
count = [0]
972972

973973
def tf(data):
974-
data.draw_bytes(1)
974+
data.draw_bytes(1, 1)
975975
count[0] += 1
976976

977977
runner = ConjectureRunner(tf, settings=TEST_SETTINGS)
@@ -1421,7 +1421,7 @@ def test(data):
14211421

14221422
def test_does_not_cache_extended_prefix():
14231423
def test(data):
1424-
data.draw_bytes(8)
1424+
data.draw_bytes(8, 8)
14251425

14261426
with deterministic_PRNG():
14271427
runner = ConjectureRunner(test, settings=TEST_SETTINGS)
@@ -1438,7 +1438,7 @@ def test_does_cache_if_extend_is_not_used():
14381438

14391439
def test(data):
14401440
calls[0] += 1
1441-
data.draw_bytes(1)
1441+
data.draw_bytes(1, 1)
14421442

14431443
with deterministic_PRNG():
14441444
runner = ConjectureRunner(test, settings=TEST_SETTINGS)
@@ -1455,7 +1455,7 @@ def test_does_result_for_reuse():
14551455

14561456
def test(data):
14571457
calls[0] += 1
1458-
data.draw_bytes(1)
1458+
data.draw_bytes(1, 1)
14591459

14601460
with deterministic_PRNG():
14611461
runner = ConjectureRunner(test, settings=TEST_SETTINGS)
@@ -1469,7 +1469,7 @@ def test(data):
14691469

14701470
def test_does_not_cache_overrun_if_extending():
14711471
def test(data):
1472-
data.draw_bytes(8)
1472+
data.draw_bytes(8, 8)
14731473

14741474
with deterministic_PRNG():
14751475
runner = ConjectureRunner(test, settings=TEST_SETTINGS)
@@ -1482,8 +1482,8 @@ def test(data):
14821482

14831483
def test_does_cache_overrun_if_not_extending():
14841484
def test(data):
1485-
data.draw_bytes(8)
1486-
data.draw_bytes(8)
1485+
data.draw_bytes(8, 8)
1486+
data.draw_bytes(8, 8)
14871487

14881488
with deterministic_PRNG():
14891489
runner = ConjectureRunner(test, settings=TEST_SETTINGS)
@@ -1496,7 +1496,7 @@ def test(data):
14961496

14971497
def test_does_not_cache_extended_prefix_if_overrun():
14981498
def test(data):
1499-
data.draw_bytes(8)
1499+
data.draw_bytes(8, 8)
15001500

15011501
with deterministic_PRNG():
15021502
runner = ConjectureRunner(test, settings=TEST_SETTINGS)
@@ -1509,7 +1509,7 @@ def test(data):
15091509

15101510
def test_can_be_set_to_ignore_limits():
15111511
def test(data):
1512-
data.draw_bytes(1)
1512+
data.draw_bytes(1, 1)
15131513

15141514
with deterministic_PRNG():
15151515
runner = ConjectureRunner(

hypothesis-python/tests/conjecture/test_ir.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def test_ir_nodes(random):
333333

334334
data.start_example(42)
335335
data.draw_string(IntervalSet.from_string("abcd"), forced="abbcccdddd")
336-
data.draw_bytes(8, forced=bytes(8))
336+
data.draw_bytes(8, 8, forced=bytes(8))
337337
data.stop_example()
338338

339339
data.draw_integer(0, 100, forced=50)

0 commit comments

Comments
 (0)