@@ -56,7 +56,7 @@ def setUpClass(cls):
56
56
frame = cls .frame = Frame (root )
57
57
text = cls .text = Text (frame )
58
58
text .insert ('1.0' , code_sample )
59
- # Need to pack for creation of code context label widget.
59
+ # Need to pack for creation of code context text widget.
60
60
frame .pack (side = 'left' , fill = 'both' , expand = 1 )
61
61
text .pack (side = 'top' , fill = 'both' , expand = 1 )
62
62
cls .editor = DummyEditwin (root , frame , text )
@@ -75,11 +75,11 @@ def setUp(self):
75
75
self .cc = codecontext .CodeContext (self .editor )
76
76
77
77
def tearDown (self ):
78
- if self .cc .label :
79
- self .cc .label .destroy ()
78
+ if self .cc .context :
79
+ self .cc .context .destroy ()
80
80
# Explicitly call __del__ to remove scheduled scripts.
81
81
self .cc .__del__ ()
82
- del self .cc .label , self .cc
82
+ del self .cc .context , self .cc
83
83
84
84
def test_init (self ):
85
85
eq = self .assertEqual
@@ -89,7 +89,7 @@ def test_init(self):
89
89
eq (cc .editwin , ed )
90
90
eq (cc .text , ed .text )
91
91
eq (cc .textfont , ed .text ['font' ])
92
- self .assertIsNone (cc .label )
92
+ self .assertIsNone (cc .context )
93
93
eq (cc .info , [(0 , - 1 , '' , False )])
94
94
eq (cc .topvisible , 1 )
95
95
eq (self .root .tk .call ('after' , 'info' , self .cc .t1 )[1 ], 'timer' )
@@ -120,20 +120,20 @@ def test_toggle_code_context_event(self):
120
120
toggle = cc .toggle_code_context_event
121
121
122
122
# Make sure code context is off.
123
- if cc .label :
123
+ if cc .context :
124
124
toggle ()
125
125
126
126
# Toggle on.
127
127
eq (toggle (), 'break' )
128
- self .assertIsNotNone (cc .label )
129
- eq (cc .label ['font' ], cc .textfont )
130
- eq (cc .label ['fg' ], cc .colors ['foreground' ])
131
- eq (cc .label ['bg' ], cc .colors ['background' ])
132
- eq (cc .label [ 'text' ] , '' )
128
+ self .assertIsNotNone (cc .context )
129
+ eq (cc .context ['font' ], cc .textfont )
130
+ eq (cc .context ['fg' ], cc .colors ['foreground' ])
131
+ eq (cc .context ['bg' ], cc .colors ['background' ])
132
+ eq (cc .context . get ( '1.0' , 'end-1c' ) , '' )
133
133
134
134
# Toggle off.
135
135
eq (toggle (), 'break' )
136
- self .assertIsNone (cc .label )
136
+ self .assertIsNone (cc .context )
137
137
138
138
def test_get_context (self ):
139
139
eq = self .assertEqual
@@ -187,7 +187,7 @@ def test_update_code_context(self):
187
187
eq = self .assertEqual
188
188
cc = self .cc
189
189
# Ensure code context is active.
190
- if not cc .label :
190
+ if not cc .context :
191
191
cc .toggle_code_context_event ()
192
192
193
193
# Invoke update_code_context without scrolling - nothing happens.
@@ -200,21 +200,21 @@ def test_update_code_context(self):
200
200
cc .update_code_context ()
201
201
eq (cc .info , [(0 , - 1 , '' , False )])
202
202
eq (cc .topvisible , 2 )
203
- eq (cc .label [ 'text' ] , '' )
203
+ eq (cc .context . get ( '1.0' , 'end-1c' ) , '' )
204
204
205
205
# Scroll down to line 2.
206
206
cc .text .yview (2 )
207
207
cc .update_code_context ()
208
208
eq (cc .info , [(0 , - 1 , '' , False ), (2 , 0 , 'class C1():' , 'class' )])
209
209
eq (cc .topvisible , 3 )
210
- eq (cc .label [ 'text' ] , 'class C1():' )
210
+ eq (cc .context . get ( '1.0' , 'end-1c' ) , 'class C1():' )
211
211
212
212
# Scroll down to line 3. Since it's a comment, nothing changes.
213
213
cc .text .yview (3 )
214
214
cc .update_code_context ()
215
215
eq (cc .info , [(0 , - 1 , '' , False ), (2 , 0 , 'class C1():' , 'class' )])
216
216
eq (cc .topvisible , 4 )
217
- eq (cc .label [ 'text' ] , 'class C1():' )
217
+ eq (cc .context . get ( '1.0' , 'end-1c' ) , 'class C1():' )
218
218
219
219
# Scroll down to line 4.
220
220
cc .text .yview (4 )
@@ -223,7 +223,7 @@ def test_update_code_context(self):
223
223
(2 , 0 , 'class C1():' , 'class' ),
224
224
(4 , 4 , ' def __init__(self, a, b):' , 'def' )])
225
225
eq (cc .topvisible , 5 )
226
- eq (cc .label [ 'text' ] , 'class C1():\n '
226
+ eq (cc .context . get ( '1.0' , 'end-1c' ) , 'class C1():\n '
227
227
' def __init__(self, a, b):' )
228
228
229
229
# Scroll down to line 11. Last 'def' is removed.
@@ -235,7 +235,7 @@ def test_update_code_context(self):
235
235
(8 , 8 , ' if a > b:' , 'if' ),
236
236
(10 , 8 , ' elif a < b:' , 'elif' )])
237
237
eq (cc .topvisible , 12 )
238
- eq (cc .label [ 'text' ] , 'class C1():\n '
238
+ eq (cc .context . get ( '1.0' , 'end-1c' ) , 'class C1():\n '
239
239
' def compare(self):\n '
240
240
' if a > b:\n '
241
241
' elif a < b:' )
@@ -249,7 +249,7 @@ def test_update_code_context(self):
249
249
(8 , 8 , ' if a > b:' , 'if' ),
250
250
(10 , 8 , ' elif a < b:' , 'elif' )])
251
251
eq (cc .topvisible , 12 )
252
- eq (cc .label [ 'text' ] , 'class C1():\n '
252
+ eq (cc .context . get ( '1.0' , 'end-1c' ) , 'class C1():\n '
253
253
' def compare(self):\n '
254
254
' if a > b:\n '
255
255
' elif a < b:' )
@@ -262,12 +262,12 @@ def test_update_code_context(self):
262
262
(4 , 4 , ' def __init__(self, a, b):' , 'def' )])
263
263
eq (cc .topvisible , 6 )
264
264
# context_depth is 1.
265
- eq (cc .label [ 'text' ] , ' def __init__(self, a, b):' )
265
+ eq (cc .context . get ( '1.0' , 'end-1c' ) , ' def __init__(self, a, b):' )
266
266
267
267
@mock .patch .object (codecontext .CodeContext , 'update_code_context' )
268
268
def test_timer_event (self , mock_update ):
269
269
# Ensure code context is not active.
270
- if self .cc .label :
270
+ if self .cc .context :
271
271
self .cc .toggle_code_context_event ()
272
272
self .cc .timer_event ()
273
273
mock_update .assert_not_called ()
@@ -286,7 +286,7 @@ def test_config_timer_event(self):
286
286
test_colors = {'background' : '#222222' , 'foreground' : '#ffff00' }
287
287
288
288
# Ensure code context is not active.
289
- if cc .label :
289
+ if cc .context :
290
290
cc .toggle_code_context_event ()
291
291
292
292
# Nothing updates on inactive code context.
@@ -303,28 +303,28 @@ def test_config_timer_event(self):
303
303
cc .config_timer_event ()
304
304
eq (cc .textfont , save_font )
305
305
eq (cc .contextcolors , save_colors )
306
- eq (cc .label ['font' ], save_font )
307
- eq (cc .label ['background' ], save_colors ['background' ])
308
- eq (cc .label ['foreground' ], save_colors ['foreground' ])
306
+ eq (cc .context ['font' ], save_font )
307
+ eq (cc .context ['background' ], save_colors ['background' ])
308
+ eq (cc .context ['foreground' ], save_colors ['foreground' ])
309
309
310
310
# Active code context, change font.
311
311
cc .text ['font' ] = test_font
312
312
cc .config_timer_event ()
313
313
eq (cc .textfont , test_font )
314
314
eq (cc .contextcolors , save_colors )
315
- eq (cc .label ['font' ], test_font )
316
- eq (cc .label ['background' ], save_colors ['background' ])
317
- eq (cc .label ['foreground' ], save_colors ['foreground' ])
315
+ eq (cc .context ['font' ], test_font )
316
+ eq (cc .context ['background' ], save_colors ['background' ])
317
+ eq (cc .context ['foreground' ], save_colors ['foreground' ])
318
318
319
319
# Active code context, change color.
320
320
cc .text ['font' ] = save_font
321
321
codecontext .CodeContext .colors = test_colors
322
322
cc .config_timer_event ()
323
323
eq (cc .textfont , save_font )
324
324
eq (cc .contextcolors , test_colors )
325
- eq (cc .label ['font' ], save_font )
326
- eq (cc .label ['background' ], test_colors ['background' ])
327
- eq (cc .label ['foreground' ], test_colors ['foreground' ])
325
+ eq (cc .context ['font' ], save_font )
326
+ eq (cc .context ['background' ], test_colors ['background' ])
327
+ eq (cc .context ['foreground' ], test_colors ['foreground' ])
328
328
codecontext .CodeContext .colors = save_colors
329
329
cc .config_timer_event ()
330
330
0 commit comments