<commit_before>[![Build Status](https://travis-ci.org/fhuertas/mock_decorators.svg?branch=master)](https://travis-ci.org/fhuertas/mock_decorators)
[![Coverage Status](https://coveralls.io/repos/github/fhuertas/mock_decorators/badge.svg?branch=master)](https://coveralls.io/github/fhuertas/mock_decorators?branch=master)
# Python decorators for mocking

This module contains a set of decorators that allow to mock functions. (Replacing the behavior of a method, attribute, object or class)

## Requisites

This module has been created using python 3.4 and tested in python 2.7, 3.4 and 3,5. This should works in python 2.7 and higher. If you want to know if this module works
in a concrete python version, download the project and execute:

`make test PYTHON_VERSION=<python-version>`

where <python-version> is the version to test. Note: you must be installed that version. 

## Change log: 

**1.0**:

* Created the mocks, documentation.

**1.0.1**:

* Revise compatibility of ClassMock in python 2.7
* Update with coverage report

**1.0.2-1.0.4**
* Improved python 2 compatibility
* Adapted to Pypi public repository

**1.0.5**
* Added Mocks for dictionaries
* FIX: now ClassMock is reported correctly that it doesn't work in python 2

**1.0.6**
* Added mock for check if a function is called
* FIX: `make test-versions` makes tests for python 2 and 3

**1.0.7**
* FunctionMockCheckCall can return a value instead invoke the function

**1.0.9**
* FunctionMockCheckCall now check 0 invocations
* Fix: FunctionMockCheckCall checks if the value to return is None and not a condition
* Fix: the checks in the FunctionMockCheckCall

**1.1.0**
* New Mock. MockSysOutput catch the system output in a Stream 
* Fix documentation of FunctionMockCheckCall

## Installation

This module can be installed using the following options:
* From Pypi, using the following command `pip install mock_decorators`
* From respository: `pip install git+https://github.com/fhuertas/mock_decorators (for master version)`

## Usage

The tests contain examples to use this library but here there are the more useful examples: 

### FunctionMock

This mock replace a function for other. [Example](https://github.com/fhuertas/mock_decorators/blob/master/tests/mock_decorators/test_function_mock.py#L18) 

The parameters are the following: 

* **entity**: The module, class or object that you can replace the function. 
* **function_name**: The name string of the function to replace.
* **mocked_function**: The function that you can use. 
* **check_signature**: (*optional, true by default*) Check if the signature of the original function and the mocked mock function is the same<commit_msg>Add information about the new version<commit_after>[![Build Status](https://travis-ci.org/fhuertas/mock_decorators.svg?branch=master)](https://travis-ci.org/fhuertas/mock_decorators)
[![Coverage Status](https://coveralls.io/repos/github/fhuertas/mock_decorators/badge.svg?branch=master)](https://coveralls.io/github/fhuertas/mock_decorators?branch=master)
# Python decorators for mocking

This module contains a set of decorators that allow to mock functions. (Replacing the behavior of a method, attribute, object or class)

## Requisites

This module has been created using python 3.4 and tested in python 2.7, 3.4 and 3,5. This should works in python 2.7 and higher. If you want to know if this module works
in a concrete python version, download the project and execute:

`make test PYTHON_VERSION=<python-version>`

where <python-version> is the version to test. Note: you must be installed that version. 

## Change log: 

**1.0**:

* Created the mocks, documentation.

**1.0.1**:

* Revise compatibility of ClassMock in python 2.7
* Update with coverage report

**1.0.2-1.0.4**

* Improved python 2 compatibility
* Adapted to Pypi public repository

**1.0.5**

* Added Mocks for dictionaries
* FIX: now ClassMock is reported correctly that it doesn't work in python 2

**1.0.6**

* Added mock for check if a function is called
* FIX: `make test-versions` makes tests for python 2 and 3

**1.0.7**

* FunctionMockCheckCall can return a value instead invoke the function

**1.0.9**

* FunctionMockCheckCall now check 0 invocations
* Fix: FunctionMockCheckCall checks if the value to return is None and not a condition
* Fix: the checks in the FunctionMockCheckCall

**1.1.0**

* New Mock. MockSysOutput catch the system output in a Stream 
* Fix documentation of FunctionMockCheckCall

**1.1.1**

* Add coverage information 

## Installation

This module can be installed using the following options:
* From Pypi, using the following command `pip install mock_decorators`
* From respository: `pip install git+https://github.com/fhuertas/mock_decorators (for master version)`

## Usage

The tests contain examples to use this library but here there are the more useful examples: 

### FunctionMock

This mock replace a function for other. [Example](https://github.com/fhuertas/mock_decorators/blob/master/tests/mock_decorators/test_function_mock.py#L18) 

The parameters are the following: 

* **entity**: The module, class or object that you can replace the function. 
* **function_name**: The name string of the function to replace.
* **mocked_function**: The function that you can use. 
* **check_signature**: (*optional, true by default*) Check if the signature of the original function and the mocked mock function is the same
{'fraction_non_alphanumeric': 0.09351851851851851, 'fraction_numerical': 0.017222222222222222, 'mean_word_length': 4.795064377682404, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '390871', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1556, 'n_words': 640}