TypeError: tests and solution
what causes TypeError?: tests
The code in type_error/tests/test_type_error.py from what causes TypeError?
1def function_00(the_input):
2 return None
3
4
5def function_01(first, second):
6 return None
7
8
9def function_02(first, second, third):
10 return None
11
12
13def function_03(first, second, third, fourth):
14 return None
17def function_04(argument):
18 return None
19
20
21def function_05(argument_0, argument_1):
22 return None
23
24
25def function_06(
26 argument_0, argument_1,
27 argument_2,
28):
29 return None
30
31
32def function_07(
33 argument_0, argument_1,
34 argument_2, argument_n,
35):
36 return None
39def function_08(name, argument):
40 return None
41
42
43def test_type_error_w_positional_arguments():
44 function_00('a')
45 function_01('a', 'b')
46 function_02('a', 'b', 'c')
47 function_03('a', 'b', 'c', 'd')
48 function_04('a')
49 function_05('a', 'b')
50 function_06('a', 'b', 'c')
51 function_07('a', 'b', 'c', 'd')
52 function_08('last', 'one')
55def test_type_error_w_keyword_arguments():
56 function_00(the_input=0)
57 function_01(
58 first='first',
59 second={'key': 'value'},
60 )
61 function_02(
62 third=(0, 1, 2, 'n'),
63 second=[0, 1, 2, 'n'],
64 first={0, 1, 2, 'n'},
65 )
66 function_03(
67 first=None,
68 second=False,
69 third=True,
70 fourth=4,
71 )
72 function_04(argument='value')
73 function_05(
74 argument_0='value_1',
75 argument_1=(0, 1, 2, 'n'),
76 )
77 function_06(
78 argument_0='value_1',
79 argument_1=(0, 1, 2, 'n'),
80 argument_2=[0, 1, 2, 'n'],
81 )
82 function_07(
83 argument_0=(0, 1, 2, 'n'),
84 argument_1=[0, 1, 2, 'n'],
85 argument_2={0, 1, 2, 'n'},
86 argument_n={'key': 'value'},
87 )
88 function_08(
89 argument='positional',
90 name='keyword',
91 )
94def test_type_error_w_args_and_kwargs():
95 function_00('argument')
96 function_01(1, 0)
97 function_02(
98 third=True, second=False,
99 first=None,
100 )
101 function_03(
102 second=[0, 1, 2, 'n'],
103 first=(0, 1, 2, 'n'),
104 third={0, 1, 2, 'n'},
105 fourth={'key': 'value'},
106 )
107 function_04(argument='value_2')
108 function_05((0, 1, 2, 'n'), [0, 1, 2, 'n'])
109 function_06(
110 argument_2=(0, 1, 2, 'n'),
111 argument_0=[0, 1, 2, 'n'],
112 argument_1={0, 1, 2, 'n'},
113 )
114 function_07(
115 argument_n={'key': 'value'},
116 argument_2={0, 1, 2, 'n'},
117 argument_0=(0, 1, 2, 'n'),
118 argument_1=[0, 1, 2, 'n'],
119 )
120 function_08(
121 'positional',
122 argument='keyword',
123 )
124
125
126# Exceptions seen
127# AssertionError
128# NameError
129# TypeError
separate and equal TypeError: tests and solutions
separate and equal TypeError: tests
The code in type_error/tests/test_type_error.py from separate and equal TypeError
1import src.type_error
2
3
4def test_type_error_w_positional_arguments():
5 src.type_error.function_00('a')
6 src.type_error.function_01('a', 'b')
7 src.type_error.function_02('a', 'b', 'c')
8 src.type_error.function_03('a', 'b', 'c', 'd')
9 src.type_error.function_04('a')
10 src.type_error.function_05('a', 'b')
11 src.type_error.function_06('a', 'b', 'c')
12 src.type_error.function_07('a', 'b', 'c', 'd')
13 src.type_error.function_08('last', 'one')
16def test_type_error_w_keyword_arguments():
17 src.type_error.function_00(the_input=0)
18 src.type_error.function_01(
19 first='first',
20 second={'key': 'value'},
21 )
22 src.type_error.function_02(
23 third=(0, 1, 2, 'n'),
24 second=[0, 1, 2, 'n'],
25 first={0, 1, 2, 'n'}
26 )
27 src.type_error.function_03(
28 first=None,
29 second=False,
30 third=True,
31 fourth=4,
32 )
33 src.type_error.function_04(argument='value')
34 src.type_error.function_05(
35 argument_0='value_1',
36 argument_1=(0, 1, 2, 'n')
37 )
38 src.type_error.function_06(
39 argument_0='value_1',
40 argument_1=(0, 1, 2, 'n'),
41 argument_2=[0, 1, 2, 'n'],
42 )
43 src.type_error.function_07(
44 argument_0=(0, 1, 2, 'n'),
45 argument_1=[0, 1, 2, 'n'],
46 argument_2={0, 1, 2, 'n'},
47 argument_n={'key': 'value'},
48 )
49 src.type_error.function_08(
50 argument='positional',
51 name='keyword',
52 )
55def test_type_error_w_args_and_kwargs():
56 src.type_error.function_00('argument')
57 src.type_error.function_01(1, 0)
58 src.type_error.function_02(
59 third=True, second=False,
60 first=None,
61 )
62 src.type_error.function_03(
63 second=[0, 1, 2, 'n'],
64 first=(0, 1, 2, 'n'),
65 third={0, 1, 2, 'n'},
66 fourth={'key': 'value'},
67 )
68 src.type_error.function_04(argument='value_2')
69 src.type_error.function_05(
70 (0, 1, 2, 'n'), [0, 1, 2, 'n']
71 )
72 src.type_error.function_06(
73 argument_2=(0, 1, 2, 'n'),
74 argument_0=[0, 1, 2, 'n'],
75 argument_1={0, 1, 2, 'n'},
76 )
77 src.type_error.function_07(
78 argument_n={'key': 'value'},
79 argument_2={0, 1, 2, 'n'},
80 argument_0=(0, 1, 2, 'n'),
81 argument_1=[0, 1, 2, 'n'],
82 )
83 src.type_error.function_08(
84 'positional',
85 argument='keyword',
86 )
87
88
89# Exceptions seen
90# AssertionError
91# NameError
92# TypeError
93# AttributeError
separate and equal TypeError: solutions
The code in type_error/src/type_error/__init__.py from separate and equal TypeError
1def function_00(the_input):
2 return None
3
4
5def function_01(first, second):
6 return None
7
8
9def function_02(
10 third, second, first,
11 ):
12 return None
15def function_03(
16 first, second, third, fourth
17 ):
18 return None
19
20
21def function_04(argument):
22 return None
23
24
25def function_05(argument_0, argument_1):
26 return None
TypeError with classes: tests and solutions
TypeError with classes: tests
The code added to type_error/tests/test_type_error.py from TypeError with classes
89def test_type_error_w_class_methods():
90 src.type_error.AClass.method_00()
91 src.type_error.AClass().method_01()
92 src.type_error.AClass().method_02()
93 src.type_error.AClass.method_03()
94 src.type_error.AClass.method_04()
95 src.type_error.AClass().method_05()
96 src.type_error.AClass().method_06()
97 src.type_error.AClass().method_07()
98 src.type_error.AClass().method_08()
99 src.type_error.AClass().method_09()
101def test_type_error_w_the_uncallables():
102 src.type_error.none()
103 src.type_error.false()
104 src.type_error.true()
105 src.type_error.an_integer()
106 src.type_error.a_float()
107 src.type_error.a_string()
108 src.type_error.a_tuple()
109 src.type_error.a_list()
110 src.type_error.a_set()
111 src.type_error.a_dictionary()
112
113
114# Exceptions seen
115# AssertionError
116# NameError
117# TypeError
118# AttributeError
TypeError with classes: solutions
The code added to type_error/src/type_error/__init__.py from TypeError with classes
1def none(): return None
2def false(): return False
3def true(): return True
4def an_integer(): return 1234
5def a_float(): return 5.678
6def a_string(): return 'a string'
7def a_tuple(): return (0, 1, 2, 'n')
8def a_list(): return [0, 1, 2, 'n']
9def a_set(): return {0, 1, 2, 'n'}
10def a_dictionary(): return {'key': 'value'}
11
12
13def function_00(the_input):
52def function_08(name, argument):
53 return None
54
55
56class AClass(object):
57
58 @staticmethod
59 def method_00(): return None
60
61 @staticmethod
62 def method_01(): return None
63
64 def method_02(self):
65 return self.method_01()
66
67 @staticmethod
68 def method_03():
69 return AClass().method_02()
71 @staticmethod
72 def method_04():
73 return AClass.method_02(AClass)
74
75 def method_05(self):
76 return self.method_02()
77
78 def method_06(self):
79 return self.method_01()
80
81 def method_07(self):
82 return self.method_00()
83
84 def method_08(self):
85 return self.method_04()
86
87 def method_09(self):
88 return self.method_03()