blob: 1672a3413e78c64672176f97310a31745907ea97 [file] [log] [blame]
Terry Jan Reedy4f133e22013-07-13 02:34:43 -04001'''Mock classes that imitate idlelib modules or classes.
2
3Attributes and methods will be added as needed for tests.
4'''
5
6from idlelib.idle_test.mock_tk import Text
7
Terry Jan Reedye3fcfc22014-06-03 20:54:21 -04008class Func:
9 '''Mock function captures args and returns result set by test.
10
Terry Jan Reedy537e2c82014-06-05 03:38:34 -040011 Attributes:
12 self.called - records call even if no args, kwds passed.
13 self.result - set by init, returned by call.
14 self.args - captures positional arguments.
15 self.kwds - captures keyword arguments.
16
Terry Jan Reedye3fcfc22014-06-03 20:54:21 -040017 Most common use will probably be to mock methods.
Terry Jan Reedy537e2c82014-06-05 03:38:34 -040018 Mock_tk.Var and Mbox_func are special variants of this.
Terry Jan Reedye3fcfc22014-06-03 20:54:21 -040019 '''
20 def __init__(self, result=None):
Terry Jan Reedy537e2c82014-06-05 03:38:34 -040021 self.called = False
Terry Jan Reedye3fcfc22014-06-03 20:54:21 -040022 self.result = result
23 self.args = None
24 self.kwds = None
25 def __call__(self, *args, **kwds):
Terry Jan Reedy537e2c82014-06-05 03:38:34 -040026 self.called = True
Terry Jan Reedye3fcfc22014-06-03 20:54:21 -040027 self.args = args
28 self.kwds = kwds
Terry Jan Reedy223dd8d2014-07-11 00:16:00 -040029 if isinstance(self.result, BaseException):
30 raise self.result
31 else:
32 return self.result
Terry Jan Reedye3fcfc22014-06-03 20:54:21 -040033
34
Terry Jan Reedy4f133e22013-07-13 02:34:43 -040035class Editor:
36 '''Minimally imitate EditorWindow.EditorWindow class.
37 '''
38 def __init__(self, flist=None, filename=None, key=None, root=None):
39 self.text = Text()
40 self.undo = UndoDelegator()
41
42 def get_selection_indices(self):
43 first = self.text.index('1.0')
44 last = self.text.index('end')
45 return first, last
46
Terry Jan Reedye3fcfc22014-06-03 20:54:21 -040047
Terry Jan Reedy4f133e22013-07-13 02:34:43 -040048class UndoDelegator:
49 '''Minimally imitate UndoDelegator,UndoDelegator class.
50 '''
51 # A real undo block is only needed for user interaction.
52 def undo_block_start(*args):
53 pass
54 def undo_block_stop(*args):
55 pass