Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/hypothesis/internal/conjecture/shrinking/bytes.py: 80%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

5 statements  

1# This file is part of Hypothesis, which may be found at 

2# https://github.com/HypothesisWorks/hypothesis/ 

3# 

4# Copyright the Hypothesis Authors. 

5# Individual contributors are listed in AUTHORS.rst and the git log. 

6# 

7# This Source Code Form is subject to the terms of the Mozilla Public License, 

8# v. 2.0. If a copy of the MPL was not distributed with this file, You can 

9# obtain one at https://mozilla.org/MPL/2.0/. 

10 

11from hypothesis.internal.compat import int_from_bytes, int_to_bytes 

12from hypothesis.internal.conjecture.shrinking.integer import Integer 

13 

14 

15class Bytes(Integer): 

16 def __init__(self, initial, predicate, **kwargs): 

17 # shrink by interpreting the bytes as an integer. 

18 # move to Collection.shrink when we support variable-size bytes, 

19 # because b'\x00\x02' could shrink to either b'\x00\x01' or b'\x02'. 

20 super().__init__( 

21 int_from_bytes(initial), 

22 lambda n: predicate(int_to_bytes(n, len(initial))), 

23 **kwargs, 

24 )