This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

A decorator for easily mocking out multiple dependencies by monkey-patching.

@simian.patch(module=..., external=[...], internal=[...])

Installation:

$ pip install simian

simian.patch is a convenience wrapper around mock.patch with the following benefits:

  1. All patched objects are collected under a single master_mock, which is provided to the function being decorated. Any patched target can be accessed by its basename (e.g., a patched time.sleep would be accessed in the decorated function as master_mock.sleep).
  2. The patching works even if the target is imported directly (e.g., a call to sleep is patched the same as a call to time.sleep). Simian handles this by reloading the module under test after applying the external patches.
  3. Objects internal to the module under test can be patched as well. They are collected under the same master_mock and can be referenced in the same way.

After leaving the decorated function, simian reloads the module under test again, bringing it back to its pre-patched state (although all of the module’s addresses in memory have changed).

External Patching

#
# my_package.my_module
#

from time import sleep


def my_sleep(duration_secs):
    print('Sleeping for {n} seconds'.format(n=duration_secs))
    sleep(duration_secs)


#
# my_package.test.test_my_module
#

import simian
from my_package import my_module


@simian.patch(my_module, external=['time.sleep'])
def test_my_sleep(master_mock):
    my_module.my_sleep(99)
    master_mock.sleep.assert_called_once_with(99)

Internal Patching

The above example demonstrates external patching, but internal (same-module) patching works as well. Let’s extend the above example.

#
# my_package.my_module
#

from time import sleep


def my_sleep(duration_secs):
    my_logger('Starting {n}-second sleep'.format(n=duration_secs))
    sleep(duration_secs)
    my_logger('Finished {n}-second sleep'.format(n=duration_secs))


def my_logger(msg):
    print(msg)


#
# my_package.test.test_my_module
#

import simian
from mock import call
from my_package import my_module


@simian.patch(my_module, external=['time.sleep'], internal=['my_logger'])
def test_my_sleep(master_mock):
    my_module.my_sleep(99)
    master_mock.assert_has_calls(
        calls=[
            call.my_logger('Starting 99-second sleep'),
            call.sleep(99),
            call.my_logger('Finished 99-second sleep')],
        any_order=False)
Release History

Release History

2.0.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.7

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
simian-2.0.0-py2.py3-none-any.whl (3.6 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Dec 24, 2014
simian-2.0.0.tar.gz (3.3 kB) Copy SHA256 Checksum SHA256 Source Dec 24, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting