summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-03-24 08:14:36 +0000
committerNeal Norwitz <nnorwitz@gmail.com>2006-03-24 08:14:36 +0000
commitbcc0db82dc9cb474d56a4cc63748583232d9524f (patch)
tree0107d20b29b61fc7dfd9626ee7257242f8cf6302 /Lib/test
parented483ba63b9c03845386976bccff5d95df5b570a (diff)
downloadcpython-git-bcc0db82dc9cb474d56a4cc63748583232d9524f.tar.gz
Get rid of remnants of integer division
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_augassign.py30
-rw-r--r--Lib/test/test_binop.py4
-rw-r--r--Lib/test/test_class.py16
-rw-r--r--Lib/test/test_coercion.py4
-rw-r--r--Lib/test/test_complex.py8
-rw-r--r--Lib/test/test_decimal.py4
-rw-r--r--Lib/test/test_descr.py9
-rw-r--r--Lib/test/test_operator.py8
8 files changed, 20 insertions, 63 deletions
diff --git a/Lib/test/test_augassign.py b/Lib/test/test_augassign.py
index 8a8f00d88d..228e03a310 100644
--- a/Lib/test/test_augassign.py
+++ b/Lib/test/test_augassign.py
@@ -5,7 +5,7 @@ x += 1
x *= 2
x **= 2
x -= 8
-x //= 2
+x /= 2
x //= 1
x %= 12
x &= 2
@@ -19,7 +19,7 @@ x[0] += 1
x[0] *= 2
x[0] **= 2
x[0] -= 8
-x[0] //= 2
+x[0] /= 2
x[0] //= 2
x[0] %= 12
x[0] &= 2
@@ -33,7 +33,7 @@ x[0] += 1
x[0] *= 2
x[0] **= 2
x[0] -= 8
-x[0] //= 2
+x[0] /= 2
x[0] //= 1
x[0] %= 12
x[0] &= 2
@@ -123,14 +123,6 @@ class testall:
print "__imul__ called"
return self
- def __div__(self, val):
- print "__div__ called"
- def __rdiv__(self, val):
- print "__rdiv__ called"
- def __idiv__(self, val):
- print "__idiv__ called"
- return self
-
def __floordiv__(self, val):
print "__floordiv__ called"
return self
@@ -147,6 +139,9 @@ class testall:
def __itruediv__(self, val):
print "__itruediv__ called"
return self
+ def __rtruediv__(self, val):
+ print "__rtruediv__ called"
+ return self
def __mod__(self, val):
print "__mod__ called"
@@ -217,16 +212,9 @@ x * 1
1 * x
x *= 1
-if 1/2 == 0:
- x / 1
- 1 / x
- x /= 1
-else:
- # True division is in effect, so "/" doesn't map to __div__ etc;
- # but the canned expected-output file requires that those get called.
- x.__div__(1)
- x.__rdiv__(1)
- x.__idiv__(1)
+x / 1
+1 / x
+x /= 1
x // 1
1 // x
diff --git a/Lib/test/test_binop.py b/Lib/test/test_binop.py
index b3d9a625ff..719186b97b 100644
--- a/Lib/test/test_binop.py
+++ b/Lib/test/test_binop.py
@@ -140,8 +140,6 @@ class Rat(object):
return float(self) / other
return NotImplemented
- __div__ = __truediv__
-
def __rtruediv__(self, other):
"""Divide two Rats, or a Rat and a number (reversed args)."""
if isRat(other):
@@ -152,8 +150,6 @@ class Rat(object):
return other / float(self)
return NotImplemented
- __rdiv__ = __rtruediv__
-
def __floordiv__(self, other):
"""Divide two Rats, returning the floored result."""
if isint(other):
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py
index 92c220ef6f..b8b4cab96d 100644
--- a/Lib/test/test_class.py
+++ b/Lib/test/test_class.py
@@ -11,8 +11,8 @@ testmeths = [
"rsub",
"mul",
"rmul",
- "div",
- "rdiv",
+ "truediv",
+ "rtruediv",
"mod",
"rmod",
"divmod",
@@ -134,16 +134,8 @@ testme - 1
testme * 1
1 * testme
-if 1/2 == 0:
- testme / 1
- 1 / testme
-else:
- # True division is in effect, so "/" doesn't map to __div__ etc; but
- # the canned expected-output file requires that __div__ etc get called.
- testme.__coerce__(1)
- testme.__div__(1)
- testme.__coerce__(1)
- testme.__rdiv__(1)
+testme / 1
+1 / testme
testme % 1
1 % testme
diff --git a/Lib/test/test_coercion.py b/Lib/test/test_coercion.py
index ceea17b461..e12ef0dec0 100644
--- a/Lib/test/test_coercion.py
+++ b/Lib/test/test_coercion.py
@@ -44,10 +44,10 @@ class MethodNumber:
def __rmul__(self,other):
return other * self.arg
- def __div__(self,other):
+ def __truediv__(self,other):
return self.arg / other
- def __rdiv__(self,other):
+ def __rtruediv__(self,other):
return other / self.arg
def __pow__(self,other):
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index 0d42bd2b68..035f52403c 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -55,19 +55,15 @@ class ComplexTest(unittest.TestCase):
if x != 0:
q = z / x
self.assertClose(q, y)
- q = z.__div__(x)
- self.assertClose(q, y)
q = z.__truediv__(x)
self.assertClose(q, y)
if y != 0:
q = z / y
self.assertClose(q, x)
- q = z.__div__(y)
- self.assertClose(q, x)
q = z.__truediv__(y)
self.assertClose(q, x)
- def test_div(self):
+ def test_truediv(self):
simple_real = [float(i) for i in xrange(-5, 6)]
simple_complex = [complex(x, y) for x in simple_real for y in simple_real]
for x in simple_complex:
@@ -84,7 +80,7 @@ class ComplexTest(unittest.TestCase):
self.check_div(complex(random(), random()),
complex(random(), random()))
- self.assertRaises(ZeroDivisionError, complex.__div__, 1+1j, 0+0j)
+ self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j)
# FIXME: The following currently crashes on Alpha
# self.assertRaises(OverflowError, pow, 1e200+1j, 1e200+1j)
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 7d0addf217..1d33ec430f 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -507,7 +507,7 @@ class DecimalImplicitConstructionTest(unittest.TestCase):
('+', '__add__', '__radd__'),
('-', '__sub__', '__rsub__'),
('*', '__mul__', '__rmul__'),
- ('/', '__div__', '__rdiv__'),
+ ('/', '__truediv__', '__rtruediv__'),
('%', '__mod__', '__rmod__'),
('//', '__floordiv__', '__rfloordiv__'),
('**', '__pow__', '__rpow__'),
@@ -975,7 +975,6 @@ class DecimalUsabilityTest(unittest.TestCase):
checkSameDec("__abs__")
checkSameDec("__add__", True)
- checkSameDec("__div__", True)
checkSameDec("__divmod__", True)
checkSameDec("__cmp__", True)
checkSameDec("__float__")
@@ -990,7 +989,6 @@ class DecimalUsabilityTest(unittest.TestCase):
checkSameDec("__pos__")
checkSameDec("__pow__", True)
checkSameDec("__radd__", True)
- checkSameDec("__rdiv__", True)
checkSameDec("__rdivmod__", True)
checkSameDec("__repr__")
checkSameDec("__rfloordiv__", True)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 57a8f4454e..108d95e324 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -29,10 +29,6 @@ def testbinop(a, b, res, expr="a+b", meth="__add__"):
if verbose: print "checking", expr
dict = {'a': a, 'b': b}
- # XXX Hack so this passes before 2.3 when -Qnew is specified.
- if meth == "__div__" and 1/2 == 0.5:
- meth = "__truediv__"
-
vereq(eval(expr, dict), res)
t = type(a)
m = getattr(t, meth)
@@ -4044,9 +4040,8 @@ def notimplemented():
('__add__', 'x + y', 'x += y'),
('__sub__', 'x - y', 'x -= y'),
('__mul__', 'x * y', 'x *= y'),
- ('__truediv__', 'operator.truediv(x, y)', None),
- ('__floordiv__', 'operator.floordiv(x, y)', None),
- ('__div__', 'x / y', 'x /= y'),
+ ('__truediv__', 'x / y', None),
+ ('__floordiv__', 'x // y', None),
('__mod__', 'x % y', 'x %= y'),
('__divmod__', 'divmod(x, y)', None),
('__pow__', 'x ** y', 'x **= y'),
diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py
index c1fe88cbef..50c3b0c12c 100644
--- a/Lib/test/test_operator.py
+++ b/Lib/test/test_operator.py
@@ -144,11 +144,6 @@ class OperatorTestCase(unittest.TestCase):
self.failUnless(operator.delslice(a, 2, 8) is None)
self.assert_(a == [0, 1, 8, 9])
- def test_div(self):
- self.failUnlessRaises(TypeError, operator.div, 5)
- self.failUnlessRaises(TypeError, operator.div, None, None)
- self.failUnless(operator.floordiv(5, 2) == 2)
-
def test_floordiv(self):
self.failUnlessRaises(TypeError, operator.floordiv, 5)
self.failUnlessRaises(TypeError, operator.floordiv, None, None)
@@ -416,7 +411,6 @@ class OperatorTestCase(unittest.TestCase):
class C(object):
def __iadd__ (self, other): return "iadd"
def __iand__ (self, other): return "iand"
- def __idiv__ (self, other): return "idiv"
def __ifloordiv__(self, other): return "ifloordiv"
def __ilshift__ (self, other): return "ilshift"
def __imod__ (self, other): return "imod"
@@ -431,7 +425,6 @@ class OperatorTestCase(unittest.TestCase):
c = C()
self.assertEqual(operator.iadd (c, 5), "iadd")
self.assertEqual(operator.iand (c, 5), "iand")
- self.assertEqual(operator.idiv (c, 5), "idiv")
self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv")
self.assertEqual(operator.ilshift (c, 5), "ilshift")
self.assertEqual(operator.imod (c, 5), "imod")
@@ -446,7 +439,6 @@ class OperatorTestCase(unittest.TestCase):
self.assertEqual(operator.irepeat (c, 5), "imul")
self.assertEqual(operator.__iadd__ (c, 5), "iadd")
self.assertEqual(operator.__iand__ (c, 5), "iand")
- self.assertEqual(operator.__idiv__ (c, 5), "idiv")
self.assertEqual(operator.__ifloordiv__(c, 5), "ifloordiv")
self.assertEqual(operator.__ilshift__ (c, 5), "ilshift")
self.assertEqual(operator.__imod__ (c, 5), "imod")