Skip to main content

Customisable random dictionary generator for fuzz testing

Project description

dictgen

Generate random Python dictionaries for testing.

import dictgen
dictgen.generate()

### Outputs
{
    "": [
        280633528141071517,
        [
            -4279251701116042058
        ]
    ],
    "X": 957269515550119532
}

Control the number of keys allowed at a single level in the library using max_height.

import dictgen
dictgen.generate(max_height=2)

### Outputs
{
    "PZ70": "BD3X3",
    "M6": {}
}

dictgen.generate(max_height=5)

### Outputs
{
    "PZ70": "BD3X3",
    "M6": {},
    123 : None,
    "B1223S3S": [9243, None],
    "XLXSM35PW3": "1AHLFB06"
}

Control the maximum number of nested dictionaries and arrays using max_depth.

print( dictgen.generate(max_depth=3) )

### Outputs
{
    "POARS2": 2.6720361072638525e+18,
    "6": {
        "BZVADP": -1.646104091641211e+18,
        "V": []
    }
}

You can reproduce the same dictionary consistently using the seed parameter.

dictgen.generate(rand_seed=1)

### Outputs
{'4YNG5BY': -7.048155888731118e+18}

dictgen.generate(rand_seed=1)

### Outputs
{'4YNG5BY': -7.048155888731118e+18}

You can control the different functions that are used to generate your dictionaries.

key_generators, val_generators, nested_generators arguments

# Generate a dictionary with only strings as keys and values
dictgen.generate(key_generators=(dictgen.random_string,), val_generators=(dictgen.random_string,))

### Outputs
{'QM':
    {
        '57S': 'MBBO6XZP',
        '': '5WWU8AY'
    },
    '': [{'M0ISLL4': '8'}, 'XE0'],
    'EHEOL1I5': {}
}

# Generate a dictionary with a custom generator method
from uuid import uuid4

def generate_uuid(**kwargs):
    return uuid4()

dictgen.generate(key_generators=(generate_uuid,), val_generators=(dictgen.random_string,))

### Outputs
{UUID('2f85cf3e-b8f4-4750-ac3d-8ce84b9f7ed1'): [[]], UUID('a840fd05-daba-49ce-a695-fad8c1fd3675'): 'EeuM0N', UUID('6dab8e6d-35f1-479e-8763-b671b46a86b0'): 'aj'}

Examples

./examples/fuzz_tomlkit.py - an example of fuzz testing a popular toml encoder library

...

Test 5 -------------
test_data: {'HX': [[]], 'YiG': datetime.time(15, 55)}
result:
HX = [[]]
YiG = 15:55:00

CONTRIBUTING

Make sure all unit tests are passing

pip install -e .
python -m unittest

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dictgen-0.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dictgen-0.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file dictgen-0.1.tar.gz.

File metadata

  • Download URL: dictgen-0.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for dictgen-0.1.tar.gz
Algorithm Hash digest
SHA256 5679330a2242dc7b81dca8f7827ef22e9a89eb7840ab79b686fce7f7cf5b2c88
MD5 852566af16844048b15a9026c37c881d
BLAKE2b-256 b65f45aa3195529b6e867efa1fde8b7067e181f8f109cdec8eacf0833f9083c4

See more details on using hashes here.

File details

Details for the file dictgen-0.1-py3-none-any.whl.

File metadata

  • Download URL: dictgen-0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for dictgen-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1bb61114552f8c604511ae392ce6049f4719498ee50bfde0c192f9e763d0dac1
MD5 03d9aa0e2a537b584c397ec3c822831c
BLAKE2b-256 67b102b1b6c7ae1857d58384e8bd1007aaf94c0914c37ece29f7548bde5f142b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page