AssertionError: tests

  • the code from assertion_error/tests/test_assertion_error.py from AssertionError

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

      1import unittest
      2
      3
      4class TestAssertionError(unittest.TestCase):
      5
      6    an_integer = 0
      7    a_float = 0.0
      8    a_string = 'a string'
      9    a_tuple = (1, 2, 3, 'n')
     10    a_list = [1, 2, 3, 'n']
     11    a_set = {1, 2, 3, 'n'}
     12    a_dictionary = {'key': 'value'}
     13
     14    def test_what_is_an_assertion(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
    150# NOTES
    151# a dictionary is not True
    152# a dictionary is not False
    153# a dictionary is not None
    154# a set is not True
    155# a set is not False
    156# a set is not None
    157# a list is not True
    158# a list is not False
    159# a list is not None
    160# a tuple is not True
    161# a tuple is not False
    162# a tuple is not None
    163# a string is not True
    164# a string is not False
    165# a string is not None
    166# a float is not True
    167# a float is not False
    168# a float is not None
    169# an integer is not True
    170# an integer is not False
    171# an integer is not None
    172# True is True and equal to True
    173# True is not False and NOT equal to False
    174# True is not None and NOT equal to None
    175# False is not True and NOT equal to True
    176# False is False and equal to False
    177# False is not None and NOT equal to None
    178# None is not True and NOT equal to True
    179# None is not False and NOT equal to False
    180# None is None and equal to None
    181
    182
    183# Exceptions seen
    184# AssertionError
    185# NameError
    
  • the code from assertion_error/tests/test_assertion_error.py from AssertionError 3: use assertIsNotNone and assertIsNone

      1import unittest
      2
      3
      4class TestAssertionError(unittest.TestCase):
      5
      6    an_integer = 0
      7    a_float = 0.0
      8    a_string = 'a string'
      9    a_tuple = (1, 2, 3, 'n')
     10    a_list = [1, 2, 3, 'n']
     11    a_set = {1, 2, 3, 'n'}
     12    a_dictionary = {'key': 'value'}
     13
     14    def test_what_is_an_assertion(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        self.assertIsNone(None)
     32        self.assertIsNotNone(False)
     33        self.assertIsNotNone(True)
     34        self.assertIsNotNone(self.an_integer)
     35        self.assertIsNotNone(self.a_float)
     36        self.assertIsNotNone(self.a_string)
     37        self.assertIsNotNone(self.a_tuple)
     38        self.assertIsNotNone(self.a_list)
     39        self.assertIsNotNone(self.a_set)
     40        self.assertIsNotNone(self.a_dictionary)
     41
     42    def test_assertion_error_w_false(self):
     43        assert None is not False
     44        self.assertIsNot(None, False)
     45
     46        assert False is False
     47        self.assertIs(False, False)
     48
     49        assert True is not False
     50        self.assertIsNot(True, False)
     51
     52        assert self.an_integer is not False
     53        self.assertIsNot(self.an_integer, False)
     54
     55        assert self.a_float is not False
     56        self.assertIsNot(self.a_float, False)
     57
     58        assert self.a_string is not False
     59        self.assertIsNot(self.a_string, False)
     60
     61        assert self.a_tuple is not False
     62        self.assertIsNot(self.a_tuple, False)
     63
     64        assert self.a_list is not False
     65        self.assertIsNot(self.a_list, False)
     66
     67        assert self.a_set is not False
     68        self.assertIsNot(self.a_set, False)
     69
     70        assert self.a_dictionary is not False
     71        self.assertIsNot(self.a_dictionary, False)
     72
     73    def test_assertion_error_w_true(self):
     74        assert None is not True
     75        self.assertIsNot(None, True)
     76
     77        assert False is not True
     78        self.assertIsNot(False, True)
     79
     80        assert True is True
     81        self.assertIs(True, True)
     82
     83        assert self.an_integer is not True
     84        self.assertIsNot(self.an_integer, True)
     85
     86        assert self.a_float is not True
     87        self.assertIsNot(self.a_float, True)
     88
     89        assert self.a_string is not True
     90        self.assertIsNot(self.a_string, True)
     91
     92        assert self.a_tuple is not True
     93        self.assertIsNot(self.a_tuple, True)
     94
     95        assert self.a_list is not True
     96        self.assertIsNot(self.a_list, True)
     97
     98        assert self.a_set is not True
     99        self.assertIsNot(self.a_set, True)
    100
    101        assert self.a_dictionary is not True
    102        self.assertIsNot(self.a_dictionary, True)
    103
    104    def test_assertion_error_w_equality(self):
    105        assert None == None
    106        self.assertEqual(None, None)
    107
    108        assert False != None
    109        self.assertNotEqual(False, None)
    110
    111        assert False != True
    112        self.assertNotEqual(False, True)
    113
    114        assert False == False
    115        self.assertEqual(False, False)
    116
    117        assert True != None
    118        self.assertNotEqual(True, None)
    119
    120        assert True == True
    121        self.assertEqual(True, True)
    122
    123    def test_assertion_error_w_is_vs_equal(self):
    124        assert 0 is not 0.0
    125        self.assertIsNot(0, 0.0)
    126
    127        assert 0 == 0.0
    128        self.assertEqual(0, 0.0)
    129
    130
    131# NOTES
    132# a dictionary is not True
    133# a dictionary is not False
    134# a dictionary is not None
    135# a set is not True
    136# a set is not False
    137# a set is not None
    138# a list is not True
    139# a list is not False
    140# a list is not None
    141# a tuple is not True
    142# a tuple is not False
    143# a tuple is not None
    144# a string is not True
    145# a string is not False
    146# a string is not None
    147# a float is not True
    148# a float is not False
    149# a float is not None
    150# an integer is not True
    151# an integer is not False
    152# an integer is not None
    153# True is True and equal to True
    154# True is not False and NOT equal to False
    155# True is not None and NOT equal to None
    156# False is not True and NOT equal to True
    157# False is False and equal to False
    158# False is not None and NOT equal to None
    159# None is not True and NOT equal to True
    160# None is not False and NOT equal to False
    161# None is None and equal to None
    162
    163
    164# Exceptions seen
    165# AssertionError
    166# NameError