Does pyDoubles support the use of hamcrest matchers for keyword arguments when writing expectaions for a Mock object? Hamcrest works great for plain args, but I can't figure out how/if it works with kwargs. If I had to guess, after looking at pyDoubles.core for a little while, it seems there is not matching for kwargs like there is for normal args: _MethodPool_._do_kwargs_match() doesn't seem to make use of self.match_finder like _MathodPool_._do_args_match() does. Could you confirm/deny this?
Below is the code I used to tryout hamcrest matchers in kwargs... but with no success. Thanks for the help.
from hamcrest import equal_to, is_
import unittest
from pyDoubles.framework import *
class ClassToMock():
def __init__(self):
pass
def func(self, anumber, akw1="nothing", akw2="something"):
print anumber, akw1, akw2
class SimpleTestCase(unittest.TestCase):
def setUp(self):
self.classmock = mock(ClassToMock())
def tearDown(self):
self.classmock.assert_that_is_satisfied()
def test_a_simple_test(self):
""" works fine """
expect_call(self.classmock.func).with_args(4, akw2="four")
expect_call(self.classmock.func).with_args(5, akw2="five")
self.classmock.func(4, akw2="four")
self.classmock.func(5, akw2="five")
def test_an_args_matcher(self):
""" works fine """
expect_call(self.classmock.func).with_args(equal_to(4), akw2="four")
expected_args = [equal_to(5)]
expect_call(self.classmock.func).with_args(*expected_args, akw2="five")
self.classmock.func(4, akw2="four")
self.classmock.func(5, akw2="five")
def test_a_kwarg_test1(self):
""" DOESN'T WORK """
expect_call(self.classmock.func).with_args(4, akw2=equal_to("four"))
self.classmock.func(4, akw2="four")
def test_a_kwarg_test2(self):
""" DOESN'T WORK """
kwargs = {'akw2' : equal_to("four")}
expect_call(self.classmock.func).with_args(4, **kwargs)
self.classmock.func(4, akw2="four")
def test_a_kwarg_test3(self):
""" DOESN'T WORK """
kwargs = equal_to({'akw2' : "four"})
expect_call(self.classmock.func).with_args(4, **kwargs)
self.classmock.func(4, akw2="four")
if __name__ == "__main__":
unittest.main()
~ Tyler