glasser / pymox

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

Optional arguments #37

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Related to issue 12, I want to stub out a function with optional arguments. I 
can't know in advance whether the optional arguments will be provided or not.
IgnoreArg() is no help with missing arguments.

def bar(one, two=None):
  pass

The test subject may call
bar(1)
or
bar(1, two=None)
or
bar(1, None)
or
bar(1, 42)

I'd like to be able to do
bar(1, two=IgnoreArg())
and have it match all of the above.

Original issue reported on code.google.com by stefano.rivera on 16 Aug 2011 at 9:12

GoogleCodeExporter commented 9 years ago
Mox is intended to be used for deterministic tests.

Why can't you know in advance what your code is going to do?

Original comment by steve.mi...@gmail.com on 16 Aug 2011 at 3:52

GoogleCodeExporter commented 9 years ago
OK, I only really need the first two examples above.

I have to stub out a function in another library for a test, and there are 
multiple versions of this library in production. The new version passes 
two=None, the other doesn't.

Original comment by stefano.rivera on 16 Aug 2011 at 4:17