kgashok / pymox

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

And comparator should use == comparison rather than .equals #18

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
>>> import mox
>>> comparator = mox.And(1, mox.IsA(int))
>>> comparator == 1
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/var/lib/python-support/python2.4/mox.py", line 781, in __eq__
    return self.equals(rhs)
  File "/var/lib/python-support/python2.4/mox.py", line 1067, in equals
    if not comparator.equals(rhs):
AttributeError: 'int' object has no attribute 'equals'

What is the expected output? What do you see instead?
I expect True to be returned, however the AttributeError is raised.

What version of the product are you using? On what operating system?
Unknown, however the trunk version of pymox appears to have this bug in 
trunk as of Feb 23rd 2010.

Please provide any additional information below.
By using the == operator instead of the .equals() method (with the expected 
value on the lhs), this would make literal values usable. Currently 
mox.Func(lambda rhs: literal===rhs) needs to be employed to reach the same 
effect.

Comparators define __eq__ to call self.equals, so this should preserve 
existing behaviour when comparators are passed to the And() comparator. 
Although making this change could affect existing test cases that define a 
class that defines an equals method that is not called by an __eq__ method.

Note: the same problem/non-feature affects the Or comparator.

Original issue reported on code.google.com by great...@gmail.com on 23 Apr 2010 at 5:38