another way to write tests: tests

The code in unittest/tests/test_unittest.py from another way to write tests

unittest/tests/test_unittest.py
 1import unittest
 2
 3
 4class TestUnittest(unittest.TestCase):
 5
 6    def test_dir_unittest(self):
 7        reality = dir(unittest)
 8        my_expectation = [
 9            'BaseTestSuite', 'FunctionTestCase',
10            'IsolatedAsyncioTestCase', 'SkipTest',
11            'TestCase', 'TestLoader', 'TestProgram',
12            'TestResult', 'TestSuite', 'TextTestResult',
13            'TextTestRunner', '__all__', '__builtins__',
14            '__cached__', '__dir__', '__doc__',
15            '__file__', '__getattr__', '__loader__',
16            '__name__', '__package__', '__path__',
17            '__spec__', '__unittest', 'addModuleCleanup',
18            'case', 'defaultTestLoader', 'doModuleCleanups',
19            'enterModuleContext', 'expectedFailure',
20            'installHandler', 'loader', 'main',
21            'registerResult', 'removeHandler', 'removeResult',
22            'result', 'runner', 'signals', 'skip', 'skipIf',
23            'skipUnless', 'suite', 'util'
24        ]
25        assert reality == my_expectation
26        self.assertEqual(reality, my_expectation)
unittest/tests/test_unittest.py
28    def test_dir_unittest_testcase(self):
29        reality = dir(unittest.TestCase)
30        my_expectation = [
31            '__call__', '__class__', '__delattr__',
32            '__dict__', '__dir__', '__doc__', '__eq__',
33            '__firstlineno__', '__format__', '__ge__',
34            '__getattribute__', '__getstate__', '__gt__',
35            '__hash__', '__init__', '__init_subclass__',
36            '__le__', '__lt__', '__module__', '__ne__',
37            '__new__', '__reduce__', '__reduce_ex__',
38            '__repr__', '__setattr__', '__sizeof__',
39            '__static_attributes__', '__str__',
40            '__subclasshook__', '__weakref__',
41            '_addDuration', '_addExpectedFailure',
42            '_addUnexpectedSuccess', '_assertNotWarns',
43            '_baseAssertEqual', '_callCleanup',
44            '_callSetUp', '_callTearDown', '_callTestMethod',
45            '_diffThreshold', '_formatMessage',
46            '_getAssertEqualityFunc', '_tail_type_check',
47            '_truncateMessage', 'addClassCleanup',
48            'addCleanup', 'addTypeEqualityFunc',
49            'assertAlmostEqual', 'assertCountEqual',
50            'assertDictEqual', 'assertEndsWith',
51            'assertEqual', 'assertFalse', 'assertGreater',
52            'assertGreaterEqual', 'assertHasAttr',
53            'assertIn', 'assertIs', 'assertIsInstance',
54            'assertIsNone', 'assertIsNot',
55            'assertIsNotNone', 'assertIsSubclass',
56            'assertLess', 'assertLessEqual',
57            'assertListEqual', 'assertLogs',
58            'assertMultiLineEqual', 'assertNoLogs',
59            'assertNotAlmostEqual', 'assertNotEndsWith',
60            'assertNotEqual', 'assertNotHasAttr',
61            'assertNotIn', 'assertNotIsInstance',
62            'assertNotIsSubclass', 'assertNotRegex',
63            'assertNotStartsWith', 'assertRaises',
64            'assertRaisesRegex', 'assertRegex',
65            'assertSequenceEqual', 'assertSetEqual',
66            'assertStartsWith', 'assertTrue',
67            'assertTupleEqual', 'assertWarns',
68            'assertWarnsRegex', 'countTestCases',
69            'debug', 'defaultTestResult',
70            'doClassCleanups', 'doCleanups',
71            'enterClassContext', 'enterContext', 'fail',
72            'failureException', 'id', 'longMessage',
73            'maxDiff', 'run', 'setUp', 'setUpClass',
74            'shortDescription', 'skipTest', 'subTest',
75            'tearDown', 'tearDownClass'
76        ]
77        assert reality == my_expectation
78        self.assertEqual(reality, my_expectation)
unittest/tests/test_unittest.py
80    def test_assertIsNot(self):
81        assert None is not False
82        self.assertIsNot(None, False)
83
84    def test_assertIs(self):
85        assert False is False
86        self.assertIs(False, False)
87
88    def test_assertNotEqual(self):
89        assert True != 0
90        self.assertNotEqual(True, 0)
91
92    def test_assertEqual(self):
93        assert 0.0 == 0.0
94        self.assertEqual(0.0, 0.0)
unittest/tests/test_unittest.py
 96    def test_assertNotIsInstance(self):
 97        assert not isinstance(
 98            unittest.TestCase, unittest.TestCase
 99        )
