derwiki-adroll / mock

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

Platform dependent results of MagicMock inequalities #196

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
>>> from mock import MagicMock
>>> m = MagicMock()
>>> m.__lt__()
NotImplemented
>>> m < 0
(False on Linux/Darwin, True on Windows)

What is the expected output? What do you see instead?
I expect to see the same result across platforms.

What version of the product are you using? On what operating system?
I am using Mock version 1.0.1, but I first noticed the issue in version 1.0.  
I've seen this result consistently across different machines, but most recently 
tested on: 
Linux: 64bit CentOS 5.2, Python 2.7.3, glibc 2.5
Windows: Windows 7, MingW shell, Python 2.7.3.

Original issue reported on code.google.com by dwandsch...@gmail.com on 28 Jan 2013 at 7:14

GoogleCodeExporter commented 9 years ago
I can confirm this happens, and it's very odd. Investigating.

Original comment by fuzzyman on 18 Mar 2013 at 10:39

GoogleCodeExporter commented 9 years ago
Ok, so the reason for this is that mock returns NotImplemented for these 
comparisons. Python 3 (the interpreter) does the sane thing and raises an 
exception because the comparison is not meaningful.

Python 2 tries to guess - and returns a result based on comparing the *types*! 
Python 2.7 is returning different results for this operation on different 
platforms:

    >>> MagicMock < int
    False

Changing mocks to return something other than NotImplemented would be backwards 
incompatible - so where your tests are depending on the results of the 
comparison I think you need to explicitly set the result.

On the other hand, filing a bug against Python for inconsistent results would 
be perfectly acceptable.

Original comment by fuzzyman on 18 Mar 2013 at 11:54