Skip to content

Commit 2bc74ba

Browse files
committed
Add test for notepad callback with method not allowed in sync Editor callback
Fix NotepadCallbackTestCase - suite wasn't defined so it was never called. D'Oh.
1 parent 7950e04 commit 2bc74ba

1 file changed

Lines changed: 36 additions & 4 deletions

File tree

PythonScript/python_tests/tests/NotepadCallbackTestCase.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import unittest
22
import time
3+
import tempfile
4+
import os
35
from Npp import *
46

57
globalCallbackCalled = False
@@ -138,8 +140,8 @@ def callback_notepad_trigger_editor(self, args):
138140
editor.write('editor callback from notepad callback')
139141

140142
def test_editor_callback_from_notepad_callback(self):
141-
editor.callback(lambda a: self.callback_editor(args), [SCINTILLANOTIFICATION.MODIFIED])
142-
notepad.callback(lambda a: self.callback_notepad_trigger_editor(args), [NOTIFICATION.LANGCHANGED])
143+
editor.callback(lambda a: self.callback_editor(a), [SCINTILLANOTIFICATION.MODIFIED])
144+
notepad.callback(lambda a: self.callback_notepad_trigger_editor(a), [NOTIFICATION.LANGCHANGED])
143145
notepad.setLangType(LANGTYPE.PHP)
144146
self.poll_for_callback()
145147
self.assertTrue(self.callbackCalled)
@@ -151,9 +153,39 @@ def callback_editor_trigger_notepad(self, args):
151153
notepad.setLangType(LANGTYPE.PHP)
152154

153155
def test_notepad_callback_from_editor_callback(self):
154-
notepad.callback(lambda a: self.callback_notepad(args), [NOTIFICATION.LANGCHANGED])
155-
editor.callback(lambda a: self.callback_editor_trigger_notepad(args), [SCINTILLANOTIFICATION.MODIFIED])
156+
notepad.callback(lambda a: self.callback_notepad(a), [NOTIFICATION.LANGCHANGED])
157+
editor.callback(lambda a: self.callback_editor_trigger_notepad(a), [SCINTILLANOTIFICATION.MODIFIED])
156158

157159
editor.write('trigger editor callback')
158160
self.poll_for_callback()
159161
self.assertTrue(self.callbackCalled)
162+
163+
164+
def test_notepad_callback_with_disallowed_sync_method(self):
165+
"""This checks calling a method in a n++ callback, that is not allowed in
166+
a synchronous Scintilla callback - specifically because N++ callbacks are synchronous, but
167+
allow all methods"""
168+
169+
editor.write('File 1')
170+
notepad.saveAs(self.get_temp_filename())
171+
self.oldBufferID = notepad.getCurrentBufferID()
172+
notepad.new()
173+
editor.write('File 2')
174+
notepad.saveAs(self.get_temp_filename())
175+
editor.write('Change')
176+
notepad.callback(lambda a: self.callback_with_disallowed_sync_method(a), [NOTIFICATION.FILEBEFORESAVE])
177+
notepad.save()
178+
currentBufferID = notepad.getCurrentBufferID()
179+
# Close the second opened file, then both get closed neatly
180+
notepad.close()
181+
182+
self.assertTrue(self.callbackCalled)
183+
self.assertEqual(self.oldBufferID, currentBufferID)
184+
185+
186+
def callback_with_disallowed_sync_method(self, args):
187+
notepad.activateBufferID(self.oldBufferID)
188+
self.callbackCalled = True
189+
190+
191+
suite = unittest.TestLoader().loadTestsFromTestCase(NotepadCallbackTestCase)

0 commit comments

Comments
 (0)