Skip to main content

Build fixtures from a single source

Project description

fixturebuilder_py
=================

.. image:: https://travis-ci.org/flowpl/fixturebuilder_py.svg?branch=master
:target: https://travis-ci.org/flowpl/fixturebuilder_py.svg?branch=master
.. image:: https://landscape.io/github/flowpl/fixturebuilder_py/master/landscape.svg?style=flat
:target: https://landscape.io/github/flowpl/fixturebuilder_py/master
.. image:: https://coveralls.io/repos/github/flowpl/fixturebuilder_py/badge.svg?branch=master
:target: https://coveralls.io/github/flowpl/fixturebuilder_py?branch=master


Install
-------

.. code-block:: bash

$ pip install fixturebuilder


Usage
-----

.. code-block:: python

# 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.8.tar.gz (6.5 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for fixturebuilder_py-1.2.8.tar.gz
Algorithm Hash digest
SHA256 c672b28f5a30558112983def1308b04eee4e25ea0ab55b47266b292a0c6cd6bf
MD5 a776edb10678d7c8d9bbcbe9849aae2e
BLAKE2b-256 e4cb928426e4e3b2ac8a2959227fc32fe0f4f50e2e85abe11d30dc17004bb76e

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