kgashok / pymox

Automatically exported from code.google.com/p/pymox
Apache License 2.0
0 stars 0 forks source link

MockObject should be smarter about recording args vs kwargs #12

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Given the object:

class Foo(object):
  def bar(one, two, three=None):
    pass

When recording or replaying a MockObject(Foo)
 m_foo = mox.MockObject(Foo)
 # should be recorded in the same for both calls.
 m_foo.bar(1, 2, 3)  
 m_foo.bar(1, 2, three=3)

And verify should work for either:
 m_foo.bar(1, 2, 3)
 m_foo.bar(1, 2, 3)

... or ...
 m_foo.bar(1, 2, three=3)
 m_foo.bar(1, 2, three=3)

... or any combination thereof ...

This would require inspecting the method signature, and properly mapping 
keyword args, where appropriate.  I'm not sure if this is possible or not, 
but I'd like to hope so.

What is the expected output? What do you see instead?

See above.

Original issue reported on code.google.com by smidd...@gmail.com on 25 Sep 2009 at 8:28

GoogleCodeExporter commented 8 years ago

Original comment by smidd...@gmail.com on 25 Sep 2009 at 8:33

GoogleCodeExporter commented 8 years ago
Here is a patch that tries to implement the feature described.
To apply it: patch < pymox.patch, from the root of the mox directory.

When MockMethod records a call or an expectation, it normalizes the arguments 
into a map or named arguments.
The comparison of two MockMethod then compares the normalized arguments maps 
instead or the pair (position arguments, named arguments).

Cheers,
Christophe

Original comment by ta...@google.com on 8 Jun 2010 at 8:33

Attachments:

GoogleCodeExporter commented 8 years ago
Here is a new patch taking into account most of your comments.
I am not sure how the equal operator should be implemented so I left it.

Original comment by ta...@google.com on 15 Jun 2010 at 10:07

Attachments:

GoogleCodeExporter commented 8 years ago
I'm looking at this now.  Do you have some tests to verify this new behavior is 
correct.

Original comment by steve.mi...@gmail.com on 15 Jun 2010 at 9:03

GoogleCodeExporter commented 8 years ago
Sure, I added a test case for this behavior.

Original comment by ta...@google.com on 21 Jun 2010 at 10:01

Attachments: