diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2015-10-22 04:49:36 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2015-10-22 04:49:36 (GMT) |
commit | 6a4d52e86521cfabd0646daacd31ba08e6098a78 (patch) | |
tree | 8fa8b4f5a918af01fcae12b2289c51db97c8efd2 /Lib/test/test_richcmp.py | |
parent | c2a753a56c7b36159b93f6a10327f6ccb90a36e9 (diff) | |
download | cpython-6a4d52e86521cfabd0646daacd31ba08e6098a78.zip cpython-6a4d52e86521cfabd0646daacd31ba08e6098a78.tar.gz cpython-6a4d52e86521cfabd0646daacd31ba08e6098a78.tar.bz2 |
Issue #25210: Add some basic tests for the new exception message
Diffstat (limited to 'Lib/test/test_richcmp.py')
-rw-r--r-- | 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 index 1582caa..58729a9 100644 --- a/Lib/test/test_richcmp.py +++ b/Lib/test/test_richcmp.py @@ -253,6 +253,31 @@ class MiscTest(unittest.TestCase): 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): |