diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-04-10 03:55:56 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-04-10 03:55:56 (GMT) |
commit | d51374ed78a3e3145911a16cdf3b9b84b3ba7d15 (patch) | |
tree | 31f9086f20f5b8923604f41f1a4d139fa809aaed /Lib/test/test_operator.py | |
parent | 2aad6ef77419887f5875ba942e9369b4bdd34a5e (diff) | |
download | cpython-d51374ed78a3e3145911a16cdf3b9b84b3ba7d15.zip cpython-d51374ed78a3e3145911a16cdf3b9b84b3ba7d15.tar.gz cpython-d51374ed78a3e3145911a16cdf3b9b84b3ba7d15.tar.bz2 |
PEP 465: a dedicated infix operator for matrix multiplication (closes #21176)
Diffstat (limited to 'Lib/test/test_operator.py')
-rw-r--r-- | Lib/test/test_operator.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py index ab58a98..1bd0391 100644 --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -203,6 +203,15 @@ class OperatorTestCase: self.assertRaises(TypeError, operator.mul, None, None) self.assertTrue(operator.mul(5, 2) == 10) + def test_matmul(self): + operator = self.module + self.assertRaises(TypeError, operator.matmul) + self.assertRaises(TypeError, operator.matmul, 42, 42) + class M: + def __matmul__(self, other): + return other - 1 + self.assertEqual(M() @ 42, 41) + def test_neg(self): operator = self.module self.assertRaises(TypeError, operator.neg) @@ -416,6 +425,7 @@ class OperatorTestCase: def __ilshift__ (self, other): return "ilshift" def __imod__ (self, other): return "imod" def __imul__ (self, other): return "imul" + def __imatmul__ (self, other): return "imatmul" def __ior__ (self, other): return "ior" def __ipow__ (self, other): return "ipow" def __irshift__ (self, other): return "irshift" @@ -430,6 +440,7 @@ class OperatorTestCase: self.assertEqual(operator.ilshift (c, 5), "ilshift") self.assertEqual(operator.imod (c, 5), "imod") self.assertEqual(operator.imul (c, 5), "imul") + self.assertEqual(operator.imatmul (c, 5), "imatmul") self.assertEqual(operator.ior (c, 5), "ior") self.assertEqual(operator.ipow (c, 5), "ipow") self.assertEqual(operator.irshift (c, 5), "irshift") |