google-code-export / pymox

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

mox fails when it tries to substitute a user given tuple for a %s #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use the In() comparator with a tuple (In((1, 2, 3)) so that you're 
matching a function call with something that contains a tuple
2. Fail the call check

What is the expected output? What do you see instead?
pymox should give a proper error how the call signature did not match but 
instead it fails with this:
mox/mox.py", line 1400, in __repr__
    return '<sequence or map containing \'%s\'>' % self._key

What version of the product are you using? On what operating system?
0.5.0 (I browsed the SVN source and seems to have the issue). Linux based 
OS.

Please provide any additional information below.

The problem is obvious, if self._key happens to be a tuple Python will try 
to perform multiple substitutions which is not the case. So the above code 
should wrap the user value like: str(self._key) and then this issue is 
gone. I haven't checked all the other comparators but it's theoretically 
possible for this to happen in any comparator where a %s substitution is 
tried for a user given input (which can be a tuple).

Original issue reported on code.google.com by di...@google.com on 5 Jun 2010 at 12:20

GoogleCodeExporter commented 9 years ago
ping?

Original comment by di...@google.com on 10 Jul 2010 at 1:12

GoogleCodeExporter commented 9 years ago
I'll try and get on it this week.  Also, you may submit patches. :)

Original comment by steve.mi...@gmail.com on 10 Jul 2010 at 1:41

GoogleCodeExporter commented 9 years ago
Taking another look at your problem description, it looks like you may be using 
In() incorrectly.

In asserts that a single element is in a collection (list, dict, tuple) - the 
value recorded is In the collection passed as an argument.  
mox.In(1) == (1, 2, 3)

Maybe you're looking for a comparator does that "one of":
mox.(In((1, 2, 3))) == 3 and mox(In(1, 2, 3))) == 2 ...

Does that make sense, or have I misunderstood your problem?

Original comment by steve.mi...@gmail.com on 10 Jul 2010 at 2:03

GoogleCodeExporter commented 9 years ago
What about a collection of collections? Can't I use "In" to check that a tuple 
is an element in a collection? That's what I'm doing here and that's something 
that works just fine with the "in" keyword in Python, maybe I'm confused about 
the functionality expected from mox.In().

Original comment by di...@google.com on 10 Jul 2010 at 2:17

GoogleCodeExporter commented 9 years ago
Ah, okay.  Thanks for the clarification.

I'm about to run out for the night, but now that I know what I'm trying to 
reproduce with a test, I'll hopefully hammer this out first thing tomorrow.

Original comment by steve.mi...@gmail.com on 10 Jul 2010 at 2:45

GoogleCodeExporter commented 9 years ago
I've just committed revision 54, which contains a few str()s.  Thanks for 
pointing this out.

Original comment by steve.mi...@gmail.com on 10 Jul 2010 at 6:31