@@ -23,7 +23,7 @@ class TestInvertedTkYCanvas(unittest.TestCase):
23
23
24
24
def setUp (self ):
25
25
26
- self .tkinter = fake_tkinter .FakeTkinter (
26
+ self .tkinter = fake_tkinter .Module (
27
27
screen_width = SCREEN_WIDTH ,
28
28
screen_height = SCREEN_HEIGHT ,
29
29
)
@@ -44,40 +44,33 @@ def test_create_creates_tkinter_Canvas(self):
44
44
45
45
_c = canvas .InvertedYCanvas (self .master , 'background' )
46
46
47
- tkinter_canvas_call_args = self .tkinter .canvas_init_calls
48
-
49
- self .assertEqual (len (tkinter_canvas_call_args ), 1 , 'tkinter.Canvas call count' )
47
+ self .assertEqual (len (self .tkinter .canvases ), 1 , 'tkinter.Canvas call count' )
50
48
51
49
52
50
def test_create_creates_tkinter_Canvas_with_given_master (self ):
53
51
54
52
_c = canvas .InvertedYCanvas (self .master , 'background' )
55
53
56
- tkinter_canvas_call_args = self .tkinter .canvas_init_calls
54
+ canvas_init_args = self .tkinter .canvases [ 0 ]. init_args
57
55
58
56
# Passed a single positional argument: self.master
59
- (single_arg ,), _kwargs = tkinter_canvas_call_args [0 ]
60
- self .assertIs (single_arg , self .master )
57
+ self .assertIs (canvas_init_args .args [0 ], self .master )
61
58
62
59
63
60
def test_create_creates_tkinter_Canvas_with_given_background (self ):
64
61
65
62
_c = canvas .InvertedYCanvas (self .master , 'background' )
66
63
67
- tkinter_canvas_call_args = self .tkinter .canvas_init_calls
68
-
69
- _args , kwargs = tkinter_canvas_call_args [0 ]
70
- self .assertEqual (kwargs ['background' ], 'background' )
64
+ canvas_init_args = self .tkinter .canvases [0 ].init_args
65
+ self .assertEqual (canvas_init_args .kwargs ['background' ], 'background' )
71
66
72
67
73
68
def test_create_creates_tkinter_Canvas_with_zero_highlightthickness (self ):
74
69
75
70
_c = canvas .InvertedYCanvas (self .master , 'background' )
76
71
77
- tkinter_canvas_call_args = self .tkinter .canvas_init_calls
78
-
79
- _args , kwargs = tkinter_canvas_call_args [0 ]
80
- self .assertEqual (kwargs ['highlightthickness' ], 0 )
72
+ canvas_init_args = self .tkinter .canvases [0 ].init_args
73
+ self .assertEqual (canvas_init_args .kwargs ['highlightthickness' ], 0 )
81
74
82
75
83
76
def test_create_polygon_returns_integer_item_id (self ):
@@ -96,9 +89,13 @@ def test_create_polygon_inverts_y_coordinates(self):
96
89
coords = [0 , 0 , 1 , 1 , 2 , - 2 ]
97
90
_item_id = c .create_polygon (coords , fill = 'fill' , outline = 'outline' , width = 42 )
98
91
99
- args = c ._canvas .create_polygon_coords
100
-
101
- self .assertEqual (args , [0 , 0 , 1 , - 1 , 2 , 2 ])
92
+ wrapped_tkinter_canvas = self .tkinter .canvases [0 ]
93
+ wrapped_tkinter_canvas .create_polygon .assert_called_once_with (
94
+ [0 , 0 , 1 , - 1 , 2 , 2 ],
95
+ fill = mock .ANY ,
96
+ outline = mock .ANY ,
97
+ width = mock .ANY ,
98
+ )
102
99
103
100
104
101
def test_create_polygon_passes_args_to_Canvas_create_polygon (self ):
@@ -107,8 +104,13 @@ def test_create_polygon_passes_args_to_Canvas_create_polygon(self):
107
104
108
105
_item_id = c .create_polygon ([], fill = 'fill' , outline = 'outline' , width = 42 )
109
106
110
- kwargs = c ._canvas .create_polygon_kwargs
111
- self .assertEqual (kwargs , dict (fill = 'fill' , outline = 'outline' , width = 42 ))
107
+ wrapped_tkinter_canvas = self .tkinter .canvases [0 ]
108
+ wrapped_tkinter_canvas .create_polygon .assert_called_once_with (
109
+ mock .ANY ,
110
+ fill = 'fill' ,
111
+ outline = 'outline' ,
112
+ width = 42 ,
113
+ )
112
114
113
115
114
116
def test_create_image_returns_integer_item_id (self ):
@@ -126,7 +128,8 @@ def test_create_image_inverts_y_coordinate(self):
126
128
127
129
_item_id = c .create_image (42 , 24 , image = None , anchor = None )
128
130
129
- c ._canvas .create_image .assert_called_with (
131
+ wrapped_tkinter_canvas = self .tkinter .canvases [0 ]
132
+ wrapped_tkinter_canvas .create_image .assert_called_with (
130
133
42 , - 24 , image = mock .ANY , anchor = mock .ANY
131
134
)
132
135
@@ -137,7 +140,8 @@ def test_create_image_passes_args_to_Canvas_create_image(self):
137
140
138
141
_item_id = c .create_image (42 , 24 , image = 'image' , anchor = 'anchor' )
139
142
140
- c ._canvas .create_image .assert_called_with (
143
+ wrapped_tkinter_canvas = self .tkinter .canvases [0 ]
144
+ wrapped_tkinter_canvas .create_image .assert_called_with (
141
145
mock .ANY , mock .ANY , image = 'image' , anchor = 'anchor'
142
146
)
143
147
@@ -158,7 +162,8 @@ def test_create_line_inverts_y_coordinates(self):
158
162
coords = [0 , 0 , 1 , 1 , 2 , - 2 ]
159
163
_item_id = c .create_line (coords , fill = 'fill' , width = 42 , capstyle = 'capstyle' )
160
164
161
- c ._canvas .create_line .assert_called_with (
165
+ wrapped_tkinter_canvas = self .tkinter .canvases [0 ]
166
+ wrapped_tkinter_canvas .create_line .assert_called_with (
162
167
[0 , 0 , 1 , - 1 , 2 , 2 ], fill = mock .ANY , width = mock .ANY , capstyle = mock .ANY ,
163
168
)
164
169
@@ -169,7 +174,8 @@ def test_create_line_passes_args_to_Canvas_create_line(self):
169
174
170
175
_item_id = c .create_line ([], fill = 'fill' , width = 42 , capstyle = 'capstyle' )
171
176
172
- c ._canvas .create_line .assert_called_with (
177
+ wrapped_tkinter_canvas = self .tkinter .canvases [0 ]
178
+ wrapped_tkinter_canvas .create_line .assert_called_with (
173
179
mock .ANY , fill = 'fill' , width = 42 , capstyle = 'capstyle' ,
174
180
)
175
181
@@ -180,7 +186,8 @@ def test_move_calls_canvas_move_with_same_item_id(self):
180
186
181
187
c .move (42 , 0 , 0 )
182
188
183
- c ._canvas .move .assert_called_with (42 , mock .ANY , mock .ANY )
189
+ wrapped_tkinter_canvas = self .tkinter .canvases [0 ]
190
+ wrapped_tkinter_canvas .move .assert_called_with (42 , mock .ANY , mock .ANY )
184
191
185
192
186
193
def test_move_calls_canvas_move_with_inverted_y (self ):
@@ -189,7 +196,8 @@ def test_move_calls_canvas_move_with_inverted_y(self):
189
196
190
197
c .move (None , 42 , 24 )
191
198
192
- c ._canvas .move .assert_called_with (mock .ANY , 42 , - 24 )
199
+ wrapped_tkinter_canvas = self .tkinter .canvases [0 ]
200
+ wrapped_tkinter_canvas .move .assert_called_with (mock .ANY , 42 , - 24 )
193
201
194
202
195
203
def test_coords_calls_canvas_coords_with_same_item_id (self ):
@@ -198,7 +206,8 @@ def test_coords_calls_canvas_coords_with_same_item_id(self):
198
206
199
207
c .coords (42 , [])
200
208
201
- c ._canvas .coords .assert_called_with (42 , mock .ANY )
209
+ wrapped_tkinter_canvas = self .tkinter .canvases [0 ]
210
+ wrapped_tkinter_canvas .coords .assert_called_with (42 , mock .ANY )
202
211
203
212
204
213
def test_coords_calls_canvas_coords_with_inverted_y_coords (self ):
@@ -207,7 +216,8 @@ def test_coords_calls_canvas_coords_with_inverted_y_coords(self):
207
216
208
217
c .coords (None , [1 , 2 , 3 , 4 , 5 , 6 ])
209
218
210
- c ._canvas .coords .assert_called_with (
219
+ wrapped_tkinter_canvas = self .tkinter .canvases [0 ]
220
+ wrapped_tkinter_canvas .coords .assert_called_with (
211
221
mock .ANY , [1 , - 2 , 3 , - 4 , 5 , - 6 ]
212
222
)
213
223
@@ -228,8 +238,9 @@ def test_attribute_access_returns_tkinter_Canvas_attribute(self):
228
238
'tag_raise' ,
229
239
)
230
240
241
+ wrapped_tkinter_canvas = self .tkinter .canvases [0 ]
231
242
for name in names :
232
243
with self .subTest (attr_name = name ):
233
244
result = getattr (c , name )
234
- underlying = getattr (c . _canvas , name )
245
+ underlying = getattr (wrapped_tkinter_canvas , name )
235
246
self .assertIs (result , underlying )
0 commit comments