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

Uploaded Source

File details

Details for the file sealedmock-0.1.0.tar.gz.

File metadata

  • Download URL: sealedmock-0.1.0.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sealedmock-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c83b0183b99384e7b24337ef40dc719772723fdba95ec466d2a98148c61e2efc
MD5 f005fa42deb2d11f50d39fd6de465420
BLAKE2b-256 528e9f3fe4c16d9ec9cec25aeb6b5d9dec0cc7e823545f5f0b863be3c0677b10

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