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


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

Uploaded Source

Built Distribution

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

Uploaded Source

File details

Details for the file samarche-0.0.1.tar.gz.

File metadata

  • Download URL: samarche-0.0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for samarche-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0e8c46c6ded169b2d33f295ac4f4e5a99a7d8edb6a42babfcebd684eaf46b3bd
MD5 590520bf540c5d0bc476918b46f57a8b
BLAKE2b-256 1542a3166ff99a90f0fac2bcccc231080e7bd07932530e6088710c91ad473f72

See more details on using hashes here.

File details

Details for the file samarche-0.0.1-py3.4.egg.

File metadata

File hashes

Hashes for samarche-0.0.1-py3.4.egg
Algorithm Hash digest
SHA256 030b9c323b66635bece1411667a6a76e672a6167f38ad25747c503190a93e1d5
MD5 55fd8901715a10d90e78838db10d0e3b
BLAKE2b-256 567f1bd3a6a0149b595d0a7425b73a0320b3ae2bfe7cb8ab5dec71bbcf2b8237

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page