58
58
def test_can_index_results ():
59
59
@run_to_buffer
60
60
def f (data ):
61
- data .draw_bytes (5 )
61
+ data .draw_bytes (5 , 5 )
62
62
data .mark_interesting ()
63
63
64
64
assert f .index (0 ) == 0
@@ -68,8 +68,8 @@ def f(data):
68
68
def test_non_cloneable_intervals ():
69
69
@run_to_buffer
70
70
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 )
73
73
data .mark_interesting ()
74
74
75
75
assert x == bytes (19 )
@@ -79,7 +79,7 @@ def test_deletable_draws():
79
79
@run_to_buffer
80
80
def x (data ):
81
81
while True :
82
- x = data .draw_bytes (2 )
82
+ x = data .draw_bytes (2 , 2 )
83
83
if x [0 ] == 255 :
84
84
data .mark_interesting ()
85
85
@@ -97,7 +97,7 @@ def test_can_load_data_from_a_corpus():
97
97
db .save (key , value )
98
98
99
99
def f (data ):
100
- if data .draw_bytes (len (value )) == value :
100
+ if data .draw_bytes (len (value ), len ( value ) ) == value :
101
101
data .mark_interesting ()
102
102
103
103
runner = ConjectureRunner (f , settings = settings (database = db ), database_key = key )
@@ -148,7 +148,7 @@ def test_detects_flakiness():
148
148
count = [0 ]
149
149
150
150
def tf (data ):
151
- data .draw_bytes (1 )
151
+ data .draw_bytes (1 , 1 )
152
152
count [0 ] += 1
153
153
if not failed_once [0 ]:
154
154
failed_once [0 ] = True
@@ -183,9 +183,9 @@ def draw_list(data):
183
183
result = []
184
184
while True :
185
185
data .start_example (SOME_LABEL )
186
- d = data .draw_bytes (1 )[0 ] & 7
186
+ d = data .draw_bytes (1 , 1 )[0 ] & 7
187
187
if d :
188
- result .append (data .draw_bytes (d ))
188
+ result .append (data .draw_bytes (d , d ))
189
189
data .stop_example ()
190
190
if not d :
191
191
break
@@ -204,8 +204,8 @@ def b(data):
204
204
def test_draw_to_overrun ():
205
205
@run_to_buffer
206
206
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 )
209
209
if d >= 2 :
210
210
data .mark_interesting ()
211
211
@@ -214,8 +214,8 @@ def x(data):
214
214
215
215
def test_can_navigate_to_a_valid_example ():
216
216
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 )
219
219
data .mark_interesting ()
220
220
221
221
runner = ConjectureRunner (f , settings = settings (max_examples = 5000 , database = None ))
@@ -234,7 +234,7 @@ def test_stops_after_max_examples_when_reading():
234
234
seen = []
235
235
236
236
def f (data ):
237
- seen .append (data .draw_bytes (1 ))
237
+ seen .append (data .draw_bytes (1 , 1 ))
238
238
239
239
runner = ConjectureRunner (
240
240
f , settings = settings (max_examples = 1 , database = db ), database_key = key
@@ -247,7 +247,7 @@ def test_stops_after_max_examples_when_generating():
247
247
seen = []
248
248
249
249
def f (data ):
250
- seen .append (data .draw_bytes (1 ))
250
+ seen .append (data .draw_bytes (1 , 1 ))
251
251
252
252
runner = ConjectureRunner (f , settings = settings (max_examples = 1 , database = None ))
253
253
runner .run ()
@@ -285,10 +285,10 @@ def test_interleaving_engines():
285
285
286
286
@run_to_buffer
287
287
def x (data ):
288
- rnd = Random (data .draw_bytes (1 ))
288
+ rnd = Random (data .draw_bytes (1 , 1 ))
289
289
290
290
def g (d2 ):
291
- d2 .draw_bytes (1 )
291
+ d2 .draw_bytes (1 , 1 )
292
292
data .mark_interesting ()
293
293
294
294
runner = ConjectureRunner (g , random = rnd )
@@ -306,7 +306,7 @@ def test_phases_can_disable_shrinking():
306
306
seen = set ()
307
307
308
308
def f (data ):
309
- seen .add (bytes (data .draw_bytes (32 )))
309
+ seen .add (bytes (data .draw_bytes (32 , 32 )))
310
310
data .mark_interesting ()
311
311
312
312
runner = ConjectureRunner (
@@ -342,8 +342,8 @@ def test_erratic_draws():
342
342
343
343
@run_to_buffer
344
344
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 ] )
347
347
if n [0 ] == 255 :
348
348
data .mark_interesting ()
349
349
else :
@@ -368,10 +368,10 @@ def test_one_dead_branch():
368
368
369
369
@run_to_buffer
370
370
def x (data ):
371
- i = data .draw_bytes (1 )[0 ]
371
+ i = data .draw_bytes (1 , 1 )[0 ]
372
372
if i > 0 :
373
373
data .mark_invalid ()
374
- i = data .draw_bytes (1 )[0 ]
374
+ i = data .draw_bytes (1 , 1 )[0 ]
375
375
if len (seen ) < 255 :
376
376
seen .add (i )
377
377
elif i not in seen :
@@ -398,7 +398,7 @@ def test_returns_written():
398
398
399
399
@run_to_buffer
400
400
def written (data ):
401
- data .draw_bytes (len (value ), forced = value )
401
+ data .draw_bytes (len (value ), len ( value ), forced = value )
402
402
data .mark_interesting ()
403
403
404
404
assert value == written
@@ -424,21 +424,21 @@ def accept(f):
424
424
def test_fails_health_check_for_all_invalid ():
425
425
@fails_health_check (HealthCheck .filter_too_much )
426
426
def _ (data ):
427
- data .draw_bytes (2 )
427
+ data .draw_bytes (2 , 2 )
428
428
data .mark_invalid ()
429
429
430
430
431
431
def test_fails_health_check_for_large_base ():
432
432
@fails_health_check (HealthCheck .large_base_example )
433
433
def _ (data ):
434
- data .draw_bytes (10 ** 6 )
434
+ data .draw_bytes (10 ** 6 , 10 ** 6 )
435
435
436
436
437
437
def test_fails_health_check_for_large_non_base ():
438
438
@fails_health_check (HealthCheck .data_too_large )
439
439
def _ (data ):
440
440
if data .draw_integer (0 , 2 ** 8 - 1 ):
441
- data .draw_bytes (10 ** 6 )
441
+ data .draw_bytes (10 ** 6 , 10 ** 6 )
442
442
443
443
444
444
def test_fails_health_check_for_slow_draws ():
@@ -537,8 +537,8 @@ def test_can_write_bytes_towards_the_end():
537
537
538
538
def f (data ):
539
539
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 )
542
542
assert data .buffer [- len (buf ) :] == buf
543
543
544
544
with buffer_size_limit (10 ):
@@ -549,7 +549,7 @@ def test_uniqueness_is_preserved_when_writing_at_beginning():
549
549
seen = set ()
550
550
551
551
def f (data ):
552
- data .draw_bytes (1 , forced = bytes (1 ))
552
+ data .draw_bytes (1 , 1 , forced = bytes (1 ))
553
553
n = data .draw_integer (0 , 2 ** 3 - 1 )
554
554
assert n not in seen
555
555
seen .add (n )
@@ -601,7 +601,7 @@ def test_detects_too_small_block_starts():
601
601
def f (data ):
602
602
assert call_count [0 ] == 0
603
603
call_count [0 ] += 1
604
- data .draw_bytes (8 )
604
+ data .draw_bytes (8 , 8 )
605
605
data .mark_interesting ()
606
606
607
607
runner = ConjectureRunner (f , settings = settings (database = None ))
@@ -952,7 +952,7 @@ def test_cached_test_function_does_not_reinvoke_on_prefix():
952
952
def test_function (data ):
953
953
call_count [0 ] += 1
954
954
data .draw_integer (0 , 2 ** 8 - 1 )
955
- data .draw_bytes (1 , forced = bytes ([7 ]))
955
+ data .draw_bytes (1 , 1 , forced = bytes ([7 ]))
956
956
data .draw_integer (0 , 2 ** 8 - 1 )
957
957
958
958
with deterministic_PRNG ():
@@ -971,7 +971,7 @@ def test_will_evict_entries_from_the_cache(monkeypatch):
971
971
count = [0 ]
972
972
973
973
def tf (data ):
974
- data .draw_bytes (1 )
974
+ data .draw_bytes (1 , 1 )
975
975
count [0 ] += 1
976
976
977
977
runner = ConjectureRunner (tf , settings = TEST_SETTINGS )
@@ -1421,7 +1421,7 @@ def test(data):
1421
1421
1422
1422
def test_does_not_cache_extended_prefix ():
1423
1423
def test (data ):
1424
- data .draw_bytes (8 )
1424
+ data .draw_bytes (8 , 8 )
1425
1425
1426
1426
with deterministic_PRNG ():
1427
1427
runner = ConjectureRunner (test , settings = TEST_SETTINGS )
@@ -1438,7 +1438,7 @@ def test_does_cache_if_extend_is_not_used():
1438
1438
1439
1439
def test (data ):
1440
1440
calls [0 ] += 1
1441
- data .draw_bytes (1 )
1441
+ data .draw_bytes (1 , 1 )
1442
1442
1443
1443
with deterministic_PRNG ():
1444
1444
runner = ConjectureRunner (test , settings = TEST_SETTINGS )
@@ -1455,7 +1455,7 @@ def test_does_result_for_reuse():
1455
1455
1456
1456
def test (data ):
1457
1457
calls [0 ] += 1
1458
- data .draw_bytes (1 )
1458
+ data .draw_bytes (1 , 1 )
1459
1459
1460
1460
with deterministic_PRNG ():
1461
1461
runner = ConjectureRunner (test , settings = TEST_SETTINGS )
@@ -1469,7 +1469,7 @@ def test(data):
1469
1469
1470
1470
def test_does_not_cache_overrun_if_extending ():
1471
1471
def test (data ):
1472
- data .draw_bytes (8 )
1472
+ data .draw_bytes (8 , 8 )
1473
1473
1474
1474
with deterministic_PRNG ():
1475
1475
runner = ConjectureRunner (test , settings = TEST_SETTINGS )
@@ -1482,8 +1482,8 @@ def test(data):
1482
1482
1483
1483
def test_does_cache_overrun_if_not_extending ():
1484
1484
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 )
1487
1487
1488
1488
with deterministic_PRNG ():
1489
1489
runner = ConjectureRunner (test , settings = TEST_SETTINGS )
@@ -1496,7 +1496,7 @@ def test(data):
1496
1496
1497
1497
def test_does_not_cache_extended_prefix_if_overrun ():
1498
1498
def test (data ):
1499
- data .draw_bytes (8 )
1499
+ data .draw_bytes (8 , 8 )
1500
1500
1501
1501
with deterministic_PRNG ():
1502
1502
runner = ConjectureRunner (test , settings = TEST_SETTINGS )
@@ -1509,7 +1509,7 @@ def test(data):
1509
1509
1510
1510
def test_can_be_set_to_ignore_limits ():
1511
1511
def test (data ):
1512
- data .draw_bytes (1 )
1512
+ data .draw_bytes (1 , 1 )
1513
1513
1514
1514
with deterministic_PRNG ():
1515
1515
runner = ConjectureRunner (
0 commit comments