forked from kiat/Elements-of-Software-Design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_005_unittest_001.py
45 lines (31 loc) · 1.42 KB
/
example_005_unittest_001.py
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
36
37
38
39
40
41
42
43
44
45
"""A simple example to demonstrate Python unit test framework."""
# Main documentation is here
# https://docs.python.org/3/library/unittest.html
import unittest
from student import Course, Student
class TestStudent(unittest.TestCase):
"""Unit tests for the functions defined in student.py."""
def test_generate_email001(self):
"""Test generating an email with assertEqual."""
cs313e = Course("CS313E", 4, 3000)
cs329e = Course("CS329E", 4, 2500)
course_list1 = [cs313e, cs329e]
john = Student("John", "Doe", "01/01/1996", course_list1)
self.assertEqual(john.generate_email(
"utexas.edu"), "[email protected]")
def test_generate_email002(self):
"""Test generating an email with assertTrue."""
cs313e = Course("CS313E", 4, 3000)
cs329e = Course("CS329E", 4, 2500)
course_list1 = [cs313e, cs329e]
john = Student("John", "Doe", "01/01/1996", course_list1)
self.assertTrue("@" in list(john.generate_email("utexas.edu")))
def test_generate_email003(self):
"""Test generating an email with assertIn."""
cs313e = Course("CS313E", 4, 3000)
cs329e = Course("CS329E", 4, 2500)
course_list1 = [cs313e, cs329e]
john = Student("John", "Doe", "01/01/1996", course_list1)
self.assertIn("@", list(john.generate_email("utexas.edu")))
if __name__ == '__main__':
unittest.main()