-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; only version 2
-# of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
- def _test_binop_invalid_unknown(self, op):
- if op in _COMP_BINOPS:
- self.skipTest('not testing')
-
- with self.assertRaises(TypeError):
- op(self._def, object())
-
- def _test_binop_invalid_none(self, op):
- if op in _COMP_BINOPS:
- self.skipTest('not testing')
-
- with self.assertRaises(TypeError):
- op(self._def, None)
+ def _test_binop_unknown(self, op):
+ if op is operator.eq:
+ self.assertIs(op(self._def, object()), False)
+ elif op is operator.ne:
+ self.assertIs(op(self._def, object()), True)
+ else:
+ with self.assertRaises(TypeError):
+ op(self._def, object())
+
+ def _test_binop_none(self, op):
+ if op is operator.eq:
+ self.assertIs(op(self._def, None), False)
+ elif op is operator.ne:
+ self.assertIs(op(self._def, None), True)
+ else:
+ with self.assertRaises(TypeError):
+ op(self._def, None)
- ('lt', operator.lt),
- ('le', operator.le),
- ('eq', operator.eq),
- ('ne', operator.ne),
- ('ge', operator.ge),
- ('gt', operator.gt),
- ('add', operator.add),
- ('radd', lambda a, b: operator.add(b, a)),
- ('and', operator.and_),
- ('rand', lambda a, b: operator.and_(b, a)),
- ('floordiv', operator.floordiv),
- ('rfloordiv', lambda a, b: operator.floordiv(b, a)),
- ('lshift', operator.lshift),
- ('rlshift', lambda a, b: operator.lshift(b, a)),
- ('mod', operator.mod),
- ('rmod', lambda a, b: operator.mod(b, a)),
- ('mul', operator.mul),
- ('rmul', lambda a, b: operator.mul(b, a)),
- ('or', operator.or_),
- ('ror', lambda a, b: operator.or_(b, a)),
- ('pow', operator.pow),
- ('rpow', lambda a, b: operator.pow(b, a)),
- ('rshift', operator.rshift),
- ('rrshift', lambda a, b: operator.rshift(b, a)),
- ('sub', operator.sub),
- ('rsub', lambda a, b: operator.sub(b, a)),
- ('truediv', operator.truediv),
- ('rtruediv', lambda a, b: operator.truediv(b, a)),
- ('xor', operator.xor),
- ('rxor', lambda a, b: operator.xor(b, a)),
+ ("lt", operator.lt),
+ ("le", operator.le),
+ ("eq", operator.eq),
+ ("ne", operator.ne),
+ ("ge", operator.ge),
+ ("gt", operator.gt),
+ ("add", operator.add),
+ ("radd", lambda a, b: operator.add(b, a)),
+ ("and", operator.and_),
+ ("rand", lambda a, b: operator.and_(b, a)),
+ ("floordiv", operator.floordiv),
+ ("rfloordiv", lambda a, b: operator.floordiv(b, a)),
+ ("lshift", operator.lshift),
+ ("rlshift", lambda a, b: operator.lshift(b, a)),
+ ("mod", operator.mod),
+ ("rmod", lambda a, b: operator.mod(b, a)),
+ ("mul", operator.mul),
+ ("rmul", lambda a, b: operator.mul(b, a)),
+ ("or", operator.or_),
+ ("ror", lambda a, b: operator.or_(b, a)),
+ ("pow", operator.pow),
+ ("rpow", lambda a, b: operator.pow(b, a)),
+ ("rshift", operator.rshift),
+ ("rrshift", lambda a, b: operator.rshift(b, a)),
+ ("sub", operator.sub),
+ ("rsub", lambda a, b: operator.sub(b, a)),
+ ("truediv", operator.truediv),
+ ("rtruediv", lambda a, b: operator.truediv(b, a)),
+ ("xor", operator.xor),
+ ("rxor", lambda a, b: operator.xor(b, a)),
- ('neg', operator.neg),
- ('pos', operator.pos),
- ('abs', operator.abs),
- ('invert', operator.invert),
- ('round', round),
- ('round_0', partial(round, ndigits=0)),
- ('round_1', partial(round, ndigits=1)),
- ('round_2', partial(round, ndigits=2)),
- ('round_3', partial(round, ndigits=3)),
- ('ceil', math.ceil),
- ('floor', math.floor),
- ('trunc', math.trunc),
+ ("neg", operator.neg),
+ ("pos", operator.pos),
+ ("abs", operator.abs),
+ ("invert", operator.invert),
+ ("round", round),
+ ("round_0", partial(round, ndigits=0)),
+ ("round_1", partial(round, ndigits=1)),
+ ("round_2", partial(round, ndigits=2)),
+ ("round_3", partial(round, ndigits=3)),
+ ("ceil", math.ceil),
+ ("floor", math.floor),
+ ("trunc", math.trunc),