Skip to main content

Mocks that whitelist its interface

Project description

Build Status # Sealed Mock Small utility to ease the process of defining and working with mocks.

It allows you to stop the process of the mocks automatically creating other mocks at any point.

SealedMock allows you to define a point in your test where the mocks provided should stop generating mocks automatically preventing test pass when they call attributes they should not have been called.

Install

pip install sealedmock

Usage

Given you have a file like:

import urllib2

class SampleCodeClass(object):
    """This is sample code"""
    def calling_urlopen(self):
        return urllib2.urlopen("http://chooserandom.com")

    def calling_splithost(self):
        return urllib2.splithost("//host:port/path")

You can write a test like:

@patch("tests.sample_code.urllib2")
def test_using_decorator(mock):
        sample = sample_code.SampleCodeClass()
        mock.urlopen.return_value = 2
        mock.sealed = True

        # calling urlopen succeeds as mock.urlopen has been defined
        assert sample.calling_urlopen()

        # This will fail as mock.splithost has not been defined
        sample.calling_splithost()

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

sealedmock-0.1.0.tar.gz (2.3 kB view hashes)

Uploaded Source

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