python模糊匹配器
equals的Python项目详细描述
tl;dr Equals是 Mock.Any。
equals允许您断言python之间的某些等式约束 测试期间的对象有时我们不想断言 绝对平等,例如,我们需要确保两个列表具有相同的 元素,但不关心顺序。这是专门为 与Mock和doubles一起使用。
与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)
双倍使用:
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')
字符串:
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'
数字:
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
词典:
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}
迭代器:
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]
对象:
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')
安装:
>> pip install equals
发展:
>> git clone https://github.com/toddsifleet/equals >> cd equals >> make bootstrap >> make
许可证:
见许可证