Skip to main content

Samarche for testing your public api against regression !

Project description

Travis-CI

Samarche

API checker inspired by this post

Quickstart

Say you’re developping a module with a public API, for people working with it, this API is supposed to stay the same until the next major release. What would happen if a commit makes a change it shouldn’t have ?

The solution is testing :

# A class which is part of your API
class Foo:
    bar = True
    def __init__(self, stuff=False):
        self.stuff

    def thing(self):
        return "doh"

# Your tests to make sure the class stays consistent
self.assertTrue(hasattr(Foo, 'bar'))
self.assertTrue(hasattr(Foo, 'thing'))
self.assertTrue(hasattr(Foo(), 'stuff'))

Unfortunatly those tests are basically writting all your API a second time, there must be a better (and less boring) way !

Samarche allow you to take a snapshop of your API (called a signature) and then be able to test your evolving codebase against it.

Samarche register only public members (i.e. everything starting by _ is skipped) You can create signatures from a module, module.package and even module.package:package_attribute

Example

First build and save the signature of your API:

# Do this at each major release
import samarche

signature = samarche.build_signature("my_api")
with open('my_api.signature', 'wb') as fd:
    samarche.dump(signature, f)

Then put somewhere in your tests

with open('my_api.signature', 'rb') as fd:
  original_signature = samarche.load(fd)
try:
    samarche.check_signature('my_api', original_signature)
except samarche.ValidationError as e:
    print("API has changed : {}".format(e))

Project details


Release history Release notifications

This version

0.0.1

Download files

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

Files for samarche, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size samarche-0.0.1-py3.4.egg (1.1 kB) File type Egg Python version 3.4 Upload date Hashes View hashes
Filename, size samarche-0.0.1.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page