-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_student.py
86 lines (65 loc) · 2.71 KB
/
test_student.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from unittest import TestCase
from student import Student
class TestStudent(TestCase):
def test_id_getter(self):
"""Checks that id getter works without error"""
test_student = Student("Asmar", 23, 1)
self.assertEqual(test_student.id, 1)
def test_name_getter(self):
"""Checks that name getter works without error"""
test_student = Student("Asmar", 23, 1)
self.assertEqual(test_student.name, "Asmar")
def test_age_getter(self):
"""Checks that age getter works without error"""
test_student = Student("Asmar", 23, 1)
self.assertEqual(test_student.age, 23)
def test_negative_id_exception(self):
"""Checks that negative id results in a TypeError"""
with self.assertRaises(TypeError):
Student("Asmar", 23, -1)
def test_negative_age_exception(self):
"""Checks that negative age results in a TypeError"""
with self.assertRaises(TypeError):
Student("Asmar", -1, 1)
def test_no_id_exception(self):
"""
Checks that creating a student without an id results in a TypeError
"""
with self.assertRaises(TypeError):
Student("Asmar", 23)
def test_no_name_exception(self):
"""
Checks that creating a student without a name results in a TypeError
"""
with self.assertRaises(TypeError):
Student(age=23, id=1)
def test_no_age_exception(self):
"""
Checks that creating a student without an age results in a TypeError
"""
with self.assertRaises(TypeError):
Student("Asmar", id=1)
def test_wrong_id_type_exception(self):
"""Checks that not having id as an integer results in a TypeError"""
with self.assertRaises(TypeError):
Student("Asmar", 23, "1")
with self.assertRaises(TypeError):
Student("Asmar", 23, True)
with self.assertRaises(TypeError):
Student("Asmar", 23, 1.0)
def test_wrong_age_type_exception(self):
"""Checks that not having age as an integer results in a TypeError"""
with self.assertRaises(TypeError):
Student("Asmar", "23", 1)
with self.assertRaises(TypeError):
Student("Asmar", False, 1)
with self.assertRaises(TypeError):
Student("Asmar", 23.0, 1)
def test_wrong_name_type_exception(self):
"""Checks that not having name as a string results in a TypeError"""
with self.assertRaises(TypeError):
Student(True, 23, 1)
with self.assertRaises(TypeError):
Student(5, 23, 1)
with self.assertRaises(TypeError):
Student(['A', 's', 'm', 'a', 'r'], 23, 1)