100        self.assertNotIsInstance(
101            unittest.TestCase, unittest.TestCase
102        )
103
104    def test_assertIs_instance(self):
105        an_object = unittest.TestCase
106        an_instance = a_class()
107
108        assert isinstance(an_instance, a_class)
109        self.assertIsInstance(
110            an_instance, a_class
111        )
112        self.assertIsInstance(
113            self, unittest.TestCase
114        )
unittest/tests/test_unittest.py
116    def test_assertNotIsSubclass(self):
117        assert not issubclass(
118            unittest.TestCase, list
119        )
120        self.assertNotIsSubclass(
121            unittest.TestCase, dict
122        )
123
124    def test_assertIs_subclass(self):
125        assert issubclass(unittest.TestCase, object)
126        self.assertIsSubclass(
127            unittest.TestCase, object
128        )
129        self.assertIsSubclass(
130            TestUnittest, unittest.TestCase
131        )
132
133
134# Exceptions seen
135# AssertionError
136# NameError
137# TypeError
138# AttributeError

test AssertionError with unittest: tests

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

assertion_error/tests/test_assertion_error.py
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 = {}
assertion_error/tests/test_assertion_error.py
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)
assertion_error/tests/test_assertion_error.py
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)
assertion_error/tests/test_assertion_error.py
 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)
assertion_error/tests/test_assertion_error.py
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)
assertion_error/tests/test_assertion_error.py
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)
assertion_error/tests/test_assertion_error.py
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)
assertion_error/tests/test_assertion_error.py
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
assertion_error/tests/test_assertion_error.py
220# None is None and equal to None
221
222
223# Exceptions seen
224# AssertionError
225# IndentationError
226# AttributeError
227# NameError
228# TypeError

test objects with unittest: tests

The code in objects/tests/test_objects.py from test objects with unittest

objects/tests/test_objects.py
1class WPass: pass
2
3
4class WParentheses(): pass
5
6
7class WObject(object): pass
objects/tests/test_objects.py
10def test_making_an_object_w_pass():
11    assert isinstance(WPass(), object)
12    assert issubclass(WPass, object)
13
14
15def test_making_an_object_w_parentheses():
16    assert isinstance(WParentheses(), object)
17    assert issubclass(WParentheses, object)
18
19
20def test_making_an_object_w_object():
21    assert isinstance(WObject(), object)
22    assert issubclass(WObject, object)
objects/tests/test_objects.py
25def test_is_none_an_object():
26    assert isinstance(None, object)
27    # fails because None is not a class
28    # assert issubclass(None, object)
29
30
31def test_is_a_boolean_an_object():
32    assert isinstance(bool, object)
33    assert issubclass(bool, object)
34
35
36def test_is_an_integer_an_object():
37    assert isinstance(int, object)
38    assert issubclass(int, object)
objects/tests/test_objects.py
41def test_is_a_float_an_object():
42    assert isinstance(float, object)
43    assert issubclass(float, object)
44
45
46def test_is_a_string_an_object():
47    assert isinstance(str, object)
48    assert issubclass(str, object)
49
50
51def test_is_a_tuple_an_object():
52    assert isinstance(tuple, object)
53    assert issubclass(tuple, object)
objects/tests/test_objects.py
56def test_is_a_list_an_object():
57    assert isinstance(list, object)
58    assert issubclass(list, object)
59
60
61def test_is_a_set_an_object():
62    assert isinstance(set, object)
63    assert issubclass(set, object)
64
65
66def test_is_a_dictionary_an_object():
67    assert isinstance(dict, object)
68    assert issubclass(dict, object)
objects/tests/test_objects.py
71def test_dir_object():
72    reality = dir(object)
73    my_expectation = [
74        '__class__', '__delattr__', '__dir__',
75        '__doc__', '__eq__', '__format__',
76        '__ge__', '__getattribute__',
77        '__getstate__', '__gt__', '__hash__',
78        '__init__', '__init_subclass__', '__le__',
79        '__lt__', '__ne__', '__new__', '__reduce__',
80        '__reduce_ex__', '__repr__', '__setattr__',
81        '__sizeof__', '__str__', '__subclasshook__'
82    ]
83    assert reality == my_expectation
84
85
86# Exceptions seen
87# AssertionError
88# NameError
89# TypeError

test functions with unittest: tests

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

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

