what is None?: tests


None (the simplest object): tests

The code in none/tests/test_none.py from what is None?

none/tests/test_none.py
 1import unittest
 2
 3
 4class TestNone(unittest.TestCase):
 5
 6    def test_what_is_none(self):
 7        self.assertIs(None, None)
 8        self.assertIsNone(None)
 9
10    def test_is_none_a_boolean(self):
11        self.assertIsNotNone(False)
12        self.assertIsNotNone(True)
13        self.assertIsInstance(False, bool)
14        self.assertIsInstance(True, bool)
15        self.assertNotIsInstance(None, bool)
none/tests/test_none.py
17    def test_is_none_an_integer(self):
18        self.assertIsNotNone(-1)
19        self.assertIsNotNone(0)
20        self.assertIsNotNone(1)
21        self.assertIsInstance(-1, int)
22        self.assertIsInstance(0, int)
23        self.assertIsInstance(1, int)
24        self.assertNotIsInstance(None, int)
25
26    def test_is_none_a_float(self):
27        self.assertIsNotNone(-0.1)
28        self.assertIsNotNone(0.0)
29        self.assertIsNotNone(0.1)
30        self.assertIsInstance(-0.1, float)
31        self.assertIsInstance(0.0, float)
32        self.assertIsInstance(0.1, float)
33        self.assertNotIsInstance(None, float)
none/tests/test_none.py
35    def test_is_none_a_string(self):
36        self.assertIsNotNone('')
37        self.assertIsNotNone("characters")
38        self.assertIsInstance("", str)
39        self.assertIsInstance('characters', str)
40        self.assertNotIsInstance(None, str)
41
42    def test_is_none_a_tuple(self):
43        self.assertIsNotNone(())
44        self.assertIsNotNone((0, 1, 2, 'n'))
45        self.assertIsInstance((), tuple)
46        self.assertIsInstance((0, 1, 2, 'n'), tuple)
47        self.assertNotIsInstance(None, tuple)
none/tests/test_none.py
49    def test_is_none_a_list(self):
50        self.assertIsNotNone([])
51        self.assertIsNotNone([0, 1, 2, 'n'])
52        self.assertIsInstance([], list)
53        self.assertIsInstance([0, 1, 2, 'n'], list)
54        self.assertNotIsInstance(None, list)
55
56    def test_is_none_a_set(self):
57        self.assertIsNotNone(set())
58        self.assertIsNotNone({0, 1, 2, 'n'})
59        self.assertIsInstance({0, 1, 2, 'n'}, set)
60        self.assertNotIsInstance(None, set)
none/tests/test_none.py
62    def test_is_none_a_dictionary(self):
63        self.assertIsNotNone(dict())
64        self.assertIsNotNone({'key': 'value'})
65        self.assertIsInstance({}, dict)
66        self.assertIsInstance(
67            {'key': 'value'}, dict
68        )
69        self.assertNotIsInstance(None, dict)
70
71
72# NOTES
73# None is NOT a dictionary
74# None is NOT a set
75# None is NOT a list
76# None is NOT a tuple
77# None is NOT a string
78# None is NOT a float
79# None is NOT an integer
80# None is NOT a boolean
81# None is None
82
83
84# Exceptions seen
85# AssertionError

test AssertionError with None: tests

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


test functions with None

