AssertionError: tests


what is an assertion? tests

The code in assertion_error/tests/test_assertion_error.py from AssertionError

  1def test_assert_keyword():
  2    assert 1 + 1 == 2
  3
  4    assert '1' + '1' == '11'
  5
  6    assert 'I am' + ' alive' == 'I am alive'
  7
  8
  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
 29
 30
 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
 51
 52
 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
 73
 74
 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
 87
 88
 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    assert False == True
 97
 98
 99def test_failure():
100    # assert False == True
101    assert False == False
102
103
104# NOTES
105# a dictionary is not True
106# a dictionary is not False
107# a dictionary is not None
108# a set is not True
109# a set is not False
110# a set is not None
111# a list is not True
112# a list is not False
113# a list is not None
114# a tuple is not True
115# a tuple is not False
116# a tuple is not None
117# a string is not True
118# a string is not False
119# a string is not None
120# a float is not True
121# a float is not False
122# a float is not None
123# an integer is not True
124# an integer is not False
125# an integer is not None
126# True is True and equal to True
127# True is not False and NOT equal to False
128# True is not None and NOT equal to None
129# False is not True and NOT equal to True
130# False is False and equal to False
131# False is not None and NOT equal to None
132# None is not True and NOT equal to True
133# None is not False and NOT equal to False
134# None is None and equal to None
135
136
137# Exceptions seen
138# AssertionError

test AssertionError with unittest: tests

The code in assertion_error/tests/test_assertion_error.py from test AssertionError with unittest

  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
 34        assert False is not None
 35        self.assertIsNot(False, None)
 36
 37        assert True is not None
 38        self.assertIsNot(True, None)
 39
 40        assert self.an_integer is not None
 41        self.assertIsNot(self.an_integer, None)
 42
 43        assert self.a_float is not None
 44        self.assertIsNot(self.a_float, None)
 45
 46        assert self.a_string is not None
 47        self.assertIsNot(self.a_string, None)
 48
 49        assert self.a_tuple is not None
 50        self.assertIsNot(self.a_tuple, None)
 51
 52        assert self.a_list is not None
 53        self.assertIsNot(self.a_list, None)
 54
 55        assert self.a_set is not None
 56        self.assertIsNot(self.a_set, None)
 57
 58        assert self.a_dictionary is not None
 59        self.assertIsNot(self.a_dictionary, None)
 60
 61    def test_assertion_error_w_false(self):
 62        assert None is not False
 63        self.assertIsNot(None, False)
 64
 65        assert False is False
 66        self.assertIs(False, False)
 67
 68        assert True is not False
 69        self.assertIsNot(True, False)
 70
 71        assert self.an_integer is not False
 72        self.assertIsNot(self.an_integer, False)
 73
 74        assert self.a_float is not False
 75        self.assertIsNot(self.a_float, False)
 76
 77        assert self.a_string is not False
 78        self.assertIsNot(self.a_string, False)
 79
 80        assert self.a_tuple is not False
 81        self.assertIsNot(self.a_tuple, False)
 82
 83        assert self.a_list is not False
 84        self.assertIsNot(self.a_list, False)
 85
 86        assert self.a_set is not False
 87        self.assertIsNot(self.a_set, False)
 88
 89        assert self.a_dictionary is not False
 90        self.assertIsNot(self.a_dictionary, False)
 91
 92    def test_assertion_error_w_true(self):
 93        assert None is not True
 94        self.assertIsNot(None, True)
 95
 96        assert False is not True
 97        self.assertIsNot(False, True)
 98
 99        assert True is True
100        self.assertIs(True, True)
101
102        assert self.an_integer is not True
103        self.assertIsNot(self.an_integer, True)
104
105        assert self.a_float is not True
106        self.assertIsNot(self.a_float, True)
107
108        assert self.a_string is not True
109        self.assertIsNot(self.a_string, True)
110
111        assert self.a_tuple is not True
112        self.assertIsNot(self.a_tuple, True)
113
114        assert self.a_list is not True
115        self.assertIsNot(self.a_list, True)
116
117        assert self.a_set is not True
118        self.assertIsNot(self.a_set, True)
119
120        assert self.a_dictionary is not True
121        self.assertIsNot(self.a_dictionary, True)
122
123    def test_assertion_error_w_equality(self):
124        assert None == None
125        self.assertEqual(None, None)
126
127        assert False != None
128        self.assertNotEqual(False, None)
129
130        assert False != True
131        self.assertNotEqual(False, True)
132
133        assert False == False
134        self.assertEqual(False, False)
135
136        assert True != None
137        self.assertNotEqual(True, None)
138
139        assert True == True
140        self.assertEqual(True, True)
141
142    def test_assertion_error_w_is_vs_equal(self):
143        assert 0 is not 0.0
144        self.assertIsNot(0, 0.0)
145
146        assert 0 == 0.0
147        self.assertEqual(0, 0.0)
148
149    def will_not_run():
150        assert False == True
151        self.assertEqual(False, True)
152
153    def test_failure(self):
154        assert False == False
155        self.assertEqual(False, False)
156
157
158# NOTES
159# a dictionary is not True
160# a dictionary is not False
161# a dictionary is not None
162# a set is not True
163# a set is not False
164# a set is not None
165# a list is not True
166# a list is not False
167# a list is not None
168# a tuple is not True
169# a tuple is not False
170# a tuple is not None
171# a string is not True
172# a string is not False
173# a string is not None
174# a float is not True
175# a float is not False
176# a float is not None
177# an integer is not True
178# an integer is not False
179# an integer is not None
180# True is True and equal to True
181# True is not False and NOT equal to False
182# True is not None and NOT equal to None
183# False is not True and NOT equal to True
184# False is False and equal to False
185# False is not None and NOT equal to None
186# None is not True and NOT equal to True
187# None is not False and NOT equal to False
188# None is None and equal to None
189
190
191# Exceptions seen
192# AssertionError
193# AttributeError
194# NameError
195# TypeError

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 True
170# a dictionary is not False
171# a dictionary is not None
172# a set is not True
173# a set is not False
174# a set is not None
175# a list is not True
176# a list is not False
177# a list is not None
178# a tuple is not True
179# a tuple is not False
180# a tuple is not None
181# a string is not True
182# a string is not False
183# a string is not None
184# a float is not True
185# a float is not False
186# a float is not None
187# an integer is not True
188# an integer is not False
189# an integer is not None
190# True is True and equal to True
191# True is not False and NOT equal to False
192# True is not None and NOT equal to None
193# False is not True and NOT equal to True
194# False is False and equal to False
195# False is not None and NOT equal to None
196# None is not True and NOT equal to True
197# None is not 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