test person with unittest: tests

The code in person/tests/test_person.py from test person with unittest

person/tests/test_person.py
 1import src.person
 2import unittest
 3
 4
 5class TestPerson(unittest.TestCase):
 6
 7    def assert_person_factory_works(
 8            self, first_name, last_name,
 9            sex, year_of_birth
10        ):
11        self.assertEqual(
12            src.person.person(
13                first_name=first_name,
14                last_name=last_name,
15                sex=sex,
16                year_of_birth=year_of_birth,
17            ),
18            (
19                f'{first_name}, {last_name},'
20                f' {sex}, {year_of_birth}'
21            )
22        )
person/tests/test_person.py
24    def assert_say_hello_works(
25            self, first_name, last_name,
26            year_of_birth,
27        ):
28        self.assertEqual(
29            src.person.say_hello(
30                first_name=first_name,
31                last_name=last_name,
32                year_of_birth=year_of_birth
33            ),
34            (
35                f'Hello, my name is {first_name}'
36                f' {last_name} and I am'
37                f' {2026-year_of_birth}.'
38            )
39        )
person/tests/test_person.py
41    def assert_person_can_say_hello(
42            self,first_name, last_name,
43            sex, year_of_birth,
44        ):
45        self.assertEqual(
46            src.person.Person(
47                first_name=first_name,
48                last_name=last_name,
49                sex=sex,
50                year_of_birth=year_of_birth,
51            ).say_hello(),
52            (
53                f'Hello, my name is {first_name}'
54                f' {last_name} and I am'
55                f' {2026-year_of_birth}.'
56            )
57        )
person/tests/test_person.py
59    def test_joe(self):
60        first_name = 'joe'
61        last_name = 'blow'
62        sex = 'M'
63        year_of_birth = 1996
64
65        self.assert_person_factory_works(
66            first_name=first_name,
67            last_name=last_name,
68            sex=sex,
69            year_of_birth=year_of_birth
70        )
71
72        self.assert_say_hello_works(
73            first_name=first_name,
74            last_name=last_name,
75            year_of_birth=year_of_birth,
76        )
77
78        self.assert_person_can_say_hello(
79            first_name=first_name,
80            last_name=last_name,
81            sex=sex,
82            year_of_birth=year_of_birth
83        )
person/tests/test_person.py
 85    def test_jane(self):
 86        first_name = 'jane'
 87        last_name = 'doe'
 88        sex = 'F'
 89        year_of_birth = 1991
 90
 91        self.assert_person_factory_works(
 92            first_name=first_name,
 93            last_name=last_name,
 94            sex=sex,
 95            year_of_birth=year_of_birth,
 96        )
 97
 98        self.assert_say_hello_works(
 99            first_name=first_name,
100            last_name=last_name,
101            year_of_birth=year_of_birth,
102        )
103
104        self.assert_person_can_say_hello(
105            first_name=first_name,
106            last_name=last_name,
107            sex=sex,
108            year_of_birth=year_of_birth,
109        )
person/tests/test_person.py
111    def test_john(self):
112        first_name = 'john'
113        last_name = 'smith'
114        sex = 'M'
115        year_of_birth = 1580
116
117        self.assert_person_factory_works(
118            first_name=first_name,
119            last_name=last_name,
120            sex=sex,
121            year_of_birth=year_of_birth,
122        )
123
124        self.assert_say_hello_works(
125            first_name=first_name,
126            last_name=last_name,
127            year_of_birth=year_of_birth,
128        )
129
130        self.assert_person_can_say_hello(
131            first_name=first_name,
132            last_name=last_name,
133            sex=sex,
134            year_of_birth=year_of_birth,
135        )
person/tests/test_person.py
137    def test_mary(self):
138        first_name = 'mary'
139        last_name = 'public'
140        sex = 'F'
141        year_of_birth = 2000
142
143        self.assert_person_factory_works(
144            first_name=first_name,
145            last_name=last_name,
146            sex=sex,
147            year_of_birth=year_of_birth,
148        )
149
150        self.assert_say_hello_works(
151            first_name=first_name,
152            last_name=last_name,
153            year_of_birth=year_of_birth,
154        )
155
156        self.assert_person_can_say_hello(
157            first_name=first_name,
158            last_name=last_name,
159            sex=sex,
160            year_of_birth=year_of_birth,
161        )
person/tests/test_person.py
163    def test_dir_person_class(self):
164        self.assertEqual(
165            dir(src.person.Person),
166            [
167                '__class__', '__delattr__', '__dict__',
168                '__dir__', '__doc__', '__eq__',
169                '__firstlineno__', '__format__', '__ge__',
170                '__getattribute__', '__getstate__', '__gt__',
171                '__hash__', '__init__', '__init_subclass__',
172                '__le__', '__lt__', '__module__', '__ne__',
173                '__new__', '__reduce__', '__reduce_ex__',
174                '__repr__', '__setattr__', '__sizeof__',
175                '__static_attributes__', '__str__',
176                '__subclasshook__', '__weakref__', 'say_hello'
177            ]
178        )
person/tests/test_person.py
180    def test_dir_person_instance(self):
181        self.assertEqual(
182            dir(
183                src.person.Person(
184                    first_name='first_name',
185                    last_name='last_name',
186                    sex='M',
187                    year_of_birth=2026,
188                )
189            ),
190            [
191                '__class__', '__delattr__', '__dict__',
192                '__dir__', '__doc__', '__eq__',
193                '__firstlineno__', '__format__', '__ge__',
194                '__getattribute__', '__getstate__', '__gt__',
195                '__hash__', '__init__', '__init_subclass__',
196                '__le__', '__lt__', '__module__', '__ne__',
197                '__new__', '__reduce__', '__reduce_ex__',
198                '__repr__', '__setattr__', '__sizeof__',
199                '__static_attributes__', '__str__',
200                '__subclasshook__', '__weakref__', 'first_name',
201                'last_name', 'say_hello', 'sex', 'year_of_birth',
202            ]
203        )
204
205
206# Exceptions seen
207# AssertionError
208# NameError
209# TypeError
210# AttributeError
211# SyntaxError

