Skip to main content
grappa logo

Build Status PyPI Coverage Status Documentation Status Stability Code Climate Python Versions Say Thanks

About

grappa is a behavior-oriented, self-declarative, expressive and developer-friendly lightweight assertion library for Python.

grappa comes with two declarative assertion styles: expect and should.

It also comes with a detailed, human-friendly error reporting system that aims to reduce friction, provide better feedback and improve human speed and agility while identifying and fixing errors.

To get started, take a look to the showcase code, demo, tutorial and documentation.

Status

grappa is currently beta quality software. Contributions and issue reporting is welcome.

Showcase

A small example demonstrating some grappa features:

from grappa import should

True | should.be.true
False | should.be.false
None | should.be.none

'bar' | should.be.equal.to('bar')
13.14 | should.be.lower.than(14)
13.14 | should.be.higher.than(13)

'Hello grappa' | should.match('(\W)+ grappa$')
'Hello grappa' | should.contain('grappa') | should.contain('he')

{'foo': True} | should.be.a('dict')
[1, 2, 3] | should.be.a('list') > should.have.length.of(3)
(lambda x: x) | should.not_be.have.type.of('lambda')

{'foo': 'bar'} | should.have.key('foo').that.should.be.equal.to('bar')
(1, 2, 3, 4) | should.be.a(tuple) > should.have.index.at(3) > should.be.equal.to(4)

an_object | should.have.properties('foo', 'bar', 'baz')
an_object | should.implement.methods('foo', 'bar', 'baz')

({'bar': [1, 2, 3]}
    | should.have.key('bar')
    > should.be.a('list')
    > should.have.length.of(3)
    > should.contain.item(3)
    > should.have.index.at(1)
    > should.be.equal.to(2))

See documentation for more examples.

Demo

showcase

Why grappa?

grappa aims to assist humans while doing a very recurrent and not very fun task in software development: testing things.

The core idea behind grappa comes from the fact that human time is considerably more expensive than machine time, and therefore any machine assistance to optimize processes and close the gap is beneficial.

With grappa you can express almost in plain English what the test contract actually is, but in a way that’s fun and easy to write but also more easy and pleasant to read or maintain by other developers.

The Zen of grappa

  • Testing is about feedback: detailed, easy to understand, human-friendly is always better.

  • Frictionless testing: introducing self-declarative behavior testing patterns can make testing more fun for test writers and more enjoyable for test readers.

  • Expressivity is paramount: humans should easily understand what the code is doing.

  • Human time is expensive: any modern software should assist people to identify and understand errors easily.

  • Make error reporting great again: feedback during testing is key, let’s make it more handy and less frustrating.

  • Testing patterns consolidation: software expectations are limited to the boundaries of language data types and structures.

  • Hurt less feelings: seeing errors is not a nice thing, but it can be painless if details are showed you in a more gentle way.

Features

  • Behavior-oriented expressive fluent API.

  • Built-in assertion DSL with English lexicon and semantics.

  • Supports both expect and should assertion styles.

  • Full-featured built-in assertion operators.

  • Human-friendly and detailed error reporting.

  • Built-in expectations difference comparison between subject and expected values.

  • Extensible assertions supporting third-party plugins.

  • Assertion chaining and composition.

  • Composable assertion via logical operators such as and & or.

  • Testing framework agnostic. Works with unittest, nosetests, pytest, behave

  • Easy to hack via programmatic API.

  • Lightweight and (almost) dependency-free.

  • Works with Python 2.7+, 3+, PyPy and potentially with other Python implementations.

Installation

Using pip package manager:

pip install --upgrade grappa

Or install the latest sources from Github:

pip install -e git+git://github.com/grappa-py/grappa.git#egg=grappa

History

v0.1.2 / 2017-03-26

  • feat(docs): add matchers supported keyword arguments

  • feat(docs): improve descriptions

  • feat(operators): improve length operator for access based chaining

  • fix(docs): update error custom message example

  • feat(docs): improve documentation. adds operators composition section

  • fix(setup.py): add author email

v0.1.1 / 2017-03-23

  • refactor(diff): process expected values as tuple first

  • fix(contain): remove print statements

  • refactor(core): normalize yielding syntax, add missing documentation

  • refactor(core): normalize yielding syntax, add missing documentation

  • feat(#26): support disable operator chaining

  • feat(#28): better assertion reporting. feat(operators): add index operator

  • refactor(reporter): support raw mode with proper indent pretty printing

  • refactor(operators): add satisfy/satisfies attribute operators

  • feat(diff): consume diff specific subject/expected values

  • feat(operators): add is/is_not operator attributes

  • refactor(core): isolate reporters per module

  • feat(#13, #25): add suboperators support and diff output report

  • refactor(docs): update organization name

  • refactor(docs): update project image

  • refactor(reporter): ignore subject/expected output if empty

  • refactor(reporter): show diff if enabled

  • feat(docs): add in a nutshell section

  • feat(#24, #25): feature enhancements

  • feat(docs): add say thanks badge

  • refactor(reporter): load value from operator first

  • fix(docs): use proper badges

  • fix(docs): update type operator examples

  • fix(metadata): update

  • refactor(test): add chained test for keys

  • feat(Makefile): add publish commands

0.1.0 (2017-03-05)

  • First version (beta)

Download files

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

Source Distribution

grappa-0.1.2.tar.gz (33.6 kB view details)

Uploaded Source

Built Distribution

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

grappa-0.1.2-py2.py3-none-any.whl (60.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file grappa-0.1.2.tar.gz.

File metadata

  • Download URL: grappa-0.1.2.tar.gz
  • Upload date:
  • Size: 33.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for grappa-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d5619e66b4cb1a750dd7cfa76ff30b7a5e3e1116f2e8d78e317b1b88dd493823
MD5 b3d97859257f2da6f4b55938e9f227e6
BLAKE2b-256 a2ee0e5fde42a98a0c8ff5d09cdaf9c24fbd0bcda0a2d12f83d08dc6ff2a7ddc

See more details on using hashes here.

File details

Details for the file grappa-0.1.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for grappa-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e16daf2f96bf9d21e24d02d57dea24b8f6190c3e12919968bd1b816e53f53b88
MD5 3f2f211eb4fde327d9149053d0e9ff81
BLAKE2b-256 e220fa33bda0200b3c592fb6f92e59d2c80e55dd64f8dc8260bc189fa60fa1b3

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 Sentry Error logging StatusPage Status page