forked from learnbyexample/Python_Basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunittest_palindrome.py
More file actions
36 lines (27 loc) · 1.1 KB
/
unittest_palindrome.py
File metadata and controls
36 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python3
import palindrome
import unittest
class TestPalindrome(unittest.TestCase):
def test_valid(self):
# check valid input strings
self.assertTrue(palindrome.is_palindrome('kek'))
self.assertTrue(palindrome.is_palindrome("Dammit, I'm mad!"))
self.assertFalse(palindrome.is_palindrome('zzz'))
self.assertFalse(palindrome.is_palindrome('cool'))
def test_error(self):
# check only the exception raised
with self.assertRaises(ValueError):
palindrome.is_palindrome('abc123')
with self.assertRaises(TypeError):
palindrome.is_palindrome(7)
# check error message as well
with self.assertRaises(ValueError) as cm:
palindrome.is_palindrome('on 2 no')
em = str(cm.exception)
self.assertEqual(em, 'Characters other than alphabets and punctuations')
with self.assertRaises(ValueError) as cm:
palindrome.is_palindrome('to')
em = str(cm.exception)
self.assertEqual(em, 'Less than 3 alphabets')
if __name__ == '__main__':
unittest.main()