Skip to main content

Samarche for testing your public api against regression !

Project description



API checker inspired by this post


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):

    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


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)
    samarche.check_signature('my_api', original_signature)
except samarche.ValidationError as e:
    print("API has changed : {}".format(e))

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

samarche-0.0.1.tar.gz (3.8 kB view hashes)

Uploaded source

Built Distribution

samarche-0.0.1-py3.4.egg (1.1 kB view hashes)

Uploaded 3 4

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page