[Python-checkins] cpython: Issue #25210: Add some basic tests for the new exception message

berker.peksag python-checkins at python.org
Thu Oct 22 00:49:15 EDT 2015


https://hg.python.org/cpython/rev/5c7dd88cd0c5
changeset:   98825:5c7dd88cd0c5
user:        Berker Peksag <berker.peksag at gmail.com>
date:        Thu Oct 22 07:49:36 2015 +0300
summary:
  Issue #25210: Add some basic tests for the new exception message

files:
  Lib/test/test_richcmp.py |  25 +++++++++++++++++++++++++
  1 files changed, 25 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_richcmp.py b/Lib/test/test_richcmp.py
--- a/Lib/test/test_richcmp.py
+++ b/Lib/test/test_richcmp.py
@@ -253,6 +253,31 @@
         self.assertTrue(a != b)
         self.assertTrue(a < b)
 
+    def test_exception_message(self):
+        class Spam:
+            pass
+
+        tests = [
+            (lambda: 42 < None, r"'<' .* of 'int' and 'NoneType'"),
+            (lambda: None < 42, r"'<' .* of 'NoneType' and 'int'"),
+            (lambda: 42 > None, r"'>' .* of 'int' and 'NoneType'"),
+            (lambda: "foo" < None, r"'<' .* of 'str' and 'NoneType'"),
+            (lambda: "foo" >= 666, r"'>=' .* of 'str' and 'int'"),
+            (lambda: 42 <= None, r"'<=' .* of 'int' and 'NoneType'"),
+            (lambda: 42 >= None, r"'>=' .* of 'int' and 'NoneType'"),
+            (lambda: 42 < [], r"'<' .* of 'int' and 'list'"),
+            (lambda: () > [], r"'>' .* of 'tuple' and 'list'"),
+            (lambda: None >= None, r"'>=' .* of 'NoneType' and 'NoneType'"),
+            (lambda: Spam() < 42, r"'<' .* of 'Spam' and 'int'"),
+            (lambda: 42 < Spam(), r"'<' .* of 'int' and 'Spam'"),
+            (lambda: Spam() <= Spam(), r"'<=' .* of 'Spam' and 'Spam'"),
+        ]
+        for i, test in enumerate(tests):
+            with self.subTest(test=i):
+                with self.assertRaisesRegex(TypeError, test[1]):
+                    test[0]()
+
+
 class DictTest(unittest.TestCase):
 
     def test_dicts(self):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list