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:

test_object = Mock()
test_object.method({'bob': 'barker'})
test_object.method.assert_called_with(any_dict)

Usage with doubles:

test_object = TestClass()
expect(test_object).method.with_args(any_string.containing('bob'))

test_object.method('bob barker')

strings:

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:

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:

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:

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]

objects:

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-0.0.23.tar.gz (4.0 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: equals-0.0.23.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for equals-0.0.23.tar.gz
Algorithm Hash digest
SHA256 850a521907f6dac1e4d2115841066fe4b7de4e833edb54233e6f85460f54d0b9
MD5 01a8a7fbf531a0ebed75522776bc5b98
BLAKE2b-256 bcf577fc14d8003b094e85bc9e5eb31508730b703a730d79f854d8e4924d4a36

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