derwiki-adroll / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

help for tracking more complex object traversals #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following would be my idea of heaven:

>>> m = Mock()
>>> m.heap().stat.dump('somepath')
<Mock ...>
>>> m.objects_and_calls
["m.heap().stat.dump('somepath')"]

No idea how to do this one, but the current way feels a bit icky:

# h.heap().stat.dump('somepath')
self.assertEqual(h.method_calls,[('heap',(),{})])
h = h.heap.return_value
self.assertEqual(h.method_calls,[('stat.dump', ('somepath',),{})]) 

Original issue reported on code.google.com by cwith...@gmail.com on 9 Dec 2008 at 12:54

GoogleCodeExporter commented 9 years ago
See issue 8. I could add this to method_calls.

The trouble with making the traversal into a single string is that not all 
objects
have a nice repr and that reproducing the exact order of keyword argument calls
(collected as a dictionary) is impossible.

Original comment by fuzzyman on 9 Dec 2008 at 12:27

GoogleCodeExporter commented 9 years ago
One way to solve the "order of keyword argument calls" problems would be to 
always sort keywords before printing them - that way they always appear in a 
guaranteed order.

Original comment by fuzzyman on 11 Jun 2010 at 12:00

GoogleCodeExporter commented 9 years ago
I think the right way of doing this is a combination of issue 79 (using call 
objects) and issue 82 (tracking all calls). This will allow you to do:
{{{
mock.foo().bar(1, 2)

assert mock.mock_callls == [call.foo().bar(1, 2)]
}}}

Aiming for this to go in 0.8.0.

Original comment by fuzzyman on 29 Mar 2011 at 5:28