test telephone with unittest: tests

The code in telephone/tests/test_telephone.py from test telephone with unittest

telephone/tests/test_telephone.py
 1import src.telephone
 2import unittest
 3
 4
 5text = src.telephone.text
 6
 7
 8class TestTelephone(unittest.TestCase):
 9
10    def test_passing_none(self):
11        self.assertEqual(text(None), 'I got: None')
12
13    def test_passing_booleans(self):
14        self.assertEqual(text(False), 'I got: False')
15        self.assertEqual(text(True), 'I got: True')
telephone/tests/test_telephone.py
17    def test_passing_an_integer(self):
18        an_integer = 1234
19        self.assertEqual(
20            text(an_integer), f'I got: {an_integer}'
21        )
22
23    def test_passing_a_float(self):
24        a_float = 5.678
25        self.assertEqual(
26            text(a_float), f'I got: {a_float}'
27        )
telephone/tests/test_telephone.py
29    def test_passing_a_string(self):
30        a_string = 'hello'
31        self.assertEqual(
32            text('hello'), f'I got: {a_string}'
33        )
34
35    def test_passing_a_tuple(self):
36        a_tuple = (0, 1, 2, 'n')
37        self.assertEqual(
38            text(a_tuple), f"I got: {a_tuple}"
39        )
telephone/tests/test_telephone.py
41    def test_passing_a_list(self):
42        a_list = [0, 1, 2, 'n']
43        self.assertEqual(
44            text(a_list), f'I got: {a_list}'
45        )
46
47    def test_passing_a_set(self):
48        a_set = {0, 1, 2, 'n'}
49        self.assertEqual(text(a_set), f'I got: {a_set}')
telephone/tests/test_telephone.py
51    def test_passing_a_dictionary(self):
52        a_dictionary = {
53            'key0': 'value0',
54            'keyN': [0, 1, 2, 'n'],
55        }
56        reality = text(a_dictionary)
57        my_expectation = f'I got: {a_dictionary}'
58        self.assertEqual(reality, my_expectation)
telephone/tests/test_telephone.py
60    def test_passing_a_class(self):
61        self.assertEqual(
62            text(object), "I got: <class 'object'>"
63        )
64        self.assertEqual(
65            text(bool), "I got: <class 'bool'>"
66        )
67        self.assertEqual(text(int), "I got: <class 'int'>")
68        self.assertEqual(
69            text(float), "I got: <class 'float'>"
70        )
71        self.assertEqual(text(str), "I got: <class 'str'>")
72        self.assertEqual(
73            text(tuple), "I got: <class 'tuple'>"
74        )
75        self.assertEqual(
76            text(list), "I got: <class 'list'>"
77        )
78        self.assertEqual(text(set), "I got: <class 'set'>")
79        self.assertEqual(
80            text(dict), "I got: <class 'dict'>"
81        )
82
83
84# Exceptions seen
85# AssertionError
86# NameError
87# TypeError
88# AttributeError