Total Complexity | 7 |
Total Lines | 26 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from fastest.fuzzers.primitive_fuzzer.fuzz import random_integers, random_ascii_chars, random_float |
||
2 | |||
3 | |||
4 | def build_empty_of_type(item_type): |
||
5 | empty_values_for_types = { |
||
6 | "str": random_ascii_chars, |
||
7 | "int": random_integers, |
||
8 | "float": random_float, |
||
9 | "list": lambda: [], |
||
10 | "dict": lambda: {} |
||
11 | } |
||
12 | return empty_values_for_types[item_type] |
||
13 | |||
14 | |||
15 | def schema_to_object_builder(schema, name='__root__'): |
||
16 | root_object = build_empty_of_type(schema['type'])() |
||
17 | |||
18 | if schema['type'] == 'list': |
||
19 | root_object.append(schema_to_object_builder(schema['inner'])) |
||
20 | |||
21 | elif schema['type'] == 'dict': |
||
22 | for prop in schema['inner']: |
||
23 | root_object[prop['name']] = schema_to_object_builder(prop) |
||
24 | |||
25 | return root_object |
||
26 |