Coverage for /pythoncovmergedfiles/medio/medio/src/jsonschema/jsonschema/tests/fuzz_validate.py: 43%

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

28 statements  

1###### Coverage stub 

2import atexit 

3import coverage 

4cov = coverage.coverage(data_file='.coverage', cover_pylib=True) 

5cov.start() 

6# Register an exist handler that will print coverage 

7def exit_handler(): 

8 cov.stop() 

9 cov.save() 

10atexit.register(exit_handler) 

11####### End of coverage stub 

12""" 

13Fuzzing setup for OSS-Fuzz. 

14 

15See https://github.com/google/oss-fuzz/tree/master/projects/jsonschema for the 

16other half of the setup here. 

17""" 

18import sys 

19 

20from hypothesis import given, strategies 

21 

22import jsonschema 

23 

24PRIM = strategies.one_of( 

25 strategies.booleans(), 

26 strategies.integers(), 

27 strategies.floats(allow_nan=False, allow_infinity=False), 

28 strategies.text(), 

29) 

30DICT = strategies.recursive( 

31 base=strategies.one_of( 

32 strategies.booleans(), 

33 strategies.dictionaries(strategies.text(), PRIM), 

34 ), 

35 extend=lambda inner: strategies.dictionaries(strategies.text(), inner), 

36) 

37 

38 

39@given(obj1=DICT, obj2=DICT) 

40def test_schemas(obj1, obj2): 

41 try: 

42 jsonschema.validate(instance=obj1, schema=obj2) 

43 except jsonschema.exceptions.ValidationError: 

44 pass 

45 except jsonschema.exceptions.SchemaError: 

46 pass 

47 

48 

49def main(): 

50 atheris.instrument_all() 

51 atheris.Setup( 

52 sys.argv, 

53 test_schemas.hypothesis.fuzz_one_input, 

54 enable_python_coverage=True, 

55 ) 

56 atheris.Fuzz() 

57 

58 

59if __name__ == "__main__": 

60 import atheris 

61 main()