test_intercept.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:reahl 作者: reahl 项目源码 文件源码
def test_monitor():
    """A CallMonitor records each call to a method, and its arguments."""

    class SomethingElse(object):
        def foo(self, n, y=None):
            self.n = n
            return y

    s = SomethingElse()
    original_method = six.get_method_function(s.foo)

    with CallMonitor(s.foo) as monitor:
        assert s.foo(1, y='a') == 'a'
        assert s.foo(2) == None

    assert six.get_method_function(s.foo) is original_method
    assert s.n == 2
    assert monitor.times_called == 2
    assert monitor.calls[0].args == (1,)
    assert monitor.calls[0].kwargs == {'y':'a'}
    assert monitor.calls[0].return_value == 'a'

    assert monitor.calls[1].args == (2,)
    assert monitor.calls[1].kwargs == {}
    assert monitor.calls[1].return_value == None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号