AssertionError: tests
what is an assertion?: tests
The code in assertion_error/tests/test_assertion_error.py from what is an assertion?
1def test_assert_keyword():
2 assert 1 + 1 == 2
3
4 assert '1' + '1' == '11'
5
6 assert 'I am' + ' alive' == 'I am alive'
9def test_assertion_error_w_none():
10 assert None is None
11
12 assert False is not None
13
14 assert True is not None
15
16 assert 0 is not None
17
18 assert 0.0 is not None
19
20 assert '' is not None
21
22 assert () is not None
23
24 assert [] is not None
25
26 assert set() is not None
27
28 assert {} is not None
31def test_assertion_error_w_false():
32 assert None is not False
33
34 assert False is False
35
36 assert True is not False
37
38 assert 0 is not False
39
40 assert 0.0 is not False
41
42 assert '' is not False
43
44 assert () is not False
45
46 assert [] is not False
47
48 assert set() is not False
49
50 assert {} is not False
53def test_assertion_error_w_true():
54 assert None is not True
55
56 assert False is not True
57
58 assert True is True
59
60 assert 0 is not True
61
62 assert 0.0 is not True
63
64 assert '' is not True
65
66 assert () is not True
67
68 assert [] is not True
69
70 assert set() is not True
71
72 assert {} is not True
75def test_assertion_error_w_equality():
76 assert None == None
77
78 assert False != None
79
80 assert False != True
81
82 assert False == False
83
84 assert True != None
85
86 assert True == True
89def test_assertion_error_w_is_vs_equal():
90 assert 0 is not 0.0
91
92 assert 0 == 0.0
93
94
95def will_not_run():
96 # will not run because
97 # the name does not start with test
98 assert False == True
99
100
101def test_failure():
102 # assert False == True
103 assert False != True
106# NOTES
107# a dictionary is not the same object as True
108# a dictionary is not the same object as False
109# a dictionary is not the same object as None
110# a set is not the same object as True
111# a set is not the same object as False
112# a set is not the same object as None
113# a list is not the same object as True
114# a list is not the same object as False
115# a list is not the same object as None
116# a tuple is not the same object as True
117# a tuple is not the same object as False
118# a tuple is not the same object as None
119# a string is not the same object as True
120# a string is not the same object as False
121# a string is not the same object as None
122# a float is not the same object as True
123# a float is not the same object as False
124# a float is not the same object as None
125# an integer is not the same object as True
126# an integer is not the same object as False
127# an integer is not the same object as None
128# True is True and equal to True
129# True is not equal to False
130# True is not the same object as False
131# True is not equal to None
132# True is not the same object as None
133# False is not equal to True
134# False is not the same object as True
135# False is False and equal to False
136# False is not equal to None
137# False is not the same object as None
138# None is not equal to True
139# None is not the same object as True
140# None is not equal to False
141# None is not the same object as False
142# None is None and equal to None
143
144# Exceptions seen
145# AssertionError
146# IndentationError
test AssertionError with functions: tests
The code in assertion_error/tests/test_assertion_error.py from test AssertionError with functions
1def assert_is_not(x, y):
2 assert x is not y
3
4
5def assert_is_not_none(x):
6 assert_is_not(x, None)
7
8
9def assert_is_not_false(x):
10 assert_is_not(x, False)
13def assert_is_not_true(x):
14 assert_is_not(x, True)
15
16
17def assert_not_equal(x, y):
18 assert x != y
19
20
21def assert_equal(x, y):
22 assert x == y
25def test_assert_keyword():
26 assert_equal(1+1, 2)
27 assert_equal('1'+'1', '11')
28 assert_equal('I am'+' alive', 'I am alive')
31def test_assertion_error_w_none():
32 assert None is None
33
34 assert_is_not_none(False)
35 assert_is_not_none(True)
36 assert_is_not_none(0)
37 assert_is_not_none(0.0)
38 assert_is_not_none('')
39 assert_is_not_none(())
40 assert_is_not_none([])
41 assert_is_not_none(set())
42 assert_is_not_none({})
45def test_assertion_error_w_false():
46 assert False is False
47
48 assert_is_not_false(None)
49 assert_is_not_false(True)
50 assert_is_not_false(0)
51 assert_is_not_false(0.0)
52 assert_is_not_false('')
53 assert_is_not_false(())
54 assert_is_not_false([])
55 assert_is_not_false(set())
56 assert_is_not_false({})
59def test_assertion_error_w_true():
60 assert True is True
61
62 assert_is_not_true(None)
63 assert_is_not_true(False)
64 assert_is_not_true(0)
65 assert_is_not_true(0.0)
66 assert_is_not_true('')
67 assert_is_not_true(())
68 assert_is_not_true([])
69 assert_is_not_true(set())
70 assert_is_not_true({})
73def test_assertion_error_w_equality():
74 assert_equal(None, None)
75 assert_equal(False, False)
76 assert_equal(True, True)
77
78 assert_not_equal(False, None)
79 assert_not_equal(False, True)
80 assert_not_equal(True, None)
83def test_assertion_error_w_is_vs_equal():
84 assert_is_not(0, 0.0)
85 assert_equal(0, 0.0)
86
87
88def will_not_run():
89 # will not run because
90 # the name does not start with test
91 assert False == True
92
93
94def test_failure():
95 # assert False == True
96 assert_not_equal(False, True)
97
98
99# NOTES
test AssertionError with unittest: tests
The code in assertion_error/tests/test_assertion_error.py from test AssertionError with unittest
28class TestAssertionError(unittest.TestCase):
29
30 an_integer = 0
31 a_float = 0.0
32 a_string = ''
33 a_tuple = ()
34 a_list = []
35 a_set = set()
36 a_dictionary = {}
38 def test_assert_keyword(self):
39 reality = 1 + 1
40 my_expectation = 2
41 assert_equal(reality, my_expectation)
42 self.assertEqual(reality, my_expectation)
43
44 reality = '1' + '1'
45 my_expectation = '11'
46 assert_equal(reality, my_expectation)
47 self.assertEqual(reality, my_expectation)
48
49 reality = 'I am' + ' alive'
50 my_expectation = 'I am alive'
51 assert_equal(reality, my_expectation)
52 self.assertEqual(reality, my_expectation)
54 def test_assertion_error_w_none(self):
55 assert None is None
56 self.assertIs(None, None)
57
58 assert_is_not_none(False)
59 self.assertIsNot(False, None)
60
61 assert_is_not_none(True)
62 self.assertIsNot(True, None)
63
64 assert_is_not_none(self.an_integer)
65 self.assertIsNot(self.an_integer, None)
66
67 assert_is_not_none(self.a_float)
68 self.assertIsNot(self.a_float, None)
69
70 assert_is_not_none(self.a_string)
71 self.assertIsNot(self.a_string, None)
72
73 assert_is_not_none(self.a_tuple)
74 self.assertIsNot(self.a_tuple, None)
75
76 assert_is_not_none(self.a_list)
77 self.assertIsNot(self.a_list, None)
78
79 assert_is_not_none(self.a_set)
80 self.assertIsNot(self.a_set, None)
81
82 assert_is_not_none(self.a_dictionary)
83 self.assertIsNot(self.a_dictionary, None)
85 def test_assertion_error_w_false(self):
86 assert False is False
87 self.assertIs(False, False)
88
89 assert_is_not_false(None)
90 self.assertIsNot(None, False)
91
92 assert_is_not_false(True)
93 self.assertIsNot(True, False)
94
95 assert_is_not_false(self.an_integer)
96 self.assertIsNot(self.an_integer, False)
97
98 assert_is_not_false(self.a_float)
99 self.assertIsNot(self.a_float, False)
100
101 assert_is_not_false(self.a_string)
102 self.assertIsNot(self.a_string, False)
103
104 assert_is_not_false(self.a_tuple)
105 self.assertIsNot(self.a_tuple, False)
106
107 assert_is_not_false(self.a_list)
108 self.assertIsNot(self.a_list, False)
109
110 assert_is_not_false(self.a_set)
111 self.assertIsNot(self.a_set, False)
112
113 assert_is_not_false(self.a_dictionary)
114 self.assertIsNot(self.a_dictionary, False)
116 def test_assertion_error_w_true(self):
117 assert True is True
118 self.assertIs(True, True)
119
120 assert_is_not_true(None)
121 self.assertIsNot(None, True)
122
123 assert_is_not_true(False)
124 self.assertIsNot(False, True)
125
126 assert_is_not_true(self.an_integer)
127 self.assertIsNot(self.an_integer, True)
128
129 assert_is_not_true(self.a_float)
130 self.assertIsNot(self.a_float, True)
131
132 assert_is_not_true(self.a_string)
133 self.assertIsNot(self.a_string, True)
134
135 assert_is_not_true(self.a_tuple)
136 self.assertIsNot(self.a_tuple, True)
137
138 assert_is_not_true(self.a_list)
139 self.assertIsNot(self.a_list, True)
140
141 assert_is_not_true(self.a_set)
142 self.assertIsNot(self.a_set, True)
143
144 assert_is_not_true(self.a_dictionary)
145 self.assertIsNot(self.a_dictionary, True)
147 def test_assertion_error_w_equality(self):
148 assert_equal(None, None)
149 self.assertEqual(None, None)
150
151 assert_equal(False, False)
152 self.assertEqual(False, False)
153
154 assert_equal(True, True)
155 self.assertEqual(True, True)
156
157 assert_not_equal(False, None)
158 self.assertNotEqual(False, None)
159
160 assert_not_equal(False, True)
161 self.assertNotEqual(False, True)
162
163 assert_not_equal(True, None)
164 self.assertNotEqual(True, None)
166 def test_assertion_error_w_is_vs_equal(self):
167 assert_is_not(0, 0.0)
168 self.assertIsNot(0, 0.0)
169
170 assert_equal(0, 0.0)
171 self.assertEqual(0, 0.0)
173 def will_not_run():
174 # will not run because
175 # the name does not start with test
176 assert False == True
177 self.assertEqual(False, True)
178
179 def test_failure(self):
180 assert_not_equal(False, True)
181 self.assertEqual(False, False)
182
183
184# NOTES
test AssertionError with assertIsNotNone and assertIsNone: tests
The code in assertion_error/tests/test_assertion_error.py from test AssertionError with assertIsNotNone and assertIsNone
1import unittest 2 3 4class TestAssertionError(unittest.TestCase): 5 6 an_integer = 0 7 a_float = 0.0 8 a_string = '' 9 a_tuple = () 10 a_list = [] 11 a_set = set() 12 a_dictionary = {} 13 14 def test_assert_keyword(self): 15 reality = 1 + 1 16 my_expectation = 2 17 assert reality == my_expectation 18 self.assertEqual(reality, my_expectation) 19 20 reality = '1' + '1' 21 my_expectation = '11' 22 assert reality == my_expectation 23 self.assertEqual(reality, my_expectation) 24 25 reality = 'I am' + ' alive' 26 my_expectation = 'I am alive' 27 assert reality == my_expectation 28 self.assertEqual(reality, my_expectation) 29 30 def test_assertion_error_w_none(self): 31 assert None is None 32 self.assertIs(None, None) 33 self.assertIsNone(None) 34 35 assert False is not None 36 self.assertIsNot(False, None) 37 self.assertIsNotNone(False) 38 39 assert True is not None 40 self.assertIsNot(True, None) 41 self.assertIsNotNone(True) 42 43 assert self.an_integer is not None 44 self.assertIsNot(self.an_integer, None) 45 self.assertIsNotNone(self.an_integer) 46 47 assert self.a_float is not None 48 self.assertIsNot(self.a_float, None) 49 self.assertIsNotNone(self.a_float) 50 51 assert self.a_string is not None 52 self.assertIsNot(self.a_string, None) 53 self.assertIsNotNone(self.a_string) 54 55 assert self.a_tuple is not None 56 self.assertIsNot(self.a_tuple, None) 57 self.assertIsNotNone(self.a_tuple) 58 59 assert self.a_list is not None 60 self.assertIsNot(self.a_list, None) 61 self.assertIsNotNone(self.a_list) 62 63 assert self.a_set is not None 64 self.assertIsNot(self.a_set, None) 65 self.assertIsNotNone(self.a_set) 66 67 assert self.a_dictionary is not None 68 self.assertIsNot(self.a_dictionary, None) 69 self.assertIsNotNone(self.a_dictionary) 70 71 def test_assertion_error_w_false(self): 72 assert None is not False 73 self.assertIsNot(None, False) 74 75 assert False is False 76 self.assertIs(False, False) 77 78 assert True is not False 79 self.assertIsNot(True, False) 80 81 assert self.an_integer is not False 82 self.assertIsNot(self.an_integer, False) 83 84 assert self.a_float is not False 85 self.assertIsNot(self.a_float, False) 86 87 assert self.a_string is not False 88 self.assertIsNot(self.a_string, False) 89 90 assert self.a_tuple is not False 91 self.assertIsNot(self.a_tuple, False) 92 93 assert self.a_list is not False 94 self.assertIsNot(self.a_list, False) 95 96 assert self.a_set is not False 97 self.assertIsNot(self.a_set, False) 98 99 assert self.a_dictionary is not False 100 self.assertIsNot(self.a_dictionary, False) 101 102 def test_assertion_error_w_true(self): 103 assert None is not True 104 self.assertIsNot(None, True) 105 106 assert False is not True 107 self.assertIsNot(False, True) 108 109 assert True is True 110 self.assertIs(True, True) 111 112 assert self.an_integer is not True 113 self.assertIsNot(self.an_integer, True) 114 115 assert self.a_float is not True 116 self.assertIsNot(self.a_float, True) 117 118 assert self.a_string is not True 119 self.assertIsNot(self.a_string, True) 120 121 assert self.a_tuple is not True 122 self.assertIsNot(self.a_tuple, True) 123 124 assert self.a_list is not True 125 self.assertIsNot(self.a_list, True) 126 127 assert self.a_set is not True 128 self.assertIsNot(self.a_set, True) 129 130 assert self.a_dictionary is not True 131 self.assertIsNot(self.a_dictionary, True) 132 133 def test_assertion_error_w_equality(self): 134 assert None == None 135 self.assertEqual(None, None) 136 137 assert False != None 138 self.assertNotEqual(False, None) 139 140 assert False != True 141 self.assertNotEqual(False, True) 142 143 assert False == False 144 self.assertEqual(False, False) 145 146 assert True != None 147 self.assertNotEqual(True, None) 148 149 assert True == True 150 self.assertEqual(True, True) 151 152 def test_assertion_error_w_is_vs_equal(self): 153 assert 0 is not 0.0 154 self.assertIsNot(0, 0.0) 155 156 assert 0 == 0.0 157 self.assertEqual(0, 0.0) 158 159 def will_not_run(): 160 assert False == True 161 self.assertEqual(False, True) 162 163 def test_failure(self): 164 assert False == False 165 self.assertEqual(False, False) 166 167 168# NOTES 169# a dictionary is not the same object as True 170# a dictionary is not the same object as False 171# a dictionary is not the same object as None 172# a set is not the same object as True 173# a set is not the same object as False 174# a set is not the same object as None 175# a list is not the same object as True 176# a list is not the same object as False 177# a list is not the same object as None 178# a tuple is not the same object as True 179# a tuple is not the same object as False 180# a tuple is not the same object as None 181# a string is not the same object as True 182# a string is not the same object as False 183# a string is not the same object as None 184# a float is not the same object as True 185# a float is not the same object as False 186# a float is not the same object as None 187# an integer is not the same object as True 188# an integer is not the same object as False 189# an integer is not the same object as None 190# True is True and equal to True 191# True is not the same object as False and NOT equal to False 192# True is not the same object as None and NOT equal to None 193# False is not the same object as True and NOT equal to True 194# False is False and equal to False 195# False is not the same object as None and NOT equal to None 196# None is not the same object as True and NOT equal to True 197# None is not the same object as False and NOT equal to False 198# None is None and equal to None 199 200 201# Exceptions seen 202# AssertionError 203# AttributeError 204# NameError 205# TypeError