dingus
dingus copied to clipboard
assert_call seems not work on patched object
Hi,
I was interested to see how it works. After patching the original is not called anymore and I can see the calls. Fine. Two issues I've found:
- the one is already mentioned by another guy: patched("...") as var
- the one issue I found is that it seems the assertion don't work. I provided therefore the whole test code I have used for it. I think since you always intend to provide Dingus objects (right?) and you did write a test where you exactly did those assertion tests ... I assume then that it also should work for my case:
from dingus import Dingus, patch
from pprint import pprint
def low_foo(*args, **kwargs):
print("low_foo(%s, %s)" % (args, kwargs))
def high_foo(*args, **kwargs):
print("high_foo(%s, %s)" % (args, kwargs))
low_foo(*args, **kwargs)
high_foo(1, 3.1415, [1,2,3], name="hello")
print("now patching ...")
with patch("__main__.low_foo"):
high_foo(1, 3.1415, [1,2,3], name="hello")
print(low_foo)
pprint(low_foo.calls())
low_foo.assert_call(1, 3.1415, [1,2,3], name="hella")
class Bar(object):
def __init__(self, *args, **kwargs):
print("Bar.__init__(%s, %s)" % (args, kwargs))
def test(self, *args, **kwargs):
print("Bar.test(%s, %s)" % (args, kwargs))
class Foo(object):
def __init__(self, *args, **kwargs):
print("Foo.__init__(%s, %s)" % (args, kwargs))
self.bar = Bar(*args, **kwargs)
def test(self, *args, **kwargs):
print("Foo.test(%s, %s)" % (args, kwargs))
self.bar.test(*args, **kwargs)
foo = Foo("hello world", value=123)
foo.test("sunny days", value=321)
print("now patching ...")
with patch("__main__.Bar"):
foo = Foo("hello world", value=123)
foo.test("sunny days", value=321)
print(Bar)
pprint(Bar.calls())
Bar.test.assert_call("sunny days", values=322)