对python和mock的简洁模拟期望
expect的Python项目详细描述
#expect
灵感来源于[rspec的test doubles][2]和[expecter gadget][3]。
使用[mock][1]但为期望提供了更简洁的语法。
>示例:
```python
>;>def assert嫒equal(lhs,rhs):
…assert lhs==rhs
>;>;来自expect import new_expect
>;>;expect=new_expect(u eq_uu=assert_u equal)
>;>;expect(2)==2
>;>;expect(2)==3
回溯(最近一次调用):
…
assertonerror
>;>;类myclass(对象):
…@类方法
…定义我的方法(cls,arg):
…不必调用存根。
>>>gt>gt;不必调用存根。
>>gt>gt;expect(myclass.stub('my'u方法')。with(1)和返回(2)myclass.my方法(1)myclass.my方法(1)
>2
>>gt;expect.reset()
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>接收(“我的方法”)。expect.verify()
回溯(最近一次调用的最后一次):
…
断言错误:应调用一次。调用0次。
```
[1]:http://www.voidspace.org.uk/python/mock/
[2]:https://github.com/rspec/rspec mocks
[3]:https://github.com/garybernhardt/expecter
灵感来源于[rspec的test doubles][2]和[expecter gadget][3]。
使用[mock][1]但为期望提供了更简洁的语法。
>示例:
```python
>;>def assert嫒equal(lhs,rhs):
…assert lhs==rhs
>;>;来自expect import new_expect
>;>;expect=new_expect(u eq_uu=assert_u equal)
>;>;expect(2)==2
>;>;expect(2)==3
回溯(最近一次调用):
…
assertonerror
>;>;类myclass(对象):
…@类方法
…定义我的方法(cls,arg):
…不必调用存根。
>>>gt>gt;不必调用存根。
>>gt>gt;expect(myclass.stub('my'u方法')。with(1)和返回(2)myclass.my方法(1)myclass.my方法(1)
>2
>>gt;expect.reset()
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>接收(“我的方法”)。expect.verify()
回溯(最近一次调用的最后一次):
…
断言错误:应调用一次。调用0次。
```
[1]:http://www.voidspace.org.uk/python/mock/
[2]:https://github.com/rspec/rspec mocks
[3]:https://github.com/garybernhardt/expecter