Implement checks for raising messages with exceptions (#1113)

* Implement checks for messages being raised with exceptions
(Fixes #1080)

* Add self.assertRaisesWithMessage method to relevant exercise tests
    - Uses self.assertRaisesRegex
    - Checks only for the presence of a message, not content
* Add meaningful messages to failing examples
* octal: Switch to using a context manager for exception tests

* Add note regarding error messages to the insert

* simple-linked-list: Move hints.md to correct location

* simple-cipher: Remove extra whitespace from lines

* collatz-conjecture: Update hints.md

* Regenerate README to include exceptions section
This commit is contained in:
Nathan Parsons
2017-12-12 18:11:43 +00:00
committed by Corey McCandless
parent 2f93a626f1
commit f53e2ef08b
152 changed files with 2252 additions and 230 deletions

View File

@@ -32,21 +32,31 @@ class BinaryTests(unittest.TestCase):
self.assertEqual(parse_binary("10001101000"), 1128)
def test_invalid_binary_text_only(self):
with self.assertRaises(ValueError):
with self.assertRaisesWithMessage(ValueError):
parse_binary("carrot")
def test_invalid_binary_number_not_base2(self):
with self.assertRaises(ValueError):
with self.assertRaisesWithMessage(ValueError):
parse_binary("102011")
def test_invalid_binary_numbers_with_text(self):
with self.assertRaises(ValueError):
with self.assertRaisesWithMessage(ValueError):
parse_binary("10nope")
def test_invalid_binary_text_with_numbers(self):
with self.assertRaises(ValueError):
with self.assertRaisesWithMessage(ValueError):
parse_binary("nope10")
# Utility functions
def setUp(self):
try:
self.assertRaisesRegex = self.assertRaisesRegexp
except AttributeError:
pass
def assertRaisesWithMessage(self, exception):
return self.assertRaisesRegex(exception, r".+")
if __name__ == '__main__':
unittest.main()