Fuzzy Mock objects for testing
Project description
A mock equality tool for testing
tl;dr Equals is a stricter version of Mock.Any.
Equals allows you to assert certain equality constraints between python objects during testing. There are times where we don’t want to assert absolute equality, e.g. we need to ensure two lists have the same elements, but don’t care about order. This was designed specifically for usage with Mock and dobles.
API
Full Documentation is available at http://equals.readthedocs.org/en/latest/.
strings:
from equals import any_string
any_string.containing('abc') == '123 abc 456'
any_string.starting_with('abc') == 'abcdef'
any_string.ending_with('abc') == '123abc'
any_string.matching('^abc$') == 'abc'
numbers:
from equals import any_number any_number.less_than(5) == 4 any_number.less_than_or_equal_to(5) == 5 any_number.greater_than(4) == 5 any_number.greater_than_or_equal_to(5) == 5 any_number.between(1, 3) == 2
dictionaries:
from equals import any_dict
any_dict.containing(1, 2) == {1: 2, 2:3, 4:5}
any_dict.containing(foo='bar') == {
'foo': 'bar',
'bob': 'barker'
}
any_dict.not_containing(1, foo=5) == {'foo':3, 4:5}
iterators:
from equals import any_iterable any_iterable.containing(1, 2, 3) == [1, 2, 3, 4, 5] any_iterable.containing_only(1, 2, 3) == [2, 3, 1] any_iterable.not_containing(1, 2) == [3, 4] any_iterable.with_length(2) == [3, 4]
objects:
from equals import anything
anything == None
anything == True
anything == {1: 1}
anything_true == 'dd'
anything_false == ''
instance_of(dict) == {}
anything.with_attrs(foo='bar', bob='barker') == Dummy('bar', 'barker')
instance_of(Dummy).with_attrs(foo='bar', bob='barker') == Dummy('bar', 'barker')
With Mock:
from mock import Mock
from equals import any_dict
test_object = Mock()
test_object.method({'bob': 'barker'})
test_object.method.assert_called_with(any_dict)
dobles:
from dobles import expect
from equals import any_string
class TestClass(object):
def method(self, arg):
return arg
test_object = TestClass()
expect(test_object).method.with_args(any_string.containing('bob'))
test_object.method('bob barker')
Installation:
>> pip install equals
Development
Source code is available at https://github.com/smartfastlabs/equals.
To install the dependencies on a fresh clone of the repository, run make bootstrap.
To run the test suite, run make test.
To build the documentation locally, run make docs.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file equals-3.1.1.tar.gz.
File metadata
- Download URL: equals-3.1.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cac467ecd64505e57cb528f5191ee28cad125a0e8dee7cd6715f461f80dd69aa
|
|
| MD5 |
8d4268124f450e8ce1aa526af4d42958
|
|
| BLAKE2b-256 |
67a2e3663adcf20e75cff857b25bb6adb2c8089f8e1a961deafa39b7cfcdff00
|
File details
Details for the file equals-3.1.1-py3-none-any.whl.
File metadata
- Download URL: equals-3.1.1-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8558efb1eee7c8a097b9c50d5b52d34a658fa5189c3fdd339af4bc1c27efc5f2
|
|
| MD5 |
bf7faa38a5f8c364bee2667ae4a5829c
|
|
| BLAKE2b-256 |
7cb7d0d351aedf7acdf295b0bda8766572d695c6af815cb2c53c4f8b7bed85da
|