The code in functions/tests/test_functions.py from test functions with None

  1import src.functions
  2import unittest
  3
  4
  5class TestFunctions(unittest.TestCase):
  6
  7    first = 'first'
  8    last = 'last'
  9    a_tuple = (0, 1, 2, 'n')
 10    a_list = [0, 1, 2, 'n']
 11    a_set = {0, 1, 2, 'n'}
 12    a_dictionary = {'key': 'value'}
 13
 14    def test_making_a_function_w_pass(self):
 15        self.assertIsNone(src.functions.w_pass())
 16
 17    def test_making_a_function_w_return(self):
 18        self.assertIsNone(src.functions.w_return())
 19
 20    def test_making_a_function_w_return_none(self):
 21        self.assertIsNone(src.functions.w_return_none())
 22
 23    def test_what_happens_after_functions_return(self):
 24        self.assertIsNone(
 25            src.functions.return_leaves_the_function()
 26        )
 27
 28    def test_constant_function(self):
 29        self.assertEqual(
 30            src.functions.constant(), 'the same thing'
 31        )
 32
 33    def test_identity_function(self):
 34        self.assertIsNone(src.functions.identity(None))
 35        self.assertEqual(
 36            src.functions.identity(object), object
 37        )
 38
 39    def test_why_use_a_function(self):
 40        def add_x(number):
 41            return 3 + number
 42
 43        self.assertEqual(add_x(0), 3)
 44        self.assertEqual(add_x(1), 4)
 45        self.assertEqual(add_x(2), 5)
 46        self.assertEqual(add_x(3), 6)
 47        self.assertEqual(add_x(4), 7)
 48        self.assertEqual(add_x(5), 8)
 49        self.assertEqual(add_x(6), 9)
 50        self.assertEqual(add_x(7), 10)
 51        self.assertEqual(add_x(8), 11)
 52        self.assertEqual(add_x(9), 12)
 53
 54    def test_positional_arguments(self):
 55        positional_arguments = (
 56            src.functions.positional_arguments
 57        )
 58
 59        self.assertEqual(
 60            positional_arguments(self.first, self.last),
 61            (self.first, self.last)
 62        )
 63        self.assertEqual(
 64            positional_arguments(self.last, self.first),
 65            (self.last, self.first)
 66        )
 67
 68        self.assertEqual(
 69            positional_arguments(0, 1), (0, 1)
 70        )
 71
 72        self.assertEqual(
 73            positional_arguments(
 74                self.a_tuple, self.a_list
 75            ),
 76            (self.a_tuple, self.a_list)
 77        )
 78
 79        self.assertEqual(
 80            src.functions.keyword_arguments(
 81                self.a_set, self.a_dictionary
 82            ),
 83            (self.a_set, self.a_dictionary)
 84        )
 85
 86    def test_keyword_arguments(self):
 87        keyword_arguments = (
 88            src.functions.keyword_arguments
 89        )
 90
 91        self.assertEqual(
 92            keyword_arguments(
 93                first_input=self.first,
 94                last_input=self.last,
 95            ),
 96            (self.first, self.last)
 97        )
 98        self.assertEqual(
 99            keyword_arguments(
100                last_input=self.last,
101                first_input=self.first,
102            ),
103            (self.first, self.last)
104        )
105
106        self.assertEqual(
107            keyword_arguments(
108                last_input=0, first_input=1,
109            ),
110            (1, 0)
111        )
112
113        self.assertEqual(
114            keyword_arguments(
115                first_input=self.a_tuple,
116                last_input=self.a_list,
117            ),
118            (self.a_tuple, self.a_list)
119        )
120
121        self.assertEqual(
122            src.functions.positional_arguments(
123                last_input=self.a_dictionary,
124                first_input=self.a_set,
125            ),
126            (self.a_set, self.a_dictionary)
127        )
128
129    def test_args_and_kwargs(self):
130        self.assertEqual(
131            src.functions.args_and_kwargs(
132                self.first, last_input=self.last
133            ),
134            (self.first, self.last)
135        )
136
137    def test_optional_arguments(self):
138        optional_arguments = (
139            src.functions.optional_arguments
140        )
141
142        first_name, last_name = 'jane', 'doe'
143        self.assertEqual(
144            optional_arguments(
145                first_name,
146            ),
147            (first_name, last_name)
148        )
149
150        first_name, blow = 'joe', 'blow'
151        self.assertEqual(
152            optional_arguments(
153                first_name, blow
154            ),
155            (first_name, blow)
156        )
157
158        first_name = 'john'
159        self.assertEqual(
160            optional_arguments(
161                first_input=first_name,
162            ),
163            (first_name, last_name)
164        )
165
166        last_name = 'smith'
167        self.assertEqual(
168            optional_arguments(
169                last_input=last_name,
170                first_input=first_name,
171            ),
172            (first_name, last_name)
173        )
174
175    def test_unknown_number_of_arguments(self):
176        unknown_number_of_arguments = (
177            src.functions.unknown_number_of_arguments
178        )
179
180        a_tuple = (0, 1)
181        a_dictionary = {'a': 2, 'b': 3}
182        self.assertEqual(
183            unknown_number_of_arguments(
184                *a_tuple, **a_dictionary
185            ),
186            (a_tuple, a_dictionary)
187        )
188
189        a_dictionary = {'a': 2, 'b': 3, 'c': 4}
190        self.assertEqual(
191            unknown_number_of_arguments(
192                *a_tuple, **a_dictionary
193            ),
194            (a_tuple, a_dictionary)
195        )
196
197        a_tuple = (0, 1, 2)
198        a_dictionary = {'a': 3, 'b': 4, 'c': 5}
199        self.assertEqual(
200            unknown_number_of_arguments(
201                *a_tuple, **a_dictionary
202            ),
203            (a_tuple, a_dictionary)
204        )
205
206        a_tuple = (0, 1, 2, 'n')
207        self.assertEqual(
208            unknown_number_of_arguments(*a_tuple),
209            (a_tuple, {})
210        )
211
212        a_dictionary = {'a': 1, 'b': 2, 'c': 3, 'd': 'n'}
213        self.assertEqual(
214            unknown_number_of_arguments(**a_dictionary),
215            ((), a_dictionary)
216        )
217
218        self.assertEqual(
219            unknown_number_of_arguments(), ((), {})
220        )
221
222
223# Exceptions seen
224# AssertionError
225# NameError
226# TypeError
227# SyntaxError
228# AttributeError