Skip to main content

Build fixtures from a single source

Project description

Install

$ pip install fixturebuilder

Usage

# define the data structure to be worked on
start_data = {
    'prop1': 'value1',
    'prop2': 'value2',
    'dict1': {
        'dictprop1': 'dictvalue1'
    },
    'list1': [
        'listvalue1',
        'listvalue2'
    ],
    'list2': [
        {'listdictprop1': 'listdictprop1', 'listdictlist1': ['listdictlistvalue1']}
    ]
}

# initialize a new builder
builder = FixtureBulder.create(start_data)

# retrieve the data unchanged
test_data1 = builder.data

# set a new value on a property and retrieve the updated data
test_data2 = builder.set('prop1', 1).data

# do complex manipulation on the start_data and retrieve the modified data
test_data3 = builder
    .with_dict('dict1')  # descend into 'dict1' and work on it's properties
        .set('dictprop1', 12)
        .set('newlist', ['value'])
        .add('newlist', 'additional value')  # add a new value to a list
        .set('newdict', {'someprop': 'some value'})
        .with_dict('newdict')
            .set('someprop', 'change previously created value')
        .done()  # finish working on 'newdict' and return to 'dict1'
    .done()  # finish working on 'dict1' and return to the root
    .data


test_data4 = builder
    .duplicate_last_list_entry('list2')  # append a duplicated dict to the list
    .with_dict_list_element('list2')     # descend into the last list element to work on it's properties
        .add('listdictlist1', 'new value1')
        .set('listdictprop1', False)
    .done()  # finish working on the list element and return to the root
    .data

# retrieve the original unmodified data
original_data = builder.data

# setting new property raises an error
builder.set('newprop', 'newvalue')

Project details


Download files

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

Source Distribution

fixturebuilder_py-1.2.9.tar.gz (6.3 kB view details)

Uploaded Source

File details

Details for the file fixturebuilder_py-1.2.9.tar.gz.

File metadata

File hashes

Hashes for fixturebuilder_py-1.2.9.tar.gz
Algorithm Hash digest
SHA256 c1460bd436a1922485461e180dc1dc632e7b45ab0616911a2dc64e3c67165353
MD5 a55897f9dcd1a8b4a12e08b132621466
BLAKE2b-256 94fe2ed5fb8c8f51960ce087c147e42110b05f645f27dbe3d33d56fa2b860718

See more details on using hashes here.

Supported by

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