• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'''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
8class Func(object):
9    '''Mock function captures args and returns result set by test.
10
11    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
17    Most common use will probably be to mock methods.
18    Mock_tk.Var and Mbox_func are special variants of this.
19    '''
20    def __init__(self, result=None):
21        self.called = False
22        self.result = result
23        self.args = None
24        self.kwds = None
25    def __call__(self, *args, **kwds):
26        self.called = True
27        self.args = args
28        self.kwds = kwds
29        if isinstance(self.result, BaseException):
30            raise self.result
31        else:
32            return self.result
33
34
35class Editor(object):
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
47
48class UndoDelegator(object):
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
56