This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description
AssertionChain
=============

[![Build Status](https://travis-ci.org/justiniso/AssertionChain.svg)](https://travis-ci.org/justiniso/AssertionChain) [![Coverage Status](https://coveralls.io/repos/justiniso/AssertionChain/badge.svg?branch=master)](https://coveralls.io/r/justiniso/AssertionChain?branch=master)

An AssertionChain is a wrapper for a group of commands that must happen in sequence.

Installation:

pip install assertionchain

Features:

- Control order of execution of a group of functions
- Terminate execution of the rest of the chain if certain conditions are not met

Simple example:

AssertionChain()\
.do(lambda: 1 + 1, 'Add two numbers together') \
.expect(3, message='Step "{step}" did not result in expected value {expected}, value was: {actual}') \
.perform()

This is roughly equivalent to:

val = 1 + 1
assert val == 3

The above example is certainly more readable, so why use an AssertionChain at all? For starters, the chain
encourages the user to provide line-by-line detail about each step being executed. So if you want to understand
why the above assertion failed, you would have to construct a detailed error message indicating the actual and
expected value along with the step that produced the actual value. That's not particularly hard:

expected = 3
val = 1 + 1
message = 'Adding 1 + 1 did not result in expected value {expected}, value was: {actual}'.format(
expected=expected,
actual=val
)
assert val == expected, message

But having to repeat this every time you run a command can become very, very tedious. AssertionChain provides this
API for performing incremental checks on each operation being executed in the chain, reducing the overhead of having
to type all of this out.

It is a simple utility for grouping related actions and ensuring each step succeeds. For instance, assume we have a
suite of functions that interact with files (get_contents, write_contents, delete_file). Their contract stipulates
that each function will return True, False, or a value depending on whether or not they were successful. We can use an
AssertionChain to make sure each step was successful:

filename = '/tmp/sd9x0c2'
new_contents = 'myfile'

# Write the file, retrieve the contents
contents = AssertionChain()\
.do(lambda: get_contents(filename), 'Retrieve file contents').expect(False, operator='is not')\
.do(lambda: write_contents(filename, new_contents), 'Write file content').expect(True, operator='is')\
.do(lambda: write_contents(filename, ''), 'Write empty file content').expect(True, operator='is')\
.perform()

# Delete the file
AssertionChain().do(lambda: delete_file(filename), 'Delete file').expect(True, operator='is').perform()
Release History

Release History

0.1.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
assertionchain-0.1.1.tar.gz (5.4 kB) Copy SHA256 Checksum SHA256 Source Apr 6, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting