Skip to main content

Python Fuzzy Matchers

Project description

PyPi Version Travis Test Status Coveralls

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 doubles.

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

Usage with doubles:

from doubles 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')

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

Installation:

>> pip install equals

Development:

>> git clone https://github.com/toddsifleet/equals
>> cd equals
>> make bootstrap
>> make

License:

See LICENSE

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

equals-1.0.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

equals-1.0.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file equals-1.0.0.tar.gz.

File metadata

  • Download URL: equals-1.0.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for equals-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1384b5591fd29af89db21df8569680d7ac1ceb2f8dbd70d1edd28bbadc48ed0d
MD5 e52398f18f72d7400db766037efdfdfb
BLAKE2b-256 0824857d60eb6b35d3cf08d991397bb1c764556538b79a4f0eb2e24113b18804

See more details on using hashes here.

File details

Details for the file equals-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: equals-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for equals-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0234529457b752009252ec774ff9b0c6b0e6aa6300a833d7817965ce6a497679
MD5 737f74093064912ff87a8508c1ce88b3
BLAKE2b-256 d9c36ea918a42c33eb866cf29963d32db80390f59a023a9f2896c5be49cae